-
Notifications
You must be signed in to change notification settings - Fork 898
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
Load Lans effeciently in MiqProvisionVirtWorkflow #17381
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,9 +67,11 @@ | |
|
||
context 'network selection' do | ||
before do | ||
@ems = FactoryGirl.create(:ems_vmware) | ||
@host1 = FactoryGirl.create(:host_vmware, :ems_id => @ems.id) | ||
@src_vm = FactoryGirl.create(:vm_vmware, :host => @host1, :ems_id => @ems.id) | ||
@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, :host => @host1, :ems_id => @ems.id) | ||
@other_vm = FactoryGirl.create(:vm_vmware, :host => @host2, :ems_id => @ems.id) | ||
allow(Rbac).to receive(:search) do |hash| | ||
[Array.wrap(hash[:targets])] | ||
end | ||
|
@@ -84,24 +86,30 @@ | |
s11 = FactoryGirl.create(:switch, :name => "A") | ||
s12 = FactoryGirl.create(:switch, :name => "B") | ||
s13 = FactoryGirl.create(:switch, :name => "C") | ||
@src_vm.host.switches = [s11, s12, s13] | ||
s14 = FactoryGirl.create(:switch, :name => "D") | ||
@src_vm.host.switches = [s11, s12, s13] | ||
@other_vm.host.switches = [s14] | ||
@lan11 = FactoryGirl.create(:lan, :name => "lan_A", :switch_id => s11.id) | ||
@lan12 = FactoryGirl.create(:lan, :name => "lan_B", :switch_id => s12.id) | ||
@lan13 = FactoryGirl.create(:lan, :name => "lan_C", :switch_id => s13.id) | ||
@lan14 = FactoryGirl.create(:lan, :name => "lan_D", :switch_id => s14.id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @NickLaMuro - Were the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @syncrou Took me a bit to remember why I did it myself! I was actually to make sure that this test: expect { workflow.load_hosts_vlans(hosts, {}) }.not_to exceed_query_limit(1) Was actually being exercised properly when multiple hosts were present. If I left the data as it was, I would have technically passed that spec without actually avoiding an N+1 because we were only testing against 1 host (note, the previous code did a |
||
end | ||
|
||
it '#allowed_vlans' do | ||
allow(workflow).to receive(:allowed_hosts).with(no_args).and_return([workflow.host_to_hash_struct(@host1)]) | ||
allowed_hosts = [ | ||
workflow.host_to_hash_struct(@host1), | ||
workflow.host_to_hash_struct(@host2) | ||
] | ||
allow(workflow).to receive(:allowed_hosts).with(no_args).and_return(allowed_hosts) | ||
vlans = workflow.allowed_vlans(:vlans => true, :dvs => false) | ||
lan_keys = [@lan11.name, @lan13.name, @lan12.name] | ||
lan_keys = [@lan11.name, @lan13.name, @lan12.name, @lan14.name] | ||
expect(vlans.keys).to match_array(lan_keys) | ||
expect(vlans.values).to match_array(lan_keys) | ||
end | ||
|
||
it '#load_hosts_vlans' do | ||
hosts = [@host1] | ||
MiqPreloader.preload(hosts, :lans => :switches) | ||
expect { workflow.load_hosts_vlans(hosts, {}) }.not_to exceed_query_limit(0) | ||
hosts = [@host1, @host2] | ||
expect { workflow.load_hosts_vlans(hosts, {}) }.not_to exceed_query_limit(1) | ||
end | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NickLaMuro - Is pulling this out a dependency on #17354?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, don't think so, though maybe I am not understanding the question.
That was how
hosts
,lans
, andswitches
were being loaded previously, and how "zero SQL queries" were being made in the test previously. This was just using theMiqPreloader.preload
code that already existed, and I was just removing it since it was no longer needed.Did that answer the question?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, in the previous versions of the code, this prevented N+1's in the
load_hosts_vlans
method. This is no longer needed, and avoids a lot of unneeded object allocations.