Skip to content

Commit

Permalink
Merge pull request #14946 from lfu/hosts_with_selected_vlan_1435814
Browse files Browse the repository at this point in the history
Filter out the hosts with the selected network.
(cherry picked from commit acf7681)

https://bugzilla.redhat.com/show_bug.cgi?id=1458363
  • Loading branch information
bdunne authored and simaishi committed Jun 2, 2017
1 parent 2165f74 commit 162577f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/models/miq_provision_virt_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ def update_field_read_only(options = {})
fields(:hardware) { |fn, f, _dn, _d| f[:read_only] = true if options[:read_only_fields].include?(fn) }
end

def allowed_hosts_obj(options = {})
all_hosts = super
vlan_name = get_value(@values[:vlan])
return all_hosts unless vlan_name

_log.info "Filtering hosts with the following network: <#{vlan_name}>"
all_hosts.reject { |h| !h.lans.pluck(:name).include?(vlan_name) }
end

#
# Methods for populating lists of allowed values for a field
# => Input - A hash containing options specific to the called method
Expand Down
31 changes: 31 additions & 0 deletions spec/models/miq_provision_virt_workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,37 @@
end
end

context '#allowed_hosts_obj' do
before do
@ems = FactoryGirl.create(:ems_vmware)
@host1 = FactoryGirl.create(:host_vmware, :ems_id => @ems.id)
@host2 = FactoryGirl.create(:host_vmware, :ems_id => @ems.id)
@src_vm = FactoryGirl.create(:vm_vmware, :ems_id => @ems.id)
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
workflow.instance_variable_set(:@target_resource, nil)

s1 = FactoryGirl.create(:switch, :name => "A")
s2 = FactoryGirl.create(:switch, :name => "B")
@host1.switches = [s1]
@host2.switches = [s2]
@lan1 = FactoryGirl.create(:lan, :name => "lan_A", :switch_id => s1.id)
@lan2 = FactoryGirl.create(:lan, :name => "lan_B", :switch_id => s2.id)
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 network' do
workflow.instance_variable_set(:@values, :src_vm_id => @src_vm.id, :vlan => [@lan1.name, @lan1.name])
expect(workflow.allowed_hosts_obj).to match_array([@host1])
end
end

context "#update_requester_from_parameters" do
let(:user_new) { FactoryGirl.create(:user_with_email) }
let(:data_new_user) { {:user_name => user_new.name} }
Expand Down

0 comments on commit 162577f

Please sign in to comment.