-
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
Check ems_ref before uid_ems when saving VMs #18616
Changes from all commits
ae7a083
0838a11
3512eff
2673eec
8d348d5
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 |
---|---|---|
|
@@ -123,29 +123,19 @@ | |
expect(v2.uid_ems).to eq(@vm2.uid_ems) | ||
end | ||
|
||
it "should handle dups in the raw data" do | ||
it "should update the existing vm's uid_ems even if it is a duplicate" do | ||
data = raw_data_with_dups(@vm1, @vm2) | ||
EmsRefresh.save_vms_inventory(@ems, data) | ||
|
||
vms = Vm.all | ||
expect(vms.length).to eq(3) | ||
|
||
disconnected, connected = vms.partition { |v| v.ems_id.nil? } | ||
expect(disconnected.length).to eq(1) | ||
expect(connected.length).to eq(2) | ||
|
||
d = disconnected.first | ||
c1, c2 = connected.sort_by(&:id) | ||
|
||
expect(d.id).to eq(@vm2.id) | ||
expect(d.uid_ems).to eq(@vm2.uid_ems) | ||
expect(vms.length).to eq(2) | ||
v1, v2 = vms.sort_by(&:id) | ||
|
||
expect(c1.id).to eq(@vm1.id) | ||
expect(c1.uid_ems).to eq(@vm1.uid_ems) | ||
expect(v1.id).to eq(@vm1.id) | ||
expect(v1.uid_ems).to eq(@vm1.uid_ems) | ||
|
||
expect(c2.id).not_to eq(@vm1.id) | ||
expect(c2.id).not_to eq(@vm2.id) | ||
expect(c2.uid_ems).to eq(@vm1.uid_ems) | ||
expect(v2.id).to eq(@vm2.id) | ||
expect(v2.uid_ems).to eq(@vm1.uid_ems) | ||
end | ||
end | ||
|
||
|
@@ -156,29 +146,19 @@ | |
@vm2 = FactoryBot.create(:vm_with_ref, :ext_management_system => @ems, :uid_ems => @uid) | ||
end | ||
|
||
it "should handle no dups in the raw data" do | ||
it "should update the duplicate records in the database with the new uid_ems" do | ||
data = raw_data_without_dups(@vm1, @vm2) | ||
EmsRefresh.save_vms_inventory(@ems, data) | ||
|
||
vms = Vm.all | ||
expect(vms.length).to eq(3) | ||
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. Similarly here:
So we're picking the existing VM with the same ems_ref and updating the uid_ems to match the new data |
||
|
||
disconnected, connected = vms.partition { |v| v.ems_id.nil? } | ||
expect(disconnected.length).to eq(1) | ||
expect(connected.length).to eq(2) | ||
|
||
d = disconnected.first | ||
c1, c2 = connected.sort_by(&:id) | ||
|
||
expect(d.id).to eq(@vm2.id) | ||
expect(d.uid_ems).to eq(@vm2.uid_ems) | ||
expect(vms.length).to eq(2) | ||
v1, v2 = vms.sort_by(&:id) | ||
|
||
expect(c1.id).to eq(@vm1.id) | ||
expect(c1.uid_ems).to eq(@vm1.uid_ems) | ||
expect(v1.id).to eq(@vm1.id) | ||
expect(v1.uid_ems).to eq(@vm1.uid_ems) | ||
|
||
expect(c2.id).not_to eq(@vm1.id) | ||
expect(c2.id).not_to eq(@vm2.id) | ||
expect(c2.uid_ems).not_to eq(@vm1.uid_ems) | ||
expect(v2.id).to eq(@vm2.id) | ||
expect(v2.uid_ems).not_to eq(@vm1.uid_ems) | ||
end | ||
|
||
it "should handle dups in the raw data" do | ||
|
@@ -204,29 +184,19 @@ | |
@vm2 = FactoryBot.create(:vm_with_ref, :ext_management_system => @ems, :uid_ems => @uid) | ||
end | ||
|
||
it "should handle no dups in the raw data" do | ||
it "should reconnect the disconnected vm and update the active vm" do | ||
data = raw_data_without_dups(@vm1, @vm2) | ||
EmsRefresh.save_vms_inventory(@ems, data) | ||
|
||
vms = Vm.all | ||
expect(vms.length).to eq(3) | ||
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. Here we are reconnecting one VM and updating the other:
|
||
|
||
disconnected, connected = vms.partition { |v| v.ems_id.nil? } | ||
expect(disconnected.length).to eq(1) | ||
expect(connected.length).to eq(2) | ||
|
||
d = disconnected.first | ||
c1, c2 = connected.sort_by(&:id) | ||
|
||
expect(d.id).to eq(@vm2.id) | ||
expect(d.uid_ems).to eq(@vm2.uid_ems) | ||
expect(vms.length).to eq(2) | ||
v1, v2 = vms.sort_by(&:id) | ||
|
||
expect(c1.id).to eq(@vm1.id) | ||
expect(c1.uid_ems).to eq(@vm1.uid_ems) | ||
expect(v1.id).to eq(@vm1.id) | ||
expect(v1.uid_ems).to eq(@vm1.uid_ems) | ||
|
||
expect(c2.id).not_to eq(@vm1.id) | ||
expect(c2.id).not_to eq(@vm2.id) | ||
expect(c2.uid_ems).not_to eq(@vm1.uid_ems) | ||
expect(v2.id).to eq(@vm2.id) | ||
expect(v2.uid_ems).not_to eq(@vm2.uid_ems) | ||
end | ||
|
||
it "should handle dups in the raw data" do | ||
|
@@ -299,6 +269,7 @@ | |
|
||
@ems_ref1 = @vm1.ems_ref_obj | ||
@ems_ref2 = @vm2.ems_ref_obj | ||
@vm1.ems_ref = @vm2.ems_ref = nil | ||
@vm1.ems_ref_obj = @vm2.ems_ref_obj = nil | ||
@vm1.save | ||
@vm2.save | ||
|
@@ -307,7 +278,9 @@ | |
# TODO: DRY up these tests with the others just like them | ||
it "should handle no dups in the raw data" do | ||
data = raw_data_without_dups(@vm1, @vm2) | ||
data[0][:ems_ref] = @ems_ref1 | ||
data[0][:ems_ref_obj] = @ems_ref1 | ||
data[1][:ems_ref] = @ems_ref2 | ||
data[1][:ems_ref_obj] = @ems_ref2 | ||
EmsRefresh.save_vms_inventory(@ems, data) | ||
|
||
|
@@ -324,7 +297,9 @@ | |
|
||
it "should handle dups in the raw data" do | ||
data = raw_data_with_dups(@vm1, @vm2) | ||
data[0][:ems_ref] = @ems_ref1 | ||
data[0][:ems_ref_obj] = @ems_ref1 | ||
data[1][:ems_ref] = @ems_ref2 | ||
data[1][:ems_ref_obj] = @ems_ref2 | ||
EmsRefresh.save_vms_inventory(@ems, data) | ||
|
||
|
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.
This spec is now actually testing a VM with the same ems_ref and a new uid_ems get updated and not archived:
Since the second vm in the data payload has the same ems_ref as an active vm but with a different uid_ems.
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.
Do the
it
descriptions reflect these changes (here and the next 2)? (hard to tell in the diff)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.
The descriptions were pretty general, "handle dups in the raw data" doesn't really describe what it is expecting to happen.
I'll update them to better describe the expected outcome.
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.
Done