From 5eb95a4d2a3a581ddc756711db334a237931741d Mon Sep 17 00:00:00 2001 From: Boris Odnopozov Date: Sun, 24 Dec 2017 13:43:08 +0200 Subject: [PATCH] Disconnect inventory on targeted refresh When doing a targeted refresh the condition to disconnect the target from the ems was not granular enough. For example in some cases when refreshing a template the 'folder' hashes were not not empty while the 'template' hashes were, still the template was not disconnected from the ems in that case. The new condition is more accurate and should mitigate this kind of scenarios. This is part of prs that fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1511445 --- app/models/ems_refresh/save_inventory_helper.rb | 12 ++++++++++++ app/models/ems_refresh/save_inventory_infra.rb | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/ems_refresh/save_inventory_helper.rb b/app/models/ems_refresh/save_inventory_helper.rb index c2269650290..8f0d649f0bd 100644 --- a/app/models/ems_refresh/save_inventory_helper.rb +++ b/app/models/ems_refresh/save_inventory_helper.rb @@ -185,4 +185,16 @@ def determine_deletes_using_association(ems, target, disconnect = true) [] end end + + def hashes_of_target_empty?(hashes, target) + hashes.blank? || (hashes[:storages].blank? && + case target + when VmOrTemplate + hashes[:vms].blank? + when Host + hashes[:hosts].blank? + when EmsFolder + hashes[:folders].blank? + end) + end end diff --git a/app/models/ems_refresh/save_inventory_infra.rb b/app/models/ems_refresh/save_inventory_infra.rb index 21ed10a85d0..30c15a6fd8d 100644 --- a/app/models/ems_refresh/save_inventory_infra.rb +++ b/app/models/ems_refresh/save_inventory_infra.rb @@ -39,7 +39,7 @@ def save_ems_infra_inventory(ems, hashes, target = nil, disconnect = true) log_header = "EMS: [#{ems.name}], id: [#{ems.id}]" # Check if the data coming in reflects a complete removal from the ems - if hashes.blank? || (hashes[:hosts].blank? && hashes[:vms].blank? && hashes[:storages].blank? && hashes[:folders].blank?) + if hashes_of_target_empty?(hashes, target) target.disconnect_inv if disconnect return end