From 4b7cddc0d41c5475b4de5d8f9e6d3ef6dbc55203 Mon Sep 17 00:00:00 2001 From: Lucy Fu Date: Tue, 18 Jul 2017 13:48:09 -0400 Subject: [PATCH] Fix the VM Provisioning issue with auto replacement in selected dvPortGroup network. https://bugzilla.redhat.com/show_bug.cgi?id=1467399 --- .../infra_manager/provision_workflow.rb | 11 ++++++++ .../infra_manager/provision_workflow_spec.rb | 28 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/app/models/manageiq/providers/vmware/infra_manager/provision_workflow.rb b/app/models/manageiq/providers/vmware/infra_manager/provision_workflow.rb index d9f06b11d..a4801c4f4 100644 --- a/app/models/manageiq/providers/vmware/infra_manager/provision_workflow.rb +++ b/app/models/manageiq/providers/vmware/infra_manager/provision_workflow.rb @@ -144,6 +144,17 @@ def available_vlans_and_hosts(options = {}) return vlans, hosts end + def filter_hosts_by_vlan_name(all_hosts) + vlan_name = get_value(@values[:vlan]) + return all_hosts unless vlan_name + + _log.info("Filtering hosts with the following network: <#{vlan_name}>") + shared = !vlan_name.match(/dvs_/).nil? + vlan_name.sub!(/^dvs_/, '') if shared + MiqPreloader.preload(all_hosts, :lans => :switches) + all_hosts.select { |h| h.lans.any? { |lan| lan.name == vlan_name && !lan.switch.shared.blank? == shared } } + end + def allowed_storage_profiles(_options = {}) return [] if (src = resources_for_ui).blank? || src[:vm].nil? @values[:placement_storage_profile] ||= diff --git a/spec/models/manageiq/providers/vmware/infra_manager/provision_workflow_spec.rb b/spec/models/manageiq/providers/vmware/infra_manager/provision_workflow_spec.rb index ac358a77d..006ed3c17 100644 --- a/spec/models/manageiq/providers/vmware/infra_manager/provision_workflow_spec.rb +++ b/spec/models/manageiq/providers/vmware/infra_manager/provision_workflow_spec.rb @@ -244,6 +244,34 @@ expect(vlans.keys).to match_array(lan_keys) expect(vlans.values).to match_array(lan_values) end + + context '#allowed_hosts_obj' do + before do + allow(workflow).to receive(:find_all_ems_of_type).and_return([@host1, @host2]) + allow(Rbac).to receive(:search) do |hash| + [Array.wrap(hash[:targets])] + end + end + + it 'finds all hosts with no selected network' do + workflow.instance_variable_set(:@values, :src_vm_id => @src_vm.id) + expect(workflow.allowed_hosts_obj).to match_array([@host1, @host2]) + end + + it 'finds only the hosts that can access the selected vSwitch network' do + @host1.switches = [s11] + @host2.switches = [s22] + workflow.instance_variable_set(:@values, :src_vm_id => @src_vm.id, :vlan => [@lan11.name, @lan11.name]) + expect(workflow.allowed_hosts_obj).to match_array([@host1]) + end + + it 'finds only the hosts that can access the selected dvSwitch network' do + @host1.switches = [s11] + @host2.switches = [s22] + workflow.instance_variable_set(:@values, :src_vm_id => @src_vm.id, :vlan => ["dvs_#{@lan22.name}", @lan22.name]) + expect(workflow.allowed_hosts_obj).to match_array([@host2]) + end + end end end end