-
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
Check ems_ref before uid_ems when saving VMs #18616
Conversation
Added specs over in ManageIQ/manageiq-providers-vmware#386 |
6a5a212
to
c50628b
Compare
@@ -128,24 +128,15 @@ | |||
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 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:
128: data = raw_data_with_dups(@vm1, @vm2)
=> 129: EmsRefresh.save_vms_inventory(@ems, data)
130:
131: vms = Vm.all
132: expect(vms.length).to eq(2)
133:
(byebug) Vm.all.map { |vm| [vm.ems_ref, vm.uid_ems] }
[["vm-0000000000001", "fa7c21a7-2596-45b1-86b6-3ccb8b8c9273"], ["vm-0000000000002", "57a19467-b438-4e44-8710-fe4873066249"]]
(byebug) data.map { |vm| [vm[:ems_ref], vm[:uid_ems]] }
[["vm-0000000000001", "fa7c21a7-2596-45b1-86b6-3ccb8b8c9273"], ["vm-0000000000002", "fa7c21a7-2596-45b1-86b6-3ccb8b8c9273"]]
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
f975f5e
to
e794003
Compare
If there is a vm record with the same ems_ref then update that even if it has a different uid_ems. https://bugzilla.redhat.com/show_bug.cgi?id=1695008
4551dd3
to
ae7a083
Compare
@@ -161,24 +151,14 @@ | |||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly here:
(byebug) data.map { |v| [v[:ems_ref], v[:uid_ems]] }
[["vm-0000000000001", "56346b53-84d8-460a-9f8f-7fed3132c3a9"], ["vm-0000000000002", "ada1a6be-af10-4325-a198-25bb3357ed03"]]
(byebug) Vm.all.map { |v| [v[:ems_ref], v[:uid_ems]] }
[["vm-0000000000001", "56346b53-84d8-460a-9f8f-7fed3132c3a9"], ["vm-0000000000002", "56346b53-84d8-460a-9f8f-7fed3132c3a9"]]
So we're picking the existing VM with the same ems_ref and updating the uid_ems to match the new data
@@ -209,24 +189,14 @@ | |||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Here we are reconnecting one VM and updating the other:
(byebug) Vm.all.map { |v| [v[:ems_id], v[:ems_ref], v[:uid_ems]] }
[[nil, "vm-0000000000001", "17da5cea-f4bf-46a7-937d-8a247f211797"], [43000000000874, "vm-0000000000002", "17da5cea-f4bf-46a7-937d-8a247f211797"]]
(byebug) data.map { |v| [v[:ems_id], v[:ems_ref], v[:uid_ems]] }
[[nil, "vm-0000000000001", "17da5cea-f4bf-46a7-937d-8a247f211797"], [nil, "vm-0000000000002", "47f1864c-4b80-4b95-9195-38c8c54f71f0"]]
@@ -53,6 +53,8 @@ def save_vms_inventory(ems, hashes, target = nil, disconnect = true) | |||
] | |||
remove_keys = child_keys + extra_infra_keys + extra_cloud_keys | |||
|
|||
vms_by_ems_ref = ems.vms_and_templates.index_by(&:ems_ref).except(nil) |
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.
Should this be non-archived only or do you want everything (or does vms_and_templates already handle that)? I'm concerned that if an old vm has an ems_ref that matches (say the case where they update vsphere or whatever), then it will clobber.
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.
Using the association off of the ems automatically gets only the non-archived ones (aka the ones with an ems_id)
@@ -89,7 +91,7 @@ def save_vms_inventory(ems, hashes, target = nil, disconnect = true) | |||
|
|||
# Find the Vm in the database with the current uid_ems. In the event | |||
# of duplicates, try to determine which one is correct. | |||
found = vms_by_uid_ems[h[:uid_ems]] || [] | |||
found = Array(vms_by_ems_ref[h[:ems_ref]] || vms_by_uid_ems[h[: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.
If you need an array you can change the original index creation to do group_by instead of index_by
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.
👍
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.
Just be careful of your &.
change below (just noticed)
Checked commits agrare/manageiq@ae7a083~...8d348d5 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
When saving VMs only the uid_ems was considered when looking for
existing VMs when it is possible for the same VM to get a new UUID
leading to the same ems_ref and a different uid_ems.
For updating existing VMs any records with the same ems_id+ems_ref
should be considered before looking at the uid_ems.
https://bugzilla.redhat.com/show_bug.cgi?id=1695008