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

Filter out the hosts with the selected network. #14946

Merged
merged 1 commit into from
May 1, 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
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) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lfu Where you able to verify if this is save for all Infra providers? Is the host -> lan relationship always going to work here?

cc @agrare

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmcculloug yes host -> lan will work for all infra providers (at least RHV and SCVMM, I don't see any lans in openstack::infra)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Openstack infra is only for managing the undercloud - registering new baremetal nodes, adding more compute nodes, etc. In other words, there is no provisioning for Openstack Infra.

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