Skip to content

Commit

Permalink
Merge pull request #17357 from NickLaMuro/nested_hashes_for_miq_reque…
Browse files Browse the repository at this point in the history
…st_workflow

Use nested hashes instead of string keys
(cherry picked from commit 5f22e97)

https://bugzilla.redhat.com/show_bug.cgi?id=1593797
  • Loading branch information
kbrock authored and simaishi committed Jun 21, 2018
1 parent 38b974b commit de6d40d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions app/models/miq_request_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,12 @@ def find_classes_under_ci(item, klass)

def load_ems_node(item, log_header)
@ems_xml_nodes ||= {}
klass_name = item.kind_of?(MiqHashStruct) ? item.evm_object_class : item.class.base_class.name
node = @ems_xml_nodes["#{klass_name}_#{item.id}"]
klass_name = if item.kind_of?(MiqHashStruct)
Object.const_get(item.evm_object_class)
else
item.class.base_class
end
node = @ems_xml_nodes[klass_name][item.id]
$log.error("#{log_header} Resource <#{klass_name}_#{item.id} - #{item.name}> not found in cached resource tree.") if node.nil?
node
end
Expand Down Expand Up @@ -961,7 +965,8 @@ def ems_metadata_tree_add_hosts_under_clusters!(result)

def convert_to_xml(xml, result)
result.each do |obj, children|
@ems_xml_nodes["#{obj.class.base_class}_#{obj.id}"] = node = xml.add_element(obj.class.base_class.name, :object => ci_to_hash_struct(obj))
@ems_xml_nodes[obj.class.base_class] ||= {}
@ems_xml_nodes[obj.class.base_class][obj.id] = node = xml.add_element(obj.class.base_class.name, :object => ci_to_hash_struct(obj))
convert_to_xml(node, children)
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/models/miq_request_workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@
ems_folder.ext_management_system = ems
attrs = ems_folder.attributes.merge(:object => ems_folder)
xml_hash = XmlHash::Element.new('EmsFolder', attrs)
hash = {"ResourcePool_#{resource_pool.id}" => xml_hash}
hash = { ResourcePool => { resource_pool.id => xml_hash } }
workflow.instance_variable_set("@ems_xml_nodes", hash)
end

Expand All @@ -486,7 +486,7 @@
ems_folder.ext_management_system = ems
attrs = resource_pool.attributes.merge(:object => resource_pool, :ems => ems)
xml_hash = XmlHash::Element.new('ResourcePool', attrs)
hash = {"EmsFolder_#{ems_folder.id}" => xml_hash}
hash = { EmsFolder => { ems_folder.id => xml_hash } }
workflow.instance_variable_set("@ems_xml_nodes", hash)
end

Expand All @@ -506,7 +506,7 @@
datacenter.ext_management_system = ems
attrs = datacenter.attributes.merge(:object => datacenter, :ems => ems)
xml_hash = XmlHash::Element.new('EmsFolder', attrs)
hash = {"EmsFolder_#{datacenter.id}" => xml_hash}
hash = { EmsFolder => { datacenter.id => xml_hash } }
workflow.instance_variable_set("@ems_xml_nodes", hash)
end

Expand Down

0 comments on commit de6d40d

Please sign in to comment.