Skip to content

Commit 01ece9e

Browse files
committed
Prevent a vm or template being its own parent
1 parent d7aed32 commit 01ece9e

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

app/models/manageiq/providers/inventory/persister/builder/cloud_manager.rb

+20-6
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,31 @@ def vm_and_miq_template_ancestry_save_block
165165

166166
# Fetch IDs of all vms and genealogy_parents, only if genealogy_parent is present
167167
vms_genealogy_parents = vms_inventory_collection.data.each_with_object({}) do |x, obj|
168-
unless x.data[:genealogy_parent].nil?
169-
genealogy_parent_id = x.data[:genealogy_parent].load.try(:id)
170-
obj[x.id] = genealogy_parent_id if genealogy_parent_id
168+
next if x.data[:genealogy_parent].nil?
169+
170+
genealogy_parent_id = x.data[:genealogy_parent].load.try(:id)
171+
next if genealogy_parent_id.nil?
172+
173+
if genealogy_parent_id == x.id
174+
_log.warn("Cannot assign genealogy_parent to same object, ID [#{x.id}]")
175+
next
171176
end
177+
178+
obj[x.id] = genealogy_parent_id
172179
end
173180

174181
miq_template_genealogy_parents = miq_templates_inventory_collection.data.each_with_object({}) do |x, obj|
175-
unless x.data[:genealogy_parent].nil?
176-
genealogy_parent_id = x.data[:genealogy_parent].load.try(:id)
177-
obj[x.id] = genealogy_parent_id if genealogy_parent_id
182+
next if x.data[:genealogy_parent].nil?
183+
184+
genealogy_parent_id = x.data[:genealogy_parent].load.try(:id)
185+
next if genealogy_parent_id.nil?
186+
187+
if genealogy_parent_id == x.id
188+
_log.warn("Cannot assign genealogy_parent to same object, ID [#{x.id}]")
189+
next
178190
end
191+
192+
obj[x.id] = genealogy_parent_id
179193
end
180194

181195
ActiveRecord::Base.transaction do

0 commit comments

Comments
 (0)