diff --git a/app/models/miq_request_workflow.rb b/app/models/miq_request_workflow.rb index 188777ab6db..7ae9cff72cd 100644 --- a/app/models/miq_request_workflow.rb +++ b/app/models/miq_request_workflow.rb @@ -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 @@ -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 diff --git a/spec/models/miq_request_workflow_spec.rb b/spec/models/miq_request_workflow_spec.rb index caf924dedc2..ae3c49c461f 100644 --- a/spec/models/miq_request_workflow_spec.rb +++ b/spec/models/miq_request_workflow_spec.rb @@ -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 @@ -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 @@ -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