Skip to content

Commit

Permalink
Merge pull request #78 from lfu/DVPortGroup_1467399
Browse files Browse the repository at this point in the history
Fix the VM Provisioning issue with auto replacement in selected dvPortGroup network.
(cherry picked from commit 5e17387)

https://bugzilla.redhat.com/show_bug.cgi?id=1478562
  • Loading branch information
agrare authored and simaishi committed Aug 4, 2017
1 parent 579d87b commit 6a23cc6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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] ||=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6a23cc6

Please sign in to comment.