Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the VM Provisioning issue with auto replacement in selected dvPortGroup network. #78

Merged
merged 1 commit into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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