Skip to content

Commit

Permalink
Disconnect inventory on targeted refresh
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Boris Odnopozov committed Dec 24, 2017
1 parent 748ba9b commit 07459d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/models/ems_refresh/save_inventory_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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[:storage].blank? &&
case target
when VmOrTemplate
hashes[:vm].blank?
when Host
hashes[:host].blank?
when EmsFolder
hashes[:foldes].blank?
end)
end
end
2 changes: 1 addition & 1 deletion app/models/ems_refresh/save_inventory_infra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 07459d0

Please sign in to comment.