diff --git a/app/models/ems_refresh/save_inventory.rb b/app/models/ems_refresh/save_inventory.rb index 0afcaeb585f..ac8ab9fbfa7 100644 --- a/app/models/ems_refresh/save_inventory.rb +++ b/app/models/ems_refresh/save_inventory.rb @@ -1,7 +1,7 @@ module EmsRefresh::SaveInventory def save_ems_inventory(ems, hashes, target = nil) - if hashes && hashes[:_dto_collection] - hashes.delete(:_dto_collection) + if hashes && hashes[:_inventory_collection] + hashes.delete(:_inventory_collection) ManagerRefresh::SaveInventory.save_inventory(ems, hashes) return end diff --git a/app/models/manageiq/providers/cloud_manager/refresh_parser_dto.rb b/app/models/manageiq/providers/cloud_manager/refresh_parser_inventory_object.rb similarity index 90% rename from app/models/manageiq/providers/cloud_manager/refresh_parser_dto.rb rename to app/models/manageiq/providers/cloud_manager/refresh_parser_inventory_object.rb index 8b27fd6f48f..ffa70fa1058 100644 --- a/app/models/manageiq/providers/cloud_manager/refresh_parser_dto.rb +++ b/app/models/manageiq/providers/cloud_manager/refresh_parser_inventory_object.rb @@ -1,4 +1,4 @@ -class ManageIQ::Providers::CloudManager::RefreshParserDto < ::ManagerRefresh::RefreshParserDto +class ManageIQ::Providers::CloudManager::RefreshParserInventoryObject < ::ManagerRefresh::RefreshParserInventoryObject private def parse_key_pair(kp) diff --git a/app/models/manager_refresh/dto_lazy.rb b/app/models/manager_refresh/dto_lazy.rb deleted file mode 100644 index df506e9146c..00000000000 --- a/app/models/manager_refresh/dto_lazy.rb +++ /dev/null @@ -1,63 +0,0 @@ -module ManagerRefresh - class DtoLazy - include Vmdb::Logging - - attr_reader :ems_ref, :dto_collection, :key, :default - - def initialize(dto_collection, ems_ref, key: nil, default: nil) - @ems_ref = ems_ref - @dto_collection = dto_collection - @key = key - @default = default - end - - def to_s - ems_ref - end - - def inspect - suffix = "" - suffix += ", key: #{key}" if key.present? - "DtoLazy:('#{self}', #{dto_collection})#{suffix}" - end - - def load - key ? load_object_with_key : load_object - end - - def dependency? - # If key is not set, DtoLazy is a dependency, cause it points to the record itself. Otherwise DtoLazy is a - # dependency only if it points to an attribute which is a dependency or a relation. - !!(!key || transitive_dependency?) - end - - def transitive_dependency? - # If the dependency is dto_collection.lazy_find(:ems_ref, :key => :stack) - # and a :stack is a relation to another object, in the Dto object, - # then this relation is considered transitive. - !!(key && (dto_collection.dependency_attributes.keys.include?(key) || - dto_collection.model_class.reflect_on_association(key))) - end - - private - - def load_object_with_key - # TODO(lsmola) Log error if we are accessing path that is present in blacklist or not present in whitelist - found = dto_collection.find(to_s) - if found.present? - if found.try(:data).present? - found.data[key] || default - else - found.public_send(key) - end - else - default - end - end - - def load_object - dto_collection_member = dto_collection.find(to_s) - dto_collection_member.respond_to?(:object) ? dto_collection_member.object : dto_collection_member - end - end -end diff --git a/app/models/manager_refresh/graph/topological_sort.rb b/app/models/manager_refresh/graph/topological_sort.rb index 9163e3e3d6c..79d2740c359 100644 --- a/app/models/manager_refresh/graph/topological_sort.rb +++ b/app/models/manager_refresh/graph/topological_sort.rb @@ -18,7 +18,7 @@ def make_topological_sort(original_nodes, edges) # Topological sort of the graph of the DTO collections to find the right order of saving DTO collections and # identify what DTO collections can be saved in parallel. ################################################################################################################ - # The expected input here is the directed acyclic Graph G (dto_collections), consisting of Vertices(Nodes) V and + # The expected input here is the directed acyclic Graph G (inventory_collections), consisting of Vertices(Nodes) V and # Edges E: # G = (V, E) # diff --git a/app/models/manager_refresh/dto_collection.rb b/app/models/manager_refresh/inventory_collection.rb similarity index 78% rename from app/models/manager_refresh/dto_collection.rb rename to app/models/manager_refresh/inventory_collection.rb index d06552ef12c..40850ae2242 100644 --- a/app/models/manager_refresh/dto_collection.rb +++ b/app/models/manager_refresh/inventory_collection.rb @@ -1,5 +1,5 @@ module ManagerRefresh - class DtoCollection + class InventoryCollection attr_accessor :saved attr_reader :model_class, :strategy, :attributes_blacklist, :attributes_whitelist, :custom_save_block, :parent, @@ -36,7 +36,7 @@ def initialize(model_class, manager_ref: nil, association: nil, parent: nil, str blacklist_attributes!(attributes_blacklist) if attributes_blacklist.present? whitelist_attributes!(attributes_whitelist) if attributes_whitelist.present? - validate_dto_collection! + validate_inventory_collection! end def to_a @@ -61,8 +61,8 @@ def load_from_db def process_strategy_local_db_cache_all self.saved = true - # TODO(lsmola) selected need to contain also :keys used in other DtoCollections pointing to this one, once we - # get list of all keys for each DtoCollection ,we can uncomnent + # TODO(lsmola) selected need to contain also :keys used in other InventoryCollections pointing to this one, once + # we get list of all keys for each InventoryCollection ,we can uncomnent # selected = [:id] + manager_ref.map { |x| model_class.reflect_on_association(x).try(:foreign_key) || x } # selected << :type if model_class.new.respond_to? :type # load_from_db.select(selected).find_each do |record| @@ -99,12 +99,12 @@ def saveable? dependencies.all?(&:saved?) end - def <<(dto) - unless data_index[dto.manager_uuid] - data_index[dto.manager_uuid] = dto - data << dto + def <<(inventory_object) + unless data_index[inventory_object.manager_uuid] + data_index[inventory_object.manager_uuid] = inventory_object + data << inventory_object - actualize_dependencies(dto) + actualize_dependencies(inventory_object) end end @@ -138,11 +138,11 @@ def find(manager_uuid) end def lazy_find(manager_uuid, key: nil, default: nil) - ::ManagerRefresh::DtoLazy.new(self, manager_uuid, :key => key, :default => default) + ::ManagerRefresh::InventoryObjectLazy.new(self, manager_uuid, :key => key, :default => default) end - def new_dto(hash) - ::ManagerRefresh::Dto.new(self, hash) + def new_inventory_object(hash) + ::ManagerRefresh::InventoryObject.new(self, hash) end def filtered_dependency_attributes @@ -181,31 +181,31 @@ def dependencies filtered_dependency_attributes.values.map(&:to_a).flatten.uniq end - def dependency_attributes_for(dto_collections) + def dependency_attributes_for(inventory_collections) attributes = Set.new - dto_collections.each do |dto_collection| - attributes += filtered_dependency_attributes.select { |_key, value| value.include?(dto_collection) }.keys + inventory_collections.each do |inventory_collection| + attributes += filtered_dependency_attributes.select { |_key, value| value.include?(inventory_collection) }.keys end attributes end def blacklist_attributes!(attributes) - # The manager_ref attributes cannot be blacklisted, otherwise we will not be able to identify the dto object. We - # do not automatically remove attributes causing fixed dependencies, so beware that without them, you won't be - # able to create the record. + # The manager_ref attributes cannot be blacklisted, otherwise we will not be able to identify the + # inventory_object. We do not automatically remove attributes causing fixed dependencies, so beware that without + # them, you won't be able to create the record. self.attributes_blacklist += attributes - (fixed_attributes + internal_attributes) end def whitelist_attributes!(attributes) # The manager_ref attributes always needs to be in the white list, otherwise we will not be able to identify the - # dto object. We do not automatically add attributes causing fixed dependencies, so beware that without them, you - # won't be able to create the record. + # inventory_object. We do not automatically add attributes causing fixed dependencies, so beware that without + # them, you won't be able to create the record. self.attributes_whitelist += attributes + (fixed_attributes + internal_attributes) end def clone - # A shallow copy of DtoCollection, the copy will share @data of the original collection, otherwise we would be - # copying a lot of records in memory. + # A shallow copy of InventoryCollection, the copy will share @data of the original collection, otherwise we would + # be copying a lot of records in memory. self.class.new(model_class, :manager_ref => manager_ref, :association => association, @@ -215,7 +215,8 @@ def clone :custom_save_block => custom_save_block, :data => data, :data_index => data_index, - # Dependency attributes need to be a hard copy, since those will differ for each DtoCollection + # Dependency attributes need to be a hard copy, since those will differ for each + # InventoryCollection :dependency_attributes => dependency_attributes.clone) end @@ -223,7 +224,7 @@ def to_s whitelist = ", whitelist: [#{attributes_whitelist.to_a.join(", ")}]" unless attributes_whitelist.blank? blacklist = ", blacklist: [#{attributes_blacklist.to_a.join(", ")}]" unless attributes_blacklist.blank? - "DtoCollection:<#{@model_class}>#{whitelist}#{blacklist}" + "InventoryCollection:<#{@model_class}>#{whitelist}#{blacklist}" end def inspect @@ -234,37 +235,38 @@ def inspect attr_writer :attributes_blacklist, :attributes_whitelist - def actualize_dependencies(dto) - dto.data.each do |key, value| + def actualize_dependencies(inventory_object) + inventory_object.data.each do |key, value| if dependency?(value) - (dependency_attributes[key] ||= Set.new) << value.dto_collection + (dependency_attributes[key] ||= Set.new) << value.inventory_collection self.transitive_dependency_attributes << key if transitive_dependency?(value) elsif value.kind_of?(Array) && value.any? { |x| dependency?(x) } - (dependency_attributes[key] ||= Set.new) << value.detect { |x| dependency?(x) }.dto_collection + (dependency_attributes[key] ||= Set.new) << value.detect { |x| dependency?(x) }.inventory_collection self.transitive_dependency_attributes << key if value.any? { |x| transitive_dependency?(x) } end end end def dependency?(value) - (value.kind_of?(::ManagerRefresh::DtoLazy) && value.dependency?) || value.kind_of?(::ManagerRefresh::Dto) + (value.kind_of?(::ManagerRefresh::InventoryObjectLazy) && value.dependency?) || + value.kind_of?(::ManagerRefresh::InventoryObject) end def transitive_dependency?(value) - # If the dependency is dto_collection.lazy_find(:ems_ref, :key => :stack) - # and a :stack is a relation to another object, in the Dto object, + # If the dependency is inventory_collection.lazy_find(:ems_ref, :key => :stack) + # and a :stack is a relation to another object, in the InventoryObject object, # then this dependency is considered transitive. - (value.kind_of?(::ManagerRefresh::DtoLazy) && value.transitive_dependency?) + (value.kind_of?(::ManagerRefresh::InventoryObjectLazy) && value.transitive_dependency?) end - def validate_dto_collection! + def validate_inventory_collection! if @strategy == :local_db_cache_all if (manager_ref & association_attributes).present? # Our manager_ref unique key contains a reference, that means that index we get from the API and from the # db will differ. We need a custom indexing method, so the indexing is correct. raise "The unique key list manager_ref contains a reference, which can't be built automatically when loading"\ - " the DtoCollection from the DB, you need to provide a custom_manager_uuid lambda, that builds the"\ - " correct manager_uuid given a DB record" if custom_manager_uuid.nil? + " the InventoryCollection from the DB, you need to provide a custom_manager_uuid lambda, that builds"\ + " the correct manager_uuid given a DB record" if custom_manager_uuid.nil? end end end diff --git a/app/models/manager_refresh/dto_collection/graph.rb b/app/models/manager_refresh/inventory_collection/graph.rb similarity index 65% rename from app/models/manager_refresh/dto_collection/graph.rb rename to app/models/manager_refresh/inventory_collection/graph.rb index ce89a6ce870..8814eed30e2 100644 --- a/app/models/manager_refresh/dto_collection/graph.rb +++ b/app/models/manager_refresh/inventory_collection/graph.rb @@ -1,10 +1,10 @@ module ManagerRefresh - class DtoCollection + class InventoryCollection class Graph < ::ManagerRefresh::Graph def initialize(nodes) super(nodes) - assert_dto_collections(nodes) + assert_inventory_collections(nodes) end def build_directed_acyclic_graph! @@ -53,76 +53,77 @@ def build_directed_acyclic_graph! private - def assert_dto_collections(dto_collections) - dto_collections.each do |dto_collection| - unless dto_collection.kind_of? ::ManagerRefresh::DtoCollection - raise "A ManagerRefresh::SaveInventory needs a DtoCollection object, it got: #{dto_collection.inspect}" + def assert_inventory_collections(inventory_collections) + inventory_collections.each do |inventory_collection| + unless inventory_collection.kind_of? ::ManagerRefresh::InventoryCollection + raise "A ManagerRefresh::SaveInventory needs a InventoryCollection object, it got: #{inventory_collection.inspect}" end end end def convert_to_dag!(nodes, feedback_edge_set) new_nodes = [] - dto_collection_transformations = {} - nodes.each do |dto_collection| - feedback_dependencies = feedback_edge_set.select { |e| e.second == dto_collection }.map(&:first) - attrs = dto_collection.dependency_attributes_for(feedback_dependencies) + inventory_collection_transformations = {} + nodes.each do |inventory_collection| + feedback_dependencies = feedback_edge_set.select { |e| e.second == inventory_collection }.map(&:first) + attrs = inventory_collection.dependency_attributes_for(feedback_dependencies) next if attrs.blank? - new_dto_collection = dto_collection.clone + new_inventory_collection = inventory_collection.clone - # Add dto_collection as a dependency of the new_dto_collection, so we make sure it runs after + # Add inventory_collection as a dependency of the new_inventory_collection, so we make sure it runs after # TODO(lsmola) add a nice dependency_attributes setter? It's used also in actualize_dependencies method - new_dto_collection.dependency_attributes[:__feedback_edge_set_parent] = Set.new([dto_collection]) - new_nodes << new_dto_collection + new_inventory_collection.dependency_attributes[:__feedback_edge_set_parent] = Set.new([inventory_collection]) + new_nodes << new_inventory_collection - dto_collection.blacklist_attributes!(attrs) - new_dto_collection.whitelist_attributes!(attrs) + inventory_collection.blacklist_attributes!(attrs) + new_inventory_collection.whitelist_attributes!(attrs) - # Store a simple hash for transforming dto_collection to new_dto_collection - dto_collection_transformations[dto_collection] = new_dto_collection + # Store a simple hash for transforming inventory_collection to new_inventory_collection + inventory_collection_transformations[inventory_collection] = new_inventory_collection end all_nodes = nodes + new_nodes # If we remove an attribute that was a dependency of another node, we need to move also the # dependency. So e.g. floating_ip depends on network_port's attribute vm, but we move that attribute to new - # network_port dto_collection. We will need to move also the dependency to point to the new dto_collection. + # network_port inventory_collection. We will need to move also the dependency to point to the new + # inventory_collection. # # So we have to go through all dependencies that loads a key, which is the moved attribute. We can get a list # of attributes that are using a key from transitive_dependency_attributes, from there we can get a list of # dependencies. And from the list of dependencies, we can check which ones were moved just by looking into - # dto_collection_transformations. - all_nodes.each do |dto_collection| - dto_collection.transitive_dependency_attributes.each do |transitive_dependency_attribute| - transitive_dependencies = dto_collection.dependency_attributes[transitive_dependency_attribute] + # inventory_collection_transformations. + all_nodes.each do |inventory_collection| + inventory_collection.transitive_dependency_attributes.each do |transitive_dependency_attribute| + transitive_dependencies = inventory_collection.dependency_attributes[transitive_dependency_attribute] next if transitive_dependencies.blank? transitive_dependencies.map! do |dependency| - transformed_dependency = dto_collection_transformations[dependency] + transformed_dependency = inventory_collection_transformations[dependency] transformed_dependency.blank? ? dependency : transformed_dependency end end end - # Add the new DtoCollections to the list of nodes our our graph + # Add the new InventoryCollections to the list of nodes our our graph construct_graph!(all_nodes) end - def build_edges(dto_collections) + def build_edges(inventory_collections) edges = [] transitive_edges = [] fixed_edges = [] - dto_collections.each do |dto_collection| - dto_collection.dependencies.each do |dependency| - fixed_edges << [dependency, dto_collection] if dto_collection.fixed_dependencies.include?(dependency) - if dto_collection.dependency_attributes_for([dependency]).any? { |x| dto_collection.transitive_dependency_attributes.include?(x) } - # The condition checks if the dependency is a transitive dependency, in other words a DtoLazy with :key + inventory_collections.each do |inventory_collection| + inventory_collection.dependencies.each do |dependency| + fixed_edges << [dependency, inventory_collection] if inventory_collection.fixed_dependencies.include?(dependency) + if inventory_collection.dependency_attributes_for([dependency]).any? { |x| inventory_collection.transitive_dependency_attributes.include?(x) } + # The condition checks if the dependency is a transitive dependency, in other words a InventoryObjectLazy with :key # pointing to another object. - transitive_edges << [dependency, dto_collection] + transitive_edges << [dependency, inventory_collection] else - edges << [dependency, dto_collection] + edges << [dependency, inventory_collection] end end end diff --git a/app/models/manager_refresh/dto.rb b/app/models/manager_refresh/inventory_object.rb similarity index 50% rename from app/models/manager_refresh/dto.rb rename to app/models/manager_refresh/inventory_object.rb index 05a6245f58a..a8df284cbd0 100644 --- a/app/models/manager_refresh/dto.rb +++ b/app/models/manager_refresh/inventory_object.rb @@ -1,14 +1,14 @@ module ManagerRefresh - class Dto + class InventoryObject attr_accessor :object - attr_reader :dto_collection, :data + attr_reader :inventory_collection, :data - delegate :manager_ref, :to => :dto_collection + delegate :manager_ref, :to => :inventory_collection delegate :id, :to => :object, :allow_nil => true delegate :[], :[]=, :to => :data - def initialize(dto_collection, data) - @dto_collection = dto_collection + def initialize(inventory_collection, data) + @inventory_collection = inventory_collection @data = data @object = nil @allowed_attributes_index = nil @@ -22,14 +22,14 @@ def load object end - def attributes(dto_collection_scope = nil) - # We should explicitly pass a scope, since the dto can be mapped to more DtoCollections with different blacklist + def attributes(inventory_collection_scope = nil) + # We should explicitly pass a scope, since the inventory_object can be mapped to more InventoryCollections with different blacklist # and whitelist. The generic code always passes a scope. - dto_collection_scope ||= dto_collection + inventory_collection_scope ||= inventory_collection # First transform the values data.each do |key, value| - if !allowed?(dto_collection_scope, key) + if !allowed?(inventory_collection_scope, key) next elsif loadable?(value) data[key] = value.load @@ -41,11 +41,11 @@ def attributes(dto_collection_scope = nil) end # Then return a new hash containing only the values according to the whitelist and the blacklist - data.select { |key, _value| allowed?(dto_collection_scope, key) } + data.select { |key, _value| allowed?(inventory_collection_scope, key) } end def to_s - "Dto:('#{manager_uuid}', #{dto_collection})" + "InventoryObject:('#{manager_uuid}', #{inventory_collection})" end def inspect @@ -54,16 +54,16 @@ def inspect private - def allowed?(dto_collection_scope, key) + def allowed?(inventory_collection_scope, key) # TODO(lsmola) can we make this O(1)? This check will be performed for each record in the DB - return false if dto_collection_scope.attributes_blacklist.present? && dto_collection_scope.attributes_blacklist.include?(key) - return false if dto_collection_scope.attributes_whitelist.present? && !dto_collection_scope.attributes_whitelist.include?(key) + return false if inventory_collection_scope.attributes_blacklist.present? && inventory_collection_scope.attributes_blacklist.include?(key) + return false if inventory_collection_scope.attributes_whitelist.present? && !inventory_collection_scope.attributes_whitelist.include?(key) true end def loadable?(value) - value.kind_of?(::ManagerRefresh::DtoLazy) || value.kind_of?(::ManagerRefresh::Dto) + value.kind_of?(::ManagerRefresh::InventoryObjectLazy) || value.kind_of?(::ManagerRefresh::InventoryObject) end end end diff --git a/app/models/manager_refresh/inventory_object_lazy.rb b/app/models/manager_refresh/inventory_object_lazy.rb new file mode 100644 index 00000000000..bee11a35da5 --- /dev/null +++ b/app/models/manager_refresh/inventory_object_lazy.rb @@ -0,0 +1,63 @@ +module ManagerRefresh + class InventoryObjectLazy + include Vmdb::Logging + + attr_reader :ems_ref, :inventory_collection, :key, :default + + def initialize(inventory_collection, ems_ref, key: nil, default: nil) + @ems_ref = ems_ref + @inventory_collection = inventory_collection + @key = key + @default = default + end + + def to_s + ems_ref + end + + def inspect + suffix = "" + suffix += ", key: #{key}" if key.present? + "InventoryObjectLazy:('#{self}', #{inventory_collection})#{suffix}" + end + + def load + key ? load_object_with_key : load_object + end + + def dependency? + # If key is not set, InventoryObjectLazy is a dependency, cause it points to the record itself. Otherwise + # InventoryObjectLazy is a dependency only if it points to an attribute which is a dependency or a relation. + !!(!key || transitive_dependency?) + end + + def transitive_dependency? + # If the dependency is inventory_collection.lazy_find(:ems_ref, :key => :stack) + # and a :stack is a relation to another object, in the InventoryObject object, + # then this relation is considered transitive. + !!(key && (inventory_collection.dependency_attributes.keys.include?(key) || + inventory_collection.model_class.reflect_on_association(key))) + end + + private + + def load_object_with_key + # TODO(lsmola) Log error if we are accessing path that is present in blacklist or not present in whitelist + found = inventory_collection.find(to_s) + if found.present? + if found.try(:data).present? + found.data[key] || default + else + found.public_send(key) + end + else + default + end + end + + def load_object + inventory_collection_member = inventory_collection.find(to_s) + inventory_collection_member.respond_to?(:object) ? inventory_collection_member.object : inventory_collection_member + end + end +end diff --git a/app/models/manager_refresh/refresh_parser_dto.rb b/app/models/manager_refresh/refresh_parser_dto.rb deleted file mode 100644 index 49593a3c59f..00000000000 --- a/app/models/manager_refresh/refresh_parser_dto.rb +++ /dev/null @@ -1,43 +0,0 @@ -module ManagerRefresh - class RefreshParserDto - def initialize(ems, options = nil) - @ems = ems - @options = options || {} - @data = {:_dto_collection => true} - end - - def process_dto_collection(collection, key) - collection.each do |item| - new_result = yield(item) - next if new_result.blank? - - dto = @data[key].new_dto(new_result) - @data[key] << dto - end - end - - def add_dto_collection(model_class, association, manager_ref = nil) - delete_method = model_class.new.respond_to?(:disconnect_inv) ? :disconnect_inv : nil - - @data[association] = ::ManagerRefresh::DtoCollection.new(model_class, - :parent => @ems, - :association => association, - :manager_ref => manager_ref, - :delete_method => delete_method) - end - - def add_cloud_manager_db_cached_dto(model_class, association, manager_ref = nil) - @data[association] = ::ManagerRefresh::DtoCollection.new(model_class, - :parent => @ems.parent_manager, - :association => association, - :manager_ref => manager_ref, - :strategy => :local_db_cache_all) - end - - class << self - def ems_inv_to_hashes(ems, options = nil) - new(ems, options).ems_inv_to_hashes - end - end - end -end diff --git a/app/models/manager_refresh/refresh_parser_inventory_object.rb b/app/models/manager_refresh/refresh_parser_inventory_object.rb new file mode 100644 index 00000000000..c8a8ed2b1a9 --- /dev/null +++ b/app/models/manager_refresh/refresh_parser_inventory_object.rb @@ -0,0 +1,43 @@ +module ManagerRefresh + class RefreshParserInventoryObject + def initialize(ems, options = nil) + @ems = ems + @options = options || {} + @data = {:_inventory_collection => true} + end + + def process_inventory_collection(collection, key) + collection.each do |item| + new_result = yield(item) + next if new_result.blank? + + inventory_object = @data[key].new_inventory_object(new_result) + @data[key] << inventory_object + end + end + + def add_inventory_collection(model_class, association, manager_ref = nil) + delete_method = model_class.new.respond_to?(:disconnect_inv) ? :disconnect_inv : nil + + @data[association] = ::ManagerRefresh::InventoryCollection.new(model_class, + :parent => @ems, + :association => association, + :manager_ref => manager_ref, + :delete_method => delete_method) + end + + def add_cloud_manager_db_cached_inventory_object(model_class, association, manager_ref = nil) + @data[association] = ::ManagerRefresh::InventoryCollection.new(model_class, + :parent => @ems.parent_manager, + :association => association, + :manager_ref => manager_ref, + :strategy => :local_db_cache_all) + end + + class << self + def ems_inv_to_hashes(ems, options = nil) + new(ems, options).ems_inv_to_hashes + end + end + end +end diff --git a/app/models/manager_refresh/save_collection/helper.rb b/app/models/manager_refresh/save_collection/helper.rb index 8d6149aecf5..7b5118c3192 100644 --- a/app/models/manager_refresh/save_collection/helper.rb +++ b/app/models/manager_refresh/save_collection/helper.rb @@ -1,16 +1,16 @@ module ManagerRefresh::SaveCollection module Helper - def save_dto_inventory(ems, dto_collection) - _log.info("Synchronizing #{ems.name} collection #{dto_collection.size} of size #{dto_collection} to database") + def save_inventory_object_inventory(ems, inventory_collection) + _log.info("Synchronizing #{ems.name} collection #{inventory_collection.size} of size #{inventory_collection} to database") - if dto_collection.custom_save_block.present? - _log.info("Synchronizing #{ems.name} collection #{dto_collection.size} using a custom save block") - dto_collection.custom_save_block.call(ems, dto_collection) + if inventory_collection.custom_save_block.present? + _log.info("Synchronizing #{ems.name} collection #{inventory_collection.size} using a custom save block") + inventory_collection.custom_save_block.call(ems, inventory_collection) else - save_inventory(dto_collection) + save_inventory(inventory_collection) end - _log.info("Synchronized #{ems.name} collection #{dto_collection}") - dto_collection.saved = true + _log.info("Synchronized #{ems.name} collection #{inventory_collection}") + inventory_collection.saved = true end def log_format_deletes(deletes) @@ -33,73 +33,73 @@ def log_format_deletes(deletes) private - def save_inventory(dto_collection) - dto_collection.parent.reload if dto_collection.parent - association = dto_collection.load_from_db + def save_inventory(inventory_collection) + inventory_collection.parent.reload if inventory_collection.parent + association = inventory_collection.load_from_db record_index = {} - create_or_update_inventory!(dto_collection, record_index, association) + create_or_update_inventory!(inventory_collection, record_index, association) - # Delete only if DtoCollection is complete. If it's not complete, we are sending only subset of the records, so - # we cannot invoke deleting of the missing records. - delete_inventory!(dto_collection, record_index, association) if dto_collection.delete_allowed? + # Delete only if InventoryCollection is complete. If it's not complete, we are sending only subset of the records, + # so we cannot invoke deleting of the missing records. + delete_inventory!(inventory_collection, record_index, association) if inventory_collection.delete_allowed? end - def create_or_update_inventory!(dto_collection, record_index, association) - unique_index_keys = dto_collection.manager_ref_to_cols + def create_or_update_inventory!(inventory_collection, record_index, association) + unique_index_keys = inventory_collection.manager_ref_to_cols association.find_each do |record| # TODO(lsmola) the old code was able to deal with duplicate records, should we do that? The old data still can # have duplicate methods, so we should clean them up. It will slow up the indexing though. - record_index[dto_collection.object_index_with_keys(unique_index_keys, record)] = record + record_index[inventory_collection.object_index_with_keys(unique_index_keys, record)] = record end - entity_builder = get_entity_builder(dto_collection, association) + entity_builder = get_entity_builder(inventory_collection, association) - dto_collection_size = dto_collection.size - created_counter = 0 - _log.info("*************** PROCESSING #{dto_collection} of size #{dto_collection_size} ***************") + inventory_collection_size = inventory_collection.size + created_counter = 0 + _log.info("*************** PROCESSING #{inventory_collection} of size #{inventory_collection_size} ***************") ActiveRecord::Base.transaction do - dto_collection.each do |dto| - hash = dto.attributes(dto_collection) - dto.object = record_index.delete(dto.manager_uuid) - if dto.object.nil? - next unless dto_collection.create_allowed? - dto.object = entity_builder.create!(hash.except(:id)) - created_counter += 1 + inventory_collection.each do |inventory_object| + hash = inventory_object.attributes(inventory_collection) + inventory_object.object = record_index.delete(inventory_object.manager_uuid) + if inventory_object.object.nil? + next unless inventory_collection.create_allowed? + inventory_object.object = entity_builder.create!(hash.except(:id)) + created_counter += 1 else - dto.object.assign_attributes(hash.except(:id, :type)) - if dto.object.changed? - dto.object.save! + inventory_object.object.assign_attributes(hash.except(:id, :type)) + if inventory_object.object.changed? + inventory_object.object.save! end end - dto.object.try(:reload) + inventory_object.object.try(:reload) end end - _log.info("*************** PROCESSED #{dto_collection}, created=#{created_counter}, "\ - "updated=#{dto_collection_size - created_counter} ***************") + _log.info("*************** PROCESSED #{inventory_collection}, created=#{created_counter}, "\ + "updated=#{inventory_collection_size - created_counter} ***************") end - def delete_inventory!(dto_collection, record_index, association) + def delete_inventory!(inventory_collection, record_index, association) # Delete the items no longer found unless record_index.blank? deletes = record_index.values - _log.info("*************** DELETING #{dto_collection} of size #{deletes.size} ***************") + _log.info("*************** DELETING #{inventory_collection} of size #{deletes.size} ***************") type = association.proxy_association.reflection.name - _log.info("[#{type}] Deleting with method '#{dto_collection.delete_method}' #{log_format_deletes(deletes)}") + _log.info("[#{type}] Deleting with method '#{inventory_collection.delete_method}' #{log_format_deletes(deletes)}") ActiveRecord::Base.transaction do - deletes.map(&dto_collection.delete_method) + deletes.map(&inventory_collection.delete_method) end - _log.info("*************** DELETED #{dto_collection} ***************") + _log.info("*************** DELETED #{inventory_collection} ***************") end end - def get_entity_builder(dto_collection, association) - if dto_collection.parent - association_meta_info = dto_collection.parent.class.reflect_on_association(dto_collection.association) - association_meta_info.options[:through].blank? ? association : dto_collection.model_class + def get_entity_builder(inventory_collection, association) + if inventory_collection.parent + association_meta_info = inventory_collection.parent.class.reflect_on_association(inventory_collection.association) + association_meta_info.options[:through].blank? ? association : inventory_collection.model_class else - dto_collection.model_class + inventory_collection.model_class end end end diff --git a/app/models/manager_refresh/save_collection/recursive.rb b/app/models/manager_refresh/save_collection/recursive.rb index a7c08441fca..bc9a18d93d6 100644 --- a/app/models/manager_refresh/save_collection/recursive.rb +++ b/app/models/manager_refresh/save_collection/recursive.rb @@ -3,38 +3,38 @@ class Recursive extend ManagerRefresh::SaveCollection::Helper class << self - def save_collections(ems, dto_collections) - graph = ManagerRefresh::DtoCollection::Graph.new(dto_collections.values) + def save_collections(ems, inventory_collections) + graph = ManagerRefresh::InventoryCollection::Graph.new(inventory_collections.values) graph.build_directed_acyclic_graph! - graph.nodes.each do |dto_collection| - save_collection(ems, dto_collection, []) + graph.nodes.each do |inventory_collection| + save_collection(ems, inventory_collection, []) end end private - def save_collection(ems, dto_collection, traversed_collections) - unless dto_collection.kind_of? ::ManagerRefresh::DtoCollection - raise "A ManagerRefresh::SaveInventory needs a DtoCollection object, it got: #{dto_collection.inspect}" + def save_collection(ems, inventory_collection, traversed_collections) + unless inventory_collection.kind_of? ::ManagerRefresh::InventoryCollection + raise "A ManagerRefresh::SaveInventory needs a InventoryCollection object, it got: #{inventory_collection.inspect}" end - return if dto_collection.saved? + return if inventory_collection.saved? - traversed_collections << dto_collection + traversed_collections << inventory_collection - unless dto_collection.saveable? - dto_collection.dependencies.each do |dependency| + unless inventory_collection.saveable? + inventory_collection.dependencies.each do |dependency| next if dependency.saved? if traversed_collections.include? dependency - raise "Edge from #{dto_collection} to #{dependency} creates a cycle" + raise "Edge from #{inventory_collection} to #{dependency} creates a cycle" end save_collection(ems, dependency, traversed_collections) end end - _log.info("Saving #{dto_collection} of size #{dto_collection.size}") - save_dto_inventory(ems, dto_collection) + _log.info("Saving #{inventory_collection} of size #{inventory_collection.size}") + save_inventory_object_inventory(ems, inventory_collection) end end end diff --git a/app/models/manager_refresh/save_collection/topological_sort.rb b/app/models/manager_refresh/save_collection/topological_sort.rb index 5b5e1ec9254..ca6c9444a9d 100644 --- a/app/models/manager_refresh/save_collection/topological_sort.rb +++ b/app/models/manager_refresh/save_collection/topological_sort.rb @@ -3,8 +3,8 @@ class TopologicalSort extend ManagerRefresh::SaveCollection::Helper class << self - def save_collections(ems, dto_collections) - graph = ManagerRefresh::DtoCollection::Graph.new(dto_collections.values) + def save_collections(ems, inventory_collections) + graph = ManagerRefresh::InventoryCollection::Graph.new(inventory_collections.values) graph.build_directed_acyclic_graph! layers = ManagerRefresh::Graph::TopologicalSort.new(graph).topological_sort @@ -21,8 +21,8 @@ def save_collections(ems, dto_collections) layers.each_with_index do |layer, index| _log.info("Saving manager #{ems.name} | Layer #{index}") - layer.each do |dto_collection| - save_dto_inventory(ems, dto_collection) unless dto_collection.saved? + layer.each do |inventory_collection| + save_inventory_object_inventory(ems, inventory_collection) unless inventory_collection.saved? end _log.info("Saved manager #{ems.name} | Layer #{index}") end diff --git a/app/models/manager_refresh/save_inventory.rb b/app/models/manager_refresh/save_inventory.rb index f52adf5c7e8..48444f50274 100644 --- a/app/models/manager_refresh/save_inventory.rb +++ b/app/models/manager_refresh/save_inventory.rb @@ -1,14 +1,14 @@ module ManagerRefresh class SaveInventory class << self - def save_inventory(ems, dto_collections) + def save_inventory(ems, inventory_collections) _log.info("#{log_header(ems)} Saving EMS Inventory...Start") - dto_saving_strategy = Settings.ems_refresh[ems.class.ems_type].try(:[], :dto_saving_strategy) - if dto_saving_strategy == :recursive - ManagerRefresh::SaveCollection::Recursive.save_collections(ems, dto_collections) + inventory_object_saving_strategy = Settings.ems_refresh[ems.class.ems_type].try(:[], :inventory_object_saving_strategy) + if inventory_object_saving_strategy == :recursive + ManagerRefresh::SaveCollection::Recursive.save_collections(ems, inventory_collections) else - ManagerRefresh::SaveCollection::TopologicalSort.save_collections(ems, dto_collections) + ManagerRefresh::SaveCollection::TopologicalSort.save_collections(ems, inventory_collections) end _log.info("#{log_header(ems)} Saving EMS Inventory...Complete") diff --git a/spec/models/manager_refresh/save_inventory/acyclic_graph_of_dto_collections_spec.rb b/spec/models/manager_refresh/save_inventory/acyclic_graph_of_inventory_collections_spec.rb similarity index 71% rename from spec/models/manager_refresh/save_inventory/acyclic_graph_of_dto_collections_spec.rb rename to spec/models/manager_refresh/save_inventory/acyclic_graph_of_inventory_collections_spec.rb index dbc16507778..920abf7d19b 100644 --- a/spec/models/manager_refresh/save_inventory/acyclic_graph_of_dto_collections_spec.rb +++ b/spec/models/manager_refresh/save_inventory/acyclic_graph_of_inventory_collections_spec.rb @@ -7,8 +7,8 @@ ###################################################################################################################### # - # Testing SaveInventory for directed acyclic graph (DAG) of the DtoCollection dependencies, testing that relations - # are saved correctly for a testing set of DtoCollections whose dependencies look like: + # Testing SaveInventory for directed acyclic graph (DAG) of the InventoryCollection dependencies, testing that + # relations are saved correctly for a testing set of InventoryCollections whose dependencies look like: # # +--------------+ +--------------+ # | +-----> | @@ -34,67 +34,69 @@ # The +--> marks a dependency, so Hardware +---> Vm means Hardware depends on Vm. So in this case, we need to make # sure Vm is saved to DB before Hardware does, since Hardware references Vm records # - # The dependency of the DtoCollection is caused byt find or by lazy_find called on DtoCollection. + # The dependency of the InventoryCollection is caused byt find or by lazy_find called on InventoryCollection. # # Explanation of the lazy_find vs find: # - # If we do lazy_find, it means DtoCollection can be empty at that time and this lazy_find is evaluated right before - # the DtoCollections is saved. That means it doesn't depend on order how the DtoCollections are filled with data. - # If we use find, the DtoCollection already needs to be filled with data, otherwise the find results with nil. + # If we do lazy_find, it means InventoryCollection can be empty at that time and this lazy_find is evaluated right + # before the InventoryCollections is saved. That means it doesn't depend on order how the InventoryCollections are + # filled with data. If we use find, the InventoryCollection already needs to be filled with data, otherwise the find + # results with nil. # # Example of the dependency: - # the data of the DtoCollection for Hardware contains + # the data of the InventoryCollection for Hardware contains # # @data[:vms].lazy_find(instance.id) or @data[:vms].find(instance.id) # - # This code results in LazyDto or Dto object, which we need to translate into Vm record, when we save Hardware - # record. Therefore, this depends on Vm being already saved in the DB, + # This code results in LazyInventoryObject or InventoryObject object, which we need to translate into Vm record, + # when we save Hardware record. Therefore, this depends on Vm being already saved in the DB, # # Example of the dependency using :key: # # Using @data[:hardwares].lazy_find(instance.image_id, :key => :guest_os) we do not create a dependency, this code - # fetches an attribute :guest_os of the Hardware Dto, we do not create a dependency. The attribute is available - # before we save the Hardware DtoCollection. + # fetches an attribute :guest_os of the Hardware InventoryObject, we do not create a dependency. The attribute is + # available before we save the Hardware InventoryCollection. # # But using @data[:hardwares].lazy_find(instance.image_id, :key => :vm_or_template), the attribute we are fetching - # is a record itself, that means we depend on the Hardware DtoCollection being saved. + # is a record itself, that means we depend on the Hardware InventoryCollection being saved. # ###################################################################################################################### # # Test all settings for ManagerRefresh::SaveInventory - [{:dto_saving_strategy => nil}, - {:dto_saving_strategy => :recursive}, - ].each do |dto_settings| - context "with settings #{dto_settings}" do + [{:inventory_object_saving_strategy => nil}, + {:inventory_object_saving_strategy => :recursive}, + ].each do |inventory_object_settings| + context "with settings #{inventory_object_settings}" do before :each do @zone = FactoryGirl.create(:zone) @ems = FactoryGirl.create(:ems_cloud, :zone => @zone) allow(@ems.class).to receive(:ems_type).and_return(:mock) - allow(Settings.ems_refresh).to receive(:mock).and_return(dto_settings) + allow(Settings.ems_refresh).to receive(:mock).and_return(inventory_object_settings) end context 'with empty DB' do before :each do - initialize_data_and_dto_collections + initialize_data_and_inventory_collections end - it 'creates a graph of DtoCollections' do - # Fill the DtoCollections with data - add_data_to_dto_collection(@data[:vms], @vm_data_1, @vm_data_12, @vm_data_2, @vm_data_4) - add_data_to_dto_collection(@data[:miq_templates], @image_data_1, @image_data_2, @image_data_3) - add_data_to_dto_collection(@data[:key_pairs], @key_pair_data_1, @key_pair_data_12, @key_pair_data_2, @key_pair_data_3) - add_data_to_dto_collection(@data[:hardwares], @hardware_data_1, @hardware_data_2, @hardware_data_12) - add_data_to_dto_collection(@data[:disks], @disk_data_1, @disk_data_12, @disk_data_13, @disk_data_2) - add_data_to_dto_collection(@data[:networks], @public_network_data_1, @public_network_data_12, - @public_network_data_13, @public_network_data_14, @public_network_data_2) - add_data_to_dto_collection(@data[:flavors], @flavor_data_1, @flavor_data_2, @flavor_data_3) - - # Invoke the DtoCollections saving + it 'creates a graph of InventoryCollections' do + # Fill the InventoryCollections with data + add_data_to_inventory_collection(@data[:vms], @vm_data_1, @vm_data_12, @vm_data_2, @vm_data_4) + add_data_to_inventory_collection(@data[:miq_templates], @image_data_1, @image_data_2, @image_data_3) + add_data_to_inventory_collection(@data[:key_pairs], @key_pair_data_1, @key_pair_data_12, @key_pair_data_2, + @key_pair_data_3) + add_data_to_inventory_collection(@data[:hardwares], @hardware_data_1, @hardware_data_2, @hardware_data_12) + add_data_to_inventory_collection(@data[:disks], @disk_data_1, @disk_data_12, @disk_data_13, @disk_data_2) + add_data_to_inventory_collection(@data[:networks], @public_network_data_1, @public_network_data_12, + @public_network_data_13, @public_network_data_14, @public_network_data_2) + add_data_to_inventory_collection(@data[:flavors], @flavor_data_1, @flavor_data_2, @flavor_data_3) + + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert saved data - assert_full_dto_collections_graph + assert_full_inventory_collections_graph assert_all_records_match_hashes( [Vm.all, @ems.vms], @@ -117,22 +119,23 @@ }) end - it 'creates and updates a graph of DtoCollections' do - # Fill the DtoCollections with data - add_data_to_dto_collection(@data[:vms], @vm_data_1, @vm_data_12, @vm_data_2, @vm_data_4) - add_data_to_dto_collection(@data[:miq_templates], @image_data_1, @image_data_2, @image_data_3) - add_data_to_dto_collection(@data[:key_pairs], @key_pair_data_1, @key_pair_data_12, @key_pair_data_2, @key_pair_data_3) - add_data_to_dto_collection(@data[:hardwares], @hardware_data_1, @hardware_data_2, @hardware_data_12) - add_data_to_dto_collection(@data[:disks], @disk_data_1, @disk_data_12, @disk_data_13, @disk_data_2) - add_data_to_dto_collection(@data[:networks], @public_network_data_1, @public_network_data_12, - @public_network_data_13, @public_network_data_14, @public_network_data_2) - add_data_to_dto_collection(@data[:flavors], @flavor_data_1, @flavor_data_2, @flavor_data_3) - - # Invoke the DtoCollections saving + it 'creates and updates a graph of InventoryCollections' do + # Fill the InventoryCollections with data + add_data_to_inventory_collection(@data[:vms], @vm_data_1, @vm_data_12, @vm_data_2, @vm_data_4) + add_data_to_inventory_collection(@data[:miq_templates], @image_data_1, @image_data_2, @image_data_3) + add_data_to_inventory_collection(@data[:key_pairs], @key_pair_data_1, @key_pair_data_12, @key_pair_data_2, + @key_pair_data_3) + add_data_to_inventory_collection(@data[:hardwares], @hardware_data_1, @hardware_data_2, @hardware_data_12) + add_data_to_inventory_collection(@data[:disks], @disk_data_1, @disk_data_12, @disk_data_13, @disk_data_2) + add_data_to_inventory_collection(@data[:networks], @public_network_data_1, @public_network_data_12, + @public_network_data_13, @public_network_data_14, @public_network_data_2) + add_data_to_inventory_collection(@data[:flavors], @flavor_data_1, @flavor_data_2, @flavor_data_3) + + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert that saved data have the updated values, checking id to make sure the original records are updated - assert_full_dto_collections_graph + assert_full_inventory_collections_graph assert_all_records_match_hashes( [Vm.all, @ems.vms], @@ -161,27 +164,28 @@ vm4 = Vm.find_by(:ems_ref => "vm_ems_ref_4") # Second saving with the updated data - # Fill the DtoCollections with data, that have a modified name - initialize_data_and_dto_collections - add_data_to_dto_collection(@data[:vms], - @vm_data_1.merge(:name => "vm_name_1_changed"), - @vm_data_12.merge(:name => "vm_name_12_changed"), - @vm_data_2.merge(:name => "vm_name_2_changed"), - @vm_data_4.merge(:name => "vm_name_4_changed"), - vm_data(5)) - add_data_to_dto_collection(@data[:miq_templates], @image_data_1, @image_data_2, @image_data_3) - add_data_to_dto_collection(@data[:key_pairs], @key_pair_data_1, @key_pair_data_12, @key_pair_data_2, @key_pair_data_3) - add_data_to_dto_collection(@data[:hardwares], @hardware_data_1, @hardware_data_2, @hardware_data_12) - add_data_to_dto_collection(@data[:disks], @disk_data_1, @disk_data_12, @disk_data_13, @disk_data_2) - add_data_to_dto_collection(@data[:networks], @public_network_data_1, @public_network_data_12, - @public_network_data_13, @public_network_data_14, @public_network_data_2) - add_data_to_dto_collection(@data[:flavors], @flavor_data_1, @flavor_data_2, @flavor_data_3) - - # Invoke the DtoCollections saving + # Fill the InventoryCollections with data, that have a modified name + initialize_data_and_inventory_collections + add_data_to_inventory_collection(@data[:vms], + @vm_data_1.merge(:name => "vm_name_1_changed"), + @vm_data_12.merge(:name => "vm_name_12_changed"), + @vm_data_2.merge(:name => "vm_name_2_changed"), + @vm_data_4.merge(:name => "vm_name_4_changed"), + vm_data(5)) + add_data_to_inventory_collection(@data[:miq_templates], @image_data_1, @image_data_2, @image_data_3) + add_data_to_inventory_collection(@data[:key_pairs], @key_pair_data_1, @key_pair_data_12, @key_pair_data_2, + @key_pair_data_3) + add_data_to_inventory_collection(@data[:hardwares], @hardware_data_1, @hardware_data_2, @hardware_data_12) + add_data_to_inventory_collection(@data[:disks], @disk_data_1, @disk_data_12, @disk_data_13, @disk_data_2) + add_data_to_inventory_collection(@data[:networks], @public_network_data_1, @public_network_data_12, + @public_network_data_13, @public_network_data_14, @public_network_data_2) + add_data_to_inventory_collection(@data[:flavors], @flavor_data_1, @flavor_data_2, @flavor_data_3) + + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert saved data - assert_full_dto_collections_graph + assert_full_inventory_collections_graph # Assert that saved data have the updated values, checking id to make sure the original records are updated assert_all_records_match_hashes( [Vm.all, @ems.vms], @@ -215,12 +219,12 @@ end context 'with the existing data in the DB' do - it 'updates existing records with a graph of DtoCollections' do + it 'updates existing records with a graph of InventoryCollections' do # Fill the mocked data in the DB initialize_mocked_records # Assert that the mocked data in the DB are correct - assert_full_dto_collections_graph + assert_full_inventory_collections_graph assert_all_records_match_hashes( [Vm.all, @ems.vms], @@ -242,32 +246,33 @@ :location => "default_value_unknown", }) - # Now save the records using DtoCollections - # Fill the DtoCollections with data, that have a modified name - initialize_data_and_dto_collections - add_data_to_dto_collection(@data[:vms], - @vm_data_1.merge(:name => "vm_name_1_changed"), - @vm_data_12.merge(:name => "vm_name_12_changed"), - @vm_data_2.merge(:name => "vm_name_2_changed"), - @vm_data_4.merge(:name => "vm_name_4_changed"), - vm_data(5)) - add_data_to_dto_collection(@data[:miq_templates], @image_data_1, @image_data_2, @image_data_3) - add_data_to_dto_collection(@data[:key_pairs], @key_pair_data_1, @key_pair_data_12, @key_pair_data_2, @key_pair_data_3) - add_data_to_dto_collection(@data[:hardwares], @hardware_data_1, @hardware_data_2, @hardware_data_12) - add_data_to_dto_collection(@data[:disks], - @disk_data_1.merge(:device_type => "nvme_ssd_1"), - @disk_data_12.merge(:device_type => "nvme_ssd_12"), - @disk_data_13.merge(:device_type => "nvme_ssd_13"), - @disk_data_2.merge(:device_type => "nvme_ssd_2")) - add_data_to_dto_collection(@data[:networks], @public_network_data_1, @public_network_data_12, - @public_network_data_13, @public_network_data_14, @public_network_data_2) - add_data_to_dto_collection(@data[:flavors], @flavor_data_1, @flavor_data_2, @flavor_data_3) - - # Invoke the DtoCollections saving + # Now save the records using InventoryCollections + # Fill the InventoryCollections with data, that have a modified name + initialize_data_and_inventory_collections + add_data_to_inventory_collection(@data[:vms], + @vm_data_1.merge(:name => "vm_name_1_changed"), + @vm_data_12.merge(:name => "vm_name_12_changed"), + @vm_data_2.merge(:name => "vm_name_2_changed"), + @vm_data_4.merge(:name => "vm_name_4_changed"), + vm_data(5)) + add_data_to_inventory_collection(@data[:miq_templates], @image_data_1, @image_data_2, @image_data_3) + add_data_to_inventory_collection(@data[:key_pairs], @key_pair_data_1, @key_pair_data_12, @key_pair_data_2, + @key_pair_data_3) + add_data_to_inventory_collection(@data[:hardwares], @hardware_data_1, @hardware_data_2, @hardware_data_12) + add_data_to_inventory_collection(@data[:disks], + @disk_data_1.merge(:device_type => "nvme_ssd_1"), + @disk_data_12.merge(:device_type => "nvme_ssd_12"), + @disk_data_13.merge(:device_type => "nvme_ssd_13"), + @disk_data_2.merge(:device_type => "nvme_ssd_2")) + add_data_to_inventory_collection(@data[:networks], @public_network_data_1, @public_network_data_12, + @public_network_data_13, @public_network_data_14, @public_network_data_2) + add_data_to_inventory_collection(@data[:flavors], @flavor_data_1, @flavor_data_2, @flavor_data_3) + + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert saved data - assert_full_dto_collections_graph + assert_full_inventory_collections_graph # Assert that saved data have the updated values, checking id to make sure the original records are updated assert_all_records_match_hashes( [Vm.all, @ems.vms], @@ -346,13 +351,13 @@ context "lazy_find vs find" do before :each do - # Initialize the DtoCollections + # Initialize the InventoryCollections @data = {} - @data[:vms] = ::ManagerRefresh::DtoCollection.new( + @data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) - @data[:hardwares] = ::ManagerRefresh::DtoCollection.new( + @data[:hardwares] = ::ManagerRefresh::InventoryCollection.new( Hardware, :parent => @ems, :association => :hardwares, @@ -360,17 +365,17 @@ end it "misses relation using find and loading data in a wrong order" do - # Load data into DtoCollections in wrong order, we are accessing @data[:vms] using find before we filled it - # with data + # Load data into InventoryCollections in wrong order, we are accessing @data[:vms] using find before we filled + # it with data @vm_data_1 = vm_data(1) @hardware_data_1 = hardware_data(1).merge( :vm_or_template => @data[:vms].find(vm_data(1)[:ems_ref]) ) - add_data_to_dto_collection(@data[:vms], @vm_data_1) - add_data_to_dto_collection(@data[:hardwares], @hardware_data_1) + add_data_to_inventory_collection(@data[:vms], @vm_data_1) + add_data_to_inventory_collection(@data[:hardwares], @hardware_data_1) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert saved data @@ -379,16 +384,17 @@ end it "has a relation using find and loading data in a right order" do - # Load data into DtoCollections in a right order, we are accessing @data[:vms] using find when the data are present + # Load data into InventoryCollections in a right order, we are accessing @data[:vms] using find when the data + # are present @vm_data_1 = vm_data(1) - add_data_to_dto_collection(@data[:vms], @vm_data_1) + add_data_to_inventory_collection(@data[:vms], @vm_data_1) @hardware_data_1 = hardware_data(1).merge( :vm_or_template => @data[:vms].find(vm_data(1)[:ems_ref]) ) - add_data_to_dto_collection(@data[:hardwares], @hardware_data_1) + add_data_to_inventory_collection(@data[:hardwares], @hardware_data_1) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert saved data @@ -397,17 +403,17 @@ end it "has a relation using lazy_find and loading data in a wrong order" do - # Using lazy_find, it doesn't matter in which order we load data into dto_collections. The lazy relation - # is evaluated before saving, all DtoCollections have data loaded at that time. + # Using lazy_find, it doesn't matter in which order we load data into inventory_collections. The lazy relation + # is evaluated before saving, all InventoryCollections have data loaded at that time. @vm_data_1 = vm_data(1) @hardware_data_1 = hardware_data(1).merge( :vm_or_template => @data[:vms].lazy_find(vm_data(1)[:ems_ref]) ) - add_data_to_dto_collection(@data[:vms], @vm_data_1) - add_data_to_dto_collection(@data[:hardwares], @hardware_data_1) + add_data_to_inventory_collection(@data[:vms], @vm_data_1) + add_data_to_inventory_collection(@data[:hardwares], @hardware_data_1) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert saved data @@ -418,7 +424,7 @@ end end - def assert_full_dto_collections_graph + def assert_full_inventory_collections_graph vm1 = Vm.find_by(:ems_ref => "vm_ems_ref_1") vm12 = Vm.find_by(:ems_ref => "vm_ems_ref_12") vm2 = Vm.find_by(:ems_ref => "vm_ems_ref_2") @@ -462,38 +468,38 @@ def assert_full_dto_collections_graph expect(key_pair3.vms).to match_array(nil) end - def initialize_data_and_dto_collections - # Initialize the DtoCollections + def initialize_data_and_inventory_collections + # Initialize the InventoryCollections @data = {} - @data[:vms] = ::ManagerRefresh::DtoCollection.new( + @data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) - @data[:key_pairs] = ::ManagerRefresh::DtoCollection.new( + @data[:key_pairs] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::AuthKeyPair, :parent => @ems, :association => :key_pairs, :manager_ref => [:name]) - @data[:miq_templates] = ::ManagerRefresh::DtoCollection.new( + @data[:miq_templates] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Template, :parent => @ems, :association => :miq_templates) - @data[:hardwares] = ::ManagerRefresh::DtoCollection.new( + @data[:hardwares] = ::ManagerRefresh::InventoryCollection.new( Hardware, :parent => @ems, :association => :hardwares, :manager_ref => [:vm_or_template]) - @data[:disks] = ::ManagerRefresh::DtoCollection.new( + @data[:disks] = ::ManagerRefresh::InventoryCollection.new( Disk, :parent => @ems, :association => :disks, :manager_ref => [:hardware, :device_name]) - @data[:networks] = ::ManagerRefresh::DtoCollection.new( + @data[:networks] = ::ManagerRefresh::InventoryCollection.new( Network, :parent => @ems, :association => :networks, :manager_ref => [:hardware, :description]) - @data[:flavors] = ::ManagerRefresh::DtoCollection.new( + @data[:flavors] = ::ManagerRefresh::InventoryCollection.new( Flavor, :parent => @ems, :association => :flavors, @@ -513,7 +519,7 @@ def initialize_data_and_dto_collections @key_pair_data_2 = key_pair_data(2) @key_pair_data_3 = key_pair_data(3) - @vm_data_1 = vm_data(1).merge( + @vm_data_1 = vm_data(1).merge( :flavor => @data[:flavors].lazy_find(flavor_data(1)[:name]), :genealogy_parent => @data[:miq_templates].lazy_find(image_data(1)[:ems_ref]), :key_pairs => [@data[:key_pairs].lazy_find(key_pair_data(1)[:name])], @@ -521,6 +527,7 @@ def initialize_data_and_dto_collections :key => :hostname, :default => 'default_value_unknown'), ) + @vm_data_12 = vm_data(12).merge( :flavor => @data[:flavors].lazy_find(flavor_data(1)[:name]), :genealogy_parent => @data[:miq_templates].lazy_find(image_data(1)[:ems_ref]), @@ -530,7 +537,8 @@ def initialize_data_and_dto_collections :key => :hostname, :default => 'default_value_unknown'), ) - @vm_data_2 = vm_data(2).merge( + + @vm_data_2 = vm_data(2).merge( :flavor => @data[:flavors].lazy_find(flavor_data(2)[:name]), :genealogy_parent => @data[:miq_templates].lazy_find(image_data(2)[:ems_ref]), :key_pairs => [@data[:key_pairs].lazy_find(key_pair_data(2)[:name])], @@ -538,7 +546,8 @@ def initialize_data_and_dto_collections :key => :hostname, :default => 'default_value_unknown'), ) - @vm_data_4 = vm_data(4).merge( + + @vm_data_4 = vm_data(4).merge( :flavor => @data[:flavors].lazy_find(flavor_data(4)[:name]), :genealogy_parent => @data[:miq_templates].lazy_find(image_data(4)[:ems_ref]), :key_pairs => [@data[:key_pairs].lazy_find(key_pair_data(4)[:name])].compact, @@ -547,47 +556,56 @@ def initialize_data_and_dto_collections :default => 'default_value_unknown'), ) - @hardware_data_1 = hardware_data(1).merge( + @hardware_data_1 = hardware_data(1).merge( :guest_os => @data[:miq_templates].lazy_find(image_data(1)[:ems_ref], :key => :guest_os), :vm_or_template => @data[:vms].lazy_find(vm_data(1)[:ems_ref]) ) + @hardware_data_12 = hardware_data(12).merge( :guest_os => @data[:miq_templates].lazy_find(image_data(1)[:ems_ref], :key => :guest_os), :vm_or_template => @data[:vms].lazy_find(vm_data(12)[:ems_ref]) ) - @hardware_data_2 = hardware_data(2).merge( + + @hardware_data_2 = hardware_data(2).merge( :guest_os => @data[:miq_templates].lazy_find(image_data(2)[:ems_ref], :key => :guest_os), :vm_or_template => @data[:vms].lazy_find(vm_data(2)[:ems_ref]) ) - @disk_data_1 = disk_data(1).merge( + @disk_data_1 = disk_data(1).merge( :hardware => @data[:hardwares].lazy_find(vm_data(1)[:ems_ref]), ) + @disk_data_12 = disk_data(12).merge( :hardware => @data[:hardwares].lazy_find(vm_data(12)[:ems_ref]), ) + @disk_data_13 = disk_data(13).merge( :hardware => @data[:hardwares].lazy_find(vm_data(12)[:ems_ref]), ) - @disk_data_2 = disk_data(2).merge( + + @disk_data_2 = disk_data(2).merge( :hardware => @data[:hardwares].lazy_find(vm_data(2)[:ems_ref]), ) - @public_network_data_1 = public_network_data(1).merge( + @public_network_data_1 = public_network_data(1).merge( :hardware => @data[:hardwares].lazy_find(vm_data(1)[:ems_ref]), ) + @public_network_data_12 = public_network_data(12).merge( :hardware => @data[:hardwares].lazy_find(vm_data(12)[:ems_ref]), ) + @public_network_data_13 = public_network_data(13).merge( :hardware => @data[:hardwares].lazy_find(vm_data(12)[:ems_ref]), :description => "public_2" ) + @public_network_data_14 = public_network_data(14).merge( :hardware => @data[:hardwares].lazy_find(vm_data(12)[:ems_ref]), :description => "public_2" # duplicate key, network will be ignored ) - @public_network_data_2 = public_network_data(2).merge( + + @public_network_data_2 = public_network_data(2).merge( :hardware => @data[:hardwares].lazy_find(vm_data(2)[:ems_ref]), ) end diff --git a/spec/models/manager_refresh/save_inventory/graph_of_dto_collections_spec.rb b/spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_spec.rb similarity index 72% rename from spec/models/manager_refresh/save_inventory/graph_of_dto_collections_spec.rb rename to spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_spec.rb index 9f169f3e87a..d728833d542 100644 --- a/spec/models/manager_refresh/save_inventory/graph_of_dto_collections_spec.rb +++ b/spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_spec.rb @@ -7,8 +7,8 @@ ###################################################################################################################### # - # Testing SaveInventory for general graph of the DtoCollection dependencies, testing that relations - # are saved correctly for a testing set of DtoCollections whose dependencies look like: + # Testing SaveInventory for general graph of the InventoryCollection dependencies, testing that relations + # are saved correctly for a testing set of InventoryCollections whose dependencies look like: # # 1. Example, cycle is stack -> stack # @@ -276,155 +276,155 @@ ###################################################################################################################### # # Test all settings for ManagerRefresh::SaveInventory - [{:dto_saving_strategy => nil}, - {:dto_saving_strategy => :recursive}, - ].each do |dto_settings| - context "with settings #{dto_settings}" do + [{:inventory_object_saving_strategy => nil}, + {:inventory_object_saving_strategy => :recursive}, + ].each do |inventory_object_settings| + context "with settings #{inventory_object_settings}" do before :each do @zone = FactoryGirl.create(:zone) @ems = FactoryGirl.create(:ems_cloud, :zone => @zone) @ems_network = FactoryGirl.create(:ems_network, :zone => @zone, :parent_manager => @ems) allow(@ems.class).to receive(:ems_type).and_return(:mock) - allow(Settings.ems_refresh).to receive(:mock).and_return(dto_settings) + allow(Settings.ems_refresh).to receive(:mock).and_return(inventory_object_settings) end context 'with empty DB' do before :each do - initialize_dto_collections + initialize_inventory_collections end - it 'creates and updates a graph of DtoCollections with cycle stack -> stack' do + it 'creates and updates a graph of InventoryCollections with cycle stack -> stack' do # Doing 2 times, to make sure we first create all records then update all records 2.times do - # Fill the DtoCollections with data + # Fill the InventoryCollections with data init_stack_data_with_stack_stack_cycle init_resource_data - add_data_to_dto_collection(@data[:orchestration_stacks], - @orchestration_stack_data_0_1, - @orchestration_stack_data_0_2, - @orchestration_stack_data_1_11, - @orchestration_stack_data_1_12, - @orchestration_stack_data_11_21, - @orchestration_stack_data_12_22, - @orchestration_stack_data_12_23) - add_data_to_dto_collection(@data[:orchestration_stacks_resources], - @orchestration_stack_resource_data_1_11, - @orchestration_stack_resource_data_1_11_1, - @orchestration_stack_resource_data_1_12, - @orchestration_stack_resource_data_1_12_1, - @orchestration_stack_resource_data_11_21, - @orchestration_stack_resource_data_12_22, - @orchestration_stack_resource_data_12_23) - - # Invoke the DtoCollections saving + add_data_to_inventory_collection(@data[:orchestration_stacks], + @orchestration_stack_data_0_1, + @orchestration_stack_data_0_2, + @orchestration_stack_data_1_11, + @orchestration_stack_data_1_12, + @orchestration_stack_data_11_21, + @orchestration_stack_data_12_22, + @orchestration_stack_data_12_23) + add_data_to_inventory_collection(@data[:orchestration_stacks_resources], + @orchestration_stack_resource_data_1_11, + @orchestration_stack_resource_data_1_11_1, + @orchestration_stack_resource_data_1_12, + @orchestration_stack_resource_data_1_12_1, + @orchestration_stack_resource_data_11_21, + @orchestration_stack_resource_data_12_22, + @orchestration_stack_resource_data_12_23) + + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert saved data - assert_full_dto_collections_graph + assert_full_inventory_collections_graph end end - it 'creates and updates a graph of DtoCollections with cycle stack -> resource -> stack, through resource :key' do + it 'creates and updates a graph of InventoryCollections with cycle stack -> resource -> stack, through resource :key' do # Doing 2 times, to make sure we first create all records then update all records 2.times do - # Fill the DtoCollections with data + # Fill the InventoryCollections with data init_stack_data_with_stack_resource_stack_cycle init_resource_data - add_data_to_dto_collection(@data[:orchestration_stacks], - @orchestration_stack_data_0_1, - @orchestration_stack_data_0_2, - @orchestration_stack_data_1_11, - @orchestration_stack_data_1_12, - @orchestration_stack_data_11_21, - @orchestration_stack_data_12_22, - @orchestration_stack_data_12_23) - add_data_to_dto_collection(@data[:orchestration_stacks_resources], - @orchestration_stack_resource_data_1_11, - @orchestration_stack_resource_data_1_11_1, - @orchestration_stack_resource_data_1_12, - @orchestration_stack_resource_data_1_12_1, - @orchestration_stack_resource_data_11_21, - @orchestration_stack_resource_data_12_22, - @orchestration_stack_resource_data_12_23) - - # Invoke the DtoCollections saving + add_data_to_inventory_collection(@data[:orchestration_stacks], + @orchestration_stack_data_0_1, + @orchestration_stack_data_0_2, + @orchestration_stack_data_1_11, + @orchestration_stack_data_1_12, + @orchestration_stack_data_11_21, + @orchestration_stack_data_12_22, + @orchestration_stack_data_12_23) + add_data_to_inventory_collection(@data[:orchestration_stacks_resources], + @orchestration_stack_resource_data_1_11, + @orchestration_stack_resource_data_1_11_1, + @orchestration_stack_resource_data_1_12, + @orchestration_stack_resource_data_1_12_1, + @orchestration_stack_resource_data_11_21, + @orchestration_stack_resource_data_12_22, + @orchestration_stack_resource_data_12_23) + + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert saved data - assert_full_dto_collections_graph + assert_full_inventory_collections_graph end end end - context 'with empty DB and reversed DtoCollections' do + context 'with empty DB and reversed InventoryCollections' do before :each do - initialize_dto_collections_reversed + initialize_inventory_collections_reversed end - it 'creates and updates a graph of DtoCollections with cycle stack -> stack' do + it 'creates and updates a graph of InventoryCollections with cycle stack -> stack' do # Doing 2 times, to make sure we first create all records then update all records 2.times do - # Fill the DtoCollections with data + # Fill the InventoryCollections with data init_stack_data_with_stack_stack_cycle init_resource_data - add_data_to_dto_collection(@data[:orchestration_stacks], - @orchestration_stack_data_0_1, - @orchestration_stack_data_0_2, - @orchestration_stack_data_1_11, - @orchestration_stack_data_1_12, - @orchestration_stack_data_11_21, - @orchestration_stack_data_12_22, - @orchestration_stack_data_12_23) - add_data_to_dto_collection(@data[:orchestration_stacks_resources], - @orchestration_stack_resource_data_1_11, - @orchestration_stack_resource_data_1_11_1, - @orchestration_stack_resource_data_1_12, - @orchestration_stack_resource_data_1_12_1, - @orchestration_stack_resource_data_11_21, - @orchestration_stack_resource_data_12_22, - @orchestration_stack_resource_data_12_23) - - # Invoke the DtoCollections saving + add_data_to_inventory_collection(@data[:orchestration_stacks], + @orchestration_stack_data_0_1, + @orchestration_stack_data_0_2, + @orchestration_stack_data_1_11, + @orchestration_stack_data_1_12, + @orchestration_stack_data_11_21, + @orchestration_stack_data_12_22, + @orchestration_stack_data_12_23) + add_data_to_inventory_collection(@data[:orchestration_stacks_resources], + @orchestration_stack_resource_data_1_11, + @orchestration_stack_resource_data_1_11_1, + @orchestration_stack_resource_data_1_12, + @orchestration_stack_resource_data_1_12_1, + @orchestration_stack_resource_data_11_21, + @orchestration_stack_resource_data_12_22, + @orchestration_stack_resource_data_12_23) + + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert saved data - assert_full_dto_collections_graph + assert_full_inventory_collections_graph end end - it 'creates and updates a graph of DtoCollections with cycle stack -> resource -> stack, through resource :key' do + it 'creates and updates a graph of InventoryCollections with cycle stack -> resource -> stack, through resource :key' do # Doing 2 times, to make sure we first create all records then update all records 2.times do - # Fill the DtoCollections with data + # Fill the InventoryCollections with data init_stack_data_with_stack_resource_stack_cycle init_resource_data - add_data_to_dto_collection(@data[:orchestration_stacks], - @orchestration_stack_data_0_1, - @orchestration_stack_data_0_2, - @orchestration_stack_data_1_11, - @orchestration_stack_data_1_12, - @orchestration_stack_data_11_21, - @orchestration_stack_data_12_22, - @orchestration_stack_data_12_23) - add_data_to_dto_collection(@data[:orchestration_stacks_resources], - @orchestration_stack_resource_data_1_11, - @orchestration_stack_resource_data_1_11_1, - @orchestration_stack_resource_data_1_12, - @orchestration_stack_resource_data_1_12_1, - @orchestration_stack_resource_data_11_21, - @orchestration_stack_resource_data_12_22, - @orchestration_stack_resource_data_12_23) - - # Invoke the DtoCollections saving + add_data_to_inventory_collection(@data[:orchestration_stacks], + @orchestration_stack_data_0_1, + @orchestration_stack_data_0_2, + @orchestration_stack_data_1_11, + @orchestration_stack_data_1_12, + @orchestration_stack_data_11_21, + @orchestration_stack_data_12_22, + @orchestration_stack_data_12_23) + add_data_to_inventory_collection(@data[:orchestration_stacks_resources], + @orchestration_stack_resource_data_1_11, + @orchestration_stack_resource_data_1_11_1, + @orchestration_stack_resource_data_1_12, + @orchestration_stack_resource_data_1_12_1, + @orchestration_stack_resource_data_11_21, + @orchestration_stack_resource_data_12_22, + @orchestration_stack_resource_data_12_23) + + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert saved data - assert_full_dto_collections_graph + assert_full_inventory_collections_graph end end end @@ -432,15 +432,15 @@ context 'with complex cycle' do it 'test network_port -> stack -> resource -> stack' do @data = {} - @data[:orchestration_stacks] = ::ManagerRefresh::DtoCollection.new( + @data[:orchestration_stacks] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::OrchestrationStack, :parent => @ems, :association => :orchestration_stacks) - @data[:orchestration_stacks_resources] = ::ManagerRefresh::DtoCollection.new( + @data[:orchestration_stacks_resources] = ::ManagerRefresh::InventoryCollection.new( OrchestrationStackResource, :parent => @ems, :association => :orchestration_stacks_resources) - @data[:network_ports] = ::ManagerRefresh::DtoCollection.new( + @data[:network_ports] = ::ManagerRefresh::InventoryCollection.new( NetworkPort, :parent => @ems.network_manager, :association => :network_ports) @@ -461,40 +461,40 @@ :key => :parent) ) - add_data_to_dto_collection(@data[:orchestration_stacks], - @orchestration_stack_data_0_1, - @orchestration_stack_data_0_2, - @orchestration_stack_data_1_11, - @orchestration_stack_data_1_12, - @orchestration_stack_data_11_21, - @orchestration_stack_data_12_22, - @orchestration_stack_data_12_23) - add_data_to_dto_collection(@data[:orchestration_stacks_resources], - @orchestration_stack_resource_data_1_11, - @orchestration_stack_resource_data_1_11_1, - @orchestration_stack_resource_data_1_12, - @orchestration_stack_resource_data_1_12_1, - @orchestration_stack_resource_data_11_21, - @orchestration_stack_resource_data_12_22, - @orchestration_stack_resource_data_12_23) - add_data_to_dto_collection(@data[:network_ports], - @network_port_1, - @network_port_2, - @network_port_3) - - # Invoke the DtoCollections saving + add_data_to_inventory_collection(@data[:orchestration_stacks], + @orchestration_stack_data_0_1, + @orchestration_stack_data_0_2, + @orchestration_stack_data_1_11, + @orchestration_stack_data_1_12, + @orchestration_stack_data_11_21, + @orchestration_stack_data_12_22, + @orchestration_stack_data_12_23) + add_data_to_inventory_collection(@data[:orchestration_stacks_resources], + @orchestration_stack_resource_data_1_11, + @orchestration_stack_resource_data_1_11_1, + @orchestration_stack_resource_data_1_12, + @orchestration_stack_resource_data_1_12_1, + @orchestration_stack_resource_data_11_21, + @orchestration_stack_resource_data_12_22, + @orchestration_stack_resource_data_12_23) + add_data_to_inventory_collection(@data[:network_ports], + @network_port_1, + @network_port_2, + @network_port_3) + + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert saved data - assert_full_dto_collections_graph + assert_full_inventory_collections_graph network_port_1 = NetworkPort.find_by(:ems_ref => "network_port_ems_ref_1") network_port_2 = NetworkPort.find_by(:ems_ref => "network_port_ems_ref_2") network_port_3 = NetworkPort.find_by(:ems_ref => "network_port_ems_ref_3") - orchestration_stack_0_1 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_0_1") - orchestration_stack_1_11 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_1_11") - orchestration_stack_1_12 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_1_12") + orchestration_stack_0_1 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_0_1") + orchestration_stack_1_11 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_1_11") + orchestration_stack_1_12 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_1_12") expect(network_port_1.device).to eq(orchestration_stack_0_1) expect(network_port_2.device).to eq(orchestration_stack_1_11) expect(network_port_3.device).to eq(orchestration_stack_1_12) @@ -502,15 +502,15 @@ it 'test network_port -> stack -> resource -> stack reverted' do @data = {} - @data[:network_ports] = ::ManagerRefresh::DtoCollection.new( + @data[:network_ports] = ::ManagerRefresh::InventoryCollection.new( NetworkPort, :parent => @ems.network_manager, :association => :network_ports) - @data[:orchestration_stacks_resources] = ::ManagerRefresh::DtoCollection.new( + @data[:orchestration_stacks_resources] = ::ManagerRefresh::InventoryCollection.new( OrchestrationStackResource, :parent => @ems, :association => :orchestration_stacks_resources) - @data[:orchestration_stacks] = ::ManagerRefresh::DtoCollection.new( + @data[:orchestration_stacks] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::OrchestrationStack, :parent => @ems, :association => :orchestration_stacks) @@ -531,39 +531,39 @@ :key => :parent) ) - add_data_to_dto_collection(@data[:orchestration_stacks], - @orchestration_stack_data_0_1, - @orchestration_stack_data_0_2, - @orchestration_stack_data_1_11, - @orchestration_stack_data_1_12, - @orchestration_stack_data_11_21, - @orchestration_stack_data_12_22, - @orchestration_stack_data_12_23) - add_data_to_dto_collection(@data[:orchestration_stacks_resources], - @orchestration_stack_resource_data_1_11, - @orchestration_stack_resource_data_1_11_1, - @orchestration_stack_resource_data_1_12, - @orchestration_stack_resource_data_1_12_1, - @orchestration_stack_resource_data_11_21, - @orchestration_stack_resource_data_12_22, - @orchestration_stack_resource_data_12_23) - add_data_to_dto_collection(@data[:network_ports], - @network_port_1, - @network_port_2, - @network_port_3) - - # Invoke the DtoCollections saving + add_data_to_inventory_collection(@data[:orchestration_stacks], + @orchestration_stack_data_0_1, + @orchestration_stack_data_0_2, + @orchestration_stack_data_1_11, + @orchestration_stack_data_1_12, + @orchestration_stack_data_11_21, + @orchestration_stack_data_12_22, + @orchestration_stack_data_12_23) + add_data_to_inventory_collection(@data[:orchestration_stacks_resources], + @orchestration_stack_resource_data_1_11, + @orchestration_stack_resource_data_1_11_1, + @orchestration_stack_resource_data_1_12, + @orchestration_stack_resource_data_1_12_1, + @orchestration_stack_resource_data_11_21, + @orchestration_stack_resource_data_12_22, + @orchestration_stack_resource_data_12_23) + add_data_to_inventory_collection(@data[:network_ports], + @network_port_1, + @network_port_2, + @network_port_3) + + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert saved data - assert_full_dto_collections_graph + assert_full_inventory_collections_graph network_port_1 = NetworkPort.find_by(:ems_ref => "network_port_ems_ref_1") network_port_2 = NetworkPort.find_by(:ems_ref => "network_port_ems_ref_2") network_port_3 = NetworkPort.find_by(:ems_ref => "network_port_ems_ref_3") - orchestration_stack_0_1 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_0_1") - orchestration_stack_1_11 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_1_11") - orchestration_stack_1_12 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_1_12") + orchestration_stack_0_1 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_0_1") + orchestration_stack_1_11 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_1_11") + orchestration_stack_1_12 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_1_12") expect(network_port_1.device).to eq(orchestration_stack_0_1) expect(network_port_2.device).to eq(orchestration_stack_1_11) expect(network_port_3.device).to eq(orchestration_stack_1_12) @@ -574,7 +574,7 @@ # saved the data in a correct order. In this case, we would need to save this data by creating a tree of # data dependencies and saving it according to the tree. @data = {} - @data[:network_ports] = ::ManagerRefresh::DtoCollection.new( + @data[:network_ports] = ::ManagerRefresh::InventoryCollection.new( NetworkPort, :parent => @ems.network_manager, :association => :network_ports) @@ -587,12 +587,12 @@ :key => :device) ) - add_data_to_dto_collection(@data[:network_ports], - @network_port_1, - @network_port_2) + add_data_to_inventory_collection(@data[:network_ports], + @network_port_1, + @network_port_2) - # Invoke the DtoCollections saving and check we raise an exception that a cycle was found, after we attempted - # to remove the cycles. + # Invoke the InventoryCollections saving and check we raise an exception that a cycle was found, after we + # attempted to remove the cycles. expect { ManagerRefresh::SaveInventory.save_inventory(@ems, @data) }.to raise_error(/^Cycle from /) end @@ -615,15 +615,15 @@ # @data[:orchestration_stacks] but not when pointing to @data[:network_ports], then we can transform the # edge correctly and this cycle is solvable. @data = {} - @data[:orchestration_stacks] = ::ManagerRefresh::DtoCollection.new( + @data[:orchestration_stacks] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::OrchestrationStack, :parent => @ems, :association => :orchestration_stacks) - @data[:orchestration_stacks_resources] = ::ManagerRefresh::DtoCollection.new( + @data[:orchestration_stacks_resources] = ::ManagerRefresh::InventoryCollection.new( OrchestrationStackResource, :parent => @ems, :association => :orchestration_stacks_resources) - @data[:network_ports] = ::ManagerRefresh::DtoCollection.new( + @data[:network_ports] = ::ManagerRefresh::InventoryCollection.new( NetworkPort, :parent => @ems.network_manager, :association => :network_ports) @@ -653,47 +653,47 @@ :device => @data[:network_ports].lazy_find(network_port_data(7)[:ems_ref]) ) - add_data_to_dto_collection(@data[:orchestration_stacks], - @orchestration_stack_data_0_1, - @orchestration_stack_data_0_2, - @orchestration_stack_data_1_11, - @orchestration_stack_data_1_12, - @orchestration_stack_data_11_21, - @orchestration_stack_data_12_22, - @orchestration_stack_data_12_23) - add_data_to_dto_collection(@data[:orchestration_stacks_resources], - @orchestration_stack_resource_data_1_11, - @orchestration_stack_resource_data_1_11_1, - @orchestration_stack_resource_data_1_12, - @orchestration_stack_resource_data_1_12_1, - @orchestration_stack_resource_data_11_21, - @orchestration_stack_resource_data_12_22, - @orchestration_stack_resource_data_12_23) - add_data_to_dto_collection(@data[:network_ports], - @network_port_1, - @network_port_2, - @network_port_3, - @network_port_4, - @network_port_5, - @network_port_6) - - # Invoke the DtoCollections saving and check we raise an exception that a cycle was found, after we attempted - # to remove the cycles. + add_data_to_inventory_collection(@data[:orchestration_stacks], + @orchestration_stack_data_0_1, + @orchestration_stack_data_0_2, + @orchestration_stack_data_1_11, + @orchestration_stack_data_1_12, + @orchestration_stack_data_11_21, + @orchestration_stack_data_12_22, + @orchestration_stack_data_12_23) + add_data_to_inventory_collection(@data[:orchestration_stacks_resources], + @orchestration_stack_resource_data_1_11, + @orchestration_stack_resource_data_1_11_1, + @orchestration_stack_resource_data_1_12, + @orchestration_stack_resource_data_1_12_1, + @orchestration_stack_resource_data_11_21, + @orchestration_stack_resource_data_12_22, + @orchestration_stack_resource_data_12_23) + add_data_to_inventory_collection(@data[:network_ports], + @network_port_1, + @network_port_2, + @network_port_3, + @network_port_4, + @network_port_5, + @network_port_6) + + # Invoke the InventoryCollections saving and check we raise an exception that a cycle was found, after we + # attempted to remove the cycles. # TODO(lsmola) make this spec pass, by enhancing the logic around transitive edges expect { ManagerRefresh::SaveInventory.save_inventory(@ems, @data) }.to raise_error(/^Cycle from /) end it 'test network_port -> stack -> resource -> stack and network_port -> resource -> stack -> resource -> stack ' do @data = {} - @data[:orchestration_stacks] = ::ManagerRefresh::DtoCollection.new( + @data[:orchestration_stacks] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::OrchestrationStack, :parent => @ems, :association => :orchestration_stacks) - @data[:orchestration_stacks_resources] = ::ManagerRefresh::DtoCollection.new( + @data[:orchestration_stacks_resources] = ::ManagerRefresh::InventoryCollection.new( OrchestrationStackResource, :parent => @ems, :association => :orchestration_stacks_resources) - @data[:network_ports] = ::ManagerRefresh::DtoCollection.new( + @data[:network_ports] = ::ManagerRefresh::InventoryCollection.new( NetworkPort, :parent => @ems.network_manager, :association => :network_ports) @@ -717,33 +717,33 @@ :device => @data[:orchestration_stacks_resources].lazy_find(orchestration_stack_data("12_22")[:ems_ref]) ) - add_data_to_dto_collection(@data[:orchestration_stacks], - @orchestration_stack_data_0_1, - @orchestration_stack_data_0_2, - @orchestration_stack_data_1_11, - @orchestration_stack_data_1_12, - @orchestration_stack_data_11_21, - @orchestration_stack_data_12_22, - @orchestration_stack_data_12_23) - add_data_to_dto_collection(@data[:orchestration_stacks_resources], - @orchestration_stack_resource_data_1_11, - @orchestration_stack_resource_data_1_11_1, - @orchestration_stack_resource_data_1_12, - @orchestration_stack_resource_data_1_12_1, - @orchestration_stack_resource_data_11_21, - @orchestration_stack_resource_data_12_22, - @orchestration_stack_resource_data_12_23) - add_data_to_dto_collection(@data[:network_ports], - @network_port_1, - @network_port_2, - @network_port_3, - @network_port_4) - - # Invoke the DtoCollections saving + add_data_to_inventory_collection(@data[:orchestration_stacks], + @orchestration_stack_data_0_1, + @orchestration_stack_data_0_2, + @orchestration_stack_data_1_11, + @orchestration_stack_data_1_12, + @orchestration_stack_data_11_21, + @orchestration_stack_data_12_22, + @orchestration_stack_data_12_23) + add_data_to_inventory_collection(@data[:orchestration_stacks_resources], + @orchestration_stack_resource_data_1_11, + @orchestration_stack_resource_data_1_11_1, + @orchestration_stack_resource_data_1_12, + @orchestration_stack_resource_data_1_12_1, + @orchestration_stack_resource_data_11_21, + @orchestration_stack_resource_data_12_22, + @orchestration_stack_resource_data_12_23) + add_data_to_inventory_collection(@data[:network_ports], + @network_port_1, + @network_port_2, + @network_port_3, + @network_port_4) + + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert saved data - assert_full_dto_collections_graph + assert_full_inventory_collections_graph network_port_1 = NetworkPort.find_by(:ems_ref => "network_port_ems_ref_1") network_port_2 = NetworkPort.find_by(:ems_ref => "network_port_ems_ref_2") @@ -764,40 +764,40 @@ end context 'with the existing data in the DB' do - it 'updates existing records with a graph of DtoCollections with cycle stack -> stack' do + it 'updates existing records with a graph of InventoryCollections with cycle stack -> stack' do # Create all relations directly in DB initialize_mocked_records # And check the relations are correct - assert_full_dto_collections_graph + assert_full_inventory_collections_graph # Now we will update existing DB using SaveInventory - # Fill the DtoCollections with data - initialize_dto_collections + # Fill the InventoryCollections with data + initialize_inventory_collections init_stack_data_with_stack_stack_cycle init_resource_data - add_data_to_dto_collection(@data[:orchestration_stacks], - @orchestration_stack_data_0_1, - @orchestration_stack_data_0_2, - @orchestration_stack_data_1_11, - @orchestration_stack_data_1_12, - @orchestration_stack_data_11_21, - @orchestration_stack_data_12_22, - @orchestration_stack_data_12_23) - add_data_to_dto_collection(@data[:orchestration_stacks_resources], - @orchestration_stack_resource_data_1_11, - @orchestration_stack_resource_data_1_11_1, - @orchestration_stack_resource_data_1_12, - @orchestration_stack_resource_data_1_12_1, - @orchestration_stack_resource_data_11_21, - @orchestration_stack_resource_data_12_22, - @orchestration_stack_resource_data_12_23) - - # Invoke the DtoCollections saving + add_data_to_inventory_collection(@data[:orchestration_stacks], + @orchestration_stack_data_0_1, + @orchestration_stack_data_0_2, + @orchestration_stack_data_1_11, + @orchestration_stack_data_1_12, + @orchestration_stack_data_11_21, + @orchestration_stack_data_12_22, + @orchestration_stack_data_12_23) + add_data_to_inventory_collection(@data[:orchestration_stacks_resources], + @orchestration_stack_resource_data_1_11, + @orchestration_stack_resource_data_1_11_1, + @orchestration_stack_resource_data_1_12, + @orchestration_stack_resource_data_1_12_1, + @orchestration_stack_resource_data_11_21, + @orchestration_stack_resource_data_12_22, + @orchestration_stack_resource_data_12_23) + + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert saved data - assert_full_dto_collections_graph + assert_full_inventory_collections_graph # Check that we only updated the existing records orchestration_stack_0_1 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_0_1") @@ -840,40 +840,40 @@ expect(orchestration_stack_resource_12_23).to eq(@orchestration_stack_resource_12_23) end - it 'updates existing records with a graph of DtoCollections with cycle stack -> resource -> stack, through resource :key' do + it 'updates existing records with a graph of InventoryCollections with cycle stack -> resource -> stack, through resource :key' do # Create all relations directly in DB initialize_mocked_records # And check the relations are correct - assert_full_dto_collections_graph + assert_full_inventory_collections_graph # Now we will update existing DB using SaveInventory - # Fill the DtoCollections with data - initialize_dto_collections + # Fill the InventoryCollections with data + initialize_inventory_collections init_stack_data_with_stack_resource_stack_cycle init_resource_data - add_data_to_dto_collection(@data[:orchestration_stacks], - @orchestration_stack_data_0_1, - @orchestration_stack_data_0_2, - @orchestration_stack_data_1_11, - @orchestration_stack_data_1_12, - @orchestration_stack_data_11_21, - @orchestration_stack_data_12_22, - @orchestration_stack_data_12_23) - add_data_to_dto_collection(@data[:orchestration_stacks_resources], - @orchestration_stack_resource_data_1_11, - @orchestration_stack_resource_data_1_11_1, - @orchestration_stack_resource_data_1_12, - @orchestration_stack_resource_data_1_12_1, - @orchestration_stack_resource_data_11_21, - @orchestration_stack_resource_data_12_22, - @orchestration_stack_resource_data_12_23) - - # Invoke the DtoCollections saving + add_data_to_inventory_collection(@data[:orchestration_stacks], + @orchestration_stack_data_0_1, + @orchestration_stack_data_0_2, + @orchestration_stack_data_1_11, + @orchestration_stack_data_1_12, + @orchestration_stack_data_11_21, + @orchestration_stack_data_12_22, + @orchestration_stack_data_12_23) + add_data_to_inventory_collection(@data[:orchestration_stacks_resources], + @orchestration_stack_resource_data_1_11, + @orchestration_stack_resource_data_1_11_1, + @orchestration_stack_resource_data_1_12, + @orchestration_stack_resource_data_1_12_1, + @orchestration_stack_resource_data_11_21, + @orchestration_stack_resource_data_12_22, + @orchestration_stack_resource_data_12_23) + + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert saved data - assert_full_dto_collections_graph + assert_full_inventory_collections_graph # Check that we only updated the existing records orchestration_stack_0_1 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_0_1") @@ -919,7 +919,7 @@ end end - def assert_full_dto_collections_graph + def assert_full_inventory_collections_graph orchestration_stack_0_1 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_0_1") orchestration_stack_0_2 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_0_2") orchestration_stack_1_11 = OrchestrationStack.find_by(:ems_ref => "stack_ems_ref_1_11") @@ -978,28 +978,28 @@ def assert_full_dto_collections_graph expect(orchestration_stack_resource_12_23.stack).to eq(orchestration_stack_1_12) end - def initialize_dto_collections - # Initialize the DtoCollections + def initialize_inventory_collections + # Initialize the InventoryCollections @data = {} - @data[:orchestration_stacks] = ::ManagerRefresh::DtoCollection.new( + @data[:orchestration_stacks] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::OrchestrationStack, :parent => @ems, :association => :orchestration_stacks) - @data[:orchestration_stacks_resources] = ::ManagerRefresh::DtoCollection.new( + @data[:orchestration_stacks_resources] = ::ManagerRefresh::InventoryCollection.new( OrchestrationStackResource, :parent => @ems, :association => :orchestration_stacks_resources) end - def initialize_dto_collections_reversed - # Initialize the DtoCollections in reversed order, so we know that untangling of the cycle does not depend on the - # order of the DtoCollections + def initialize_inventory_collections_reversed + # Initialize the InventoryCollections in reversed order, so we know that untangling of the cycle does not depend on + # the order of the InventoryCollections @data = {} - @data[:orchestration_stacks_resources] = ::ManagerRefresh::DtoCollection.new( + @data[:orchestration_stacks_resources] = ::ManagerRefresh::InventoryCollection.new( OrchestrationStackResource, :parent => @ems, :association => :orchestration_stacks_resources) - @data[:orchestration_stacks] = ::ManagerRefresh::DtoCollection.new( + @data[:orchestration_stacks] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::OrchestrationStack, :parent => @ems, :association => :orchestration_stacks) @@ -1023,30 +1023,36 @@ def init_stack_data_with_stack_stack_cycle end def init_stack_data_with_stack_resource_stack_cycle - @orchestration_stack_data_0_1 = orchestration_stack_data("0_1").merge( + @orchestration_stack_data_0_1 = orchestration_stack_data("0_1").merge( :parent => @data[:orchestration_stacks_resources].lazy_find(orchestration_stack_data("0_1")[:ems_ref], :key => :stack) ) - @orchestration_stack_data_0_2 = orchestration_stack_data("0_2").merge( + + @orchestration_stack_data_0_2 = orchestration_stack_data("0_2").merge( :parent => @data[:orchestration_stacks_resources].lazy_find(orchestration_stack_data("0_2")[:ems_ref], :key => :stack) ) - @orchestration_stack_data_1_11 = orchestration_stack_data("1_11").merge( + + @orchestration_stack_data_1_11 = orchestration_stack_data("1_11").merge( :parent => @data[:orchestration_stacks_resources].lazy_find(orchestration_stack_data("1_11")[:ems_ref], :key => :stack) ) - @orchestration_stack_data_1_12 = orchestration_stack_data("1_12").merge( + + @orchestration_stack_data_1_12 = orchestration_stack_data("1_12").merge( :parent => @data[:orchestration_stacks_resources].lazy_find(orchestration_stack_data("1_12")[:ems_ref], :key => :stack) ) + @orchestration_stack_data_11_21 = orchestration_stack_data("11_21").merge( :parent => @data[:orchestration_stacks_resources].lazy_find(orchestration_stack_data("11_21")[:ems_ref], :key => :stack) ) + @orchestration_stack_data_12_22 = orchestration_stack_data("12_22").merge( :parent => @data[:orchestration_stacks_resources].lazy_find(orchestration_stack_data("12_22")[:ems_ref], :key => :stack) ) + @orchestration_stack_data_12_23 = orchestration_stack_data("12_23").merge( :parent => @data[:orchestration_stacks_resources].lazy_find(orchestration_stack_data("12_23")[:ems_ref], :key => :stack) diff --git a/spec/models/manager_refresh/save_inventory/graph_of_dto_collections_targeted_refresh_spec.rb b/spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_targeted_refresh_spec.rb similarity index 61% rename from spec/models/manager_refresh/save_inventory/graph_of_dto_collections_targeted_refresh_spec.rb rename to spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_targeted_refresh_spec.rb index 0497b64e8a0..0c7b68d6adb 100644 --- a/spec/models/manager_refresh/save_inventory/graph_of_dto_collections_targeted_refresh_spec.rb +++ b/spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_targeted_refresh_spec.rb @@ -10,24 +10,24 @@ ###################################################################################################################### # # Test all settings for ManagerRefresh::SaveInventory - [{:dto_saving_strategy => nil}, - {:dto_saving_strategy => :recursive}, - ].each do |dto_settings| - context "with settings #{dto_settings}" do + [{:inventory_object_saving_strategy => nil}, + {:inventory_object_saving_strategy => :recursive}, + ].each do |inventory_object_settings| + context "with settings #{inventory_object_settings}" do before :each do @zone = FactoryGirl.create(:zone) @ems = FactoryGirl.create(:ems_cloud, :zone => @zone) allow(@ems.class).to receive(:ems_type).and_return(:mock) - allow(Settings.ems_refresh).to receive(:mock).and_return(dto_settings) + allow(Settings.ems_refresh).to receive(:mock).and_return(inventory_object_settings) end it "refreshing all records and data collects everything" do # Get the relations - initialize_all_dto_collections - initialize_dto_collection_data + initialize_all_inventory_collections + initialize_inventory_collection_data - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert all data were filled @@ -37,10 +37,10 @@ it "do a targeted refresh that will only create and update a new vm, hardware and disks" do # Get the relations - initialize_all_dto_collections - initialize_dto_collection_data + initialize_all_inventory_collections + initialize_inventory_collection_data - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert all data were filled @@ -48,8 +48,8 @@ assert_everything_is_collected ### Second refresh ### - # Initialize the DtoCollections and data for a new VM hardware and disks - initialize_dto_collections([:vms, :hardwares, :disks]) + # Initialize the InventoryCollections and data for a new VM hardware and disks + initialize_inventory_collections([:vms, :hardwares, :disks]) @vm_data_3 = vm_data(3).merge( :genealogy_parent => @data[:miq_templates].lazy_find(image_data(2)[:ems_ref]), @@ -62,14 +62,14 @@ @disk_data_31 = disk_data(31).merge( :hardware => @data[:hardwares].lazy_find(vm_data(3)[:ems_ref])) - # Fill DtoCollections with data - add_data_to_dto_collection(@data[:vms], - @vm_data_3) - add_data_to_dto_collection(@data[:hardwares], - @hardware_data_3) - add_data_to_dto_collection(@data[:disks], @disk_data_3, @disk_data_31) + # Fill InventoryCollections with data + add_data_to_inventory_collection(@data[:vms], + @vm_data_3) + add_data_to_inventory_collection(@data[:hardwares], + @hardware_data_3) + add_data_to_inventory_collection(@data[:disks], @disk_data_3, @disk_data_31) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) load_records @@ -84,38 +84,44 @@ expect(@vm3.key_pairs.pluck(:id)).to match_array([@key_pair2.id]) assert_everything_is_collected( - :extra_vms => [{ - :ems_ref => "vm_ems_ref_3", - :name => "vm_name_3", - :location => "vm_location_3", - :uid_ems => "vm_uid_ems_3", - :vendor => "amazon", - :raw_power_state => "unknown", - }], - :extra_hardware => [{ - :vm_or_template_id => @vm3.id, - :bitness => 64, - :virtualization_type => "virtualization_type_3", - :guest_os => nil, - }], - :extra_disks => [{ - :hardware_id => @vm3.hardware.id, - :device_name => "disk_name_3", - :device_type => "disk", - }, { - :hardware_id => @vm3.hardware.id, - :device_name => "disk_name_31", - :device_type => "disk", - }] + :extra_vms => [ + { + :ems_ref => "vm_ems_ref_3", + :name => "vm_name_3", + :location => "vm_location_3", + :uid_ems => "vm_uid_ems_3", + :vendor => "amazon", + :raw_power_state => "unknown", + } + ], + :extra_hardware => [ + { + :vm_or_template_id => @vm3.id, + :bitness => 64, + :virtualization_type => "virtualization_type_3", + :guest_os => nil, + } + ], + :extra_disks => [ + { + :hardware_id => @vm3.hardware.id, + :device_name => "disk_name_3", + :device_type => "disk", + }, { + :hardware_id => @vm3.hardware.id, + :device_name => "disk_name_31", + :device_type => "disk", + } + ] ) end it "do a targeted refresh that will create/update vm, then create/update/delete Vm's hardware and disks" do # Get the relations - initialize_all_dto_collections - initialize_dto_collection_data + initialize_all_inventory_collections + initialize_inventory_collection_data - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert all data were filled @@ -123,8 +129,8 @@ assert_everything_is_collected ### Second refresh ### - # Initialize the DtoCollections and data for a new VM - initialize_dto_collections([:vms, :hardwares]) + # Initialize the InventoryCollections and data for a new VM + initialize_inventory_collections([:vms, :hardwares]) @vm_data_3 = vm_data(3).merge( :genealogy_parent => @data[:miq_templates].lazy_find(image_data(2)[:ems_ref]), @@ -133,22 +139,22 @@ :guest_os => @data[:hardwares].lazy_find(image_data(2)[:ems_ref], :key => :guest_os), :vm_or_template => @data[:vms].lazy_find(vm_data(3)[:ems_ref])) - # Fill DtoCollections with data - add_data_to_dto_collection(@data[:vms], - @vm_data_3) - add_data_to_dto_collection(@data[:hardwares], - @hardware_data_3) + # Fill InventoryCollections with data + add_data_to_inventory_collection(@data[:vms], + @vm_data_3) + add_data_to_inventory_collection(@data[:hardwares], + @hardware_data_3) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) ### Third refresh ### - # Initialize the DtoCollections and data for the disks with new disk under a vm + # Initialize the InventoryCollections and data for the disks with new disk under a vm @vm3 = Vm.find_by(:ems_ref => "vm_ems_ref_3") - initialize_dto_collections([:disks]) - @data[:disks] = ::ManagerRefresh::DtoCollection.new( + initialize_inventory_collections([:disks]) + @data[:disks] = ::ManagerRefresh::InventoryCollection.new( Disk, :association => :disks, :parent => @vm3, @@ -160,9 +166,9 @@ @disk_data_31 = disk_data(31).merge( :hardware => @data[:hardwares].lazy_find(vm_data(3)[:ems_ref])) - add_data_to_dto_collection(@data[:disks], @disk_data_3, @disk_data_31) + add_data_to_inventory_collection(@data[:disks], @disk_data_3, @disk_data_31) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert all data were filled @@ -178,29 +184,35 @@ expect(@vm3.key_pairs.pluck(:id)).to match_array([@key_pair2.id]) assert_everything_is_collected( - :extra_vms => [{ - :ems_ref => "vm_ems_ref_3", - :name => "vm_name_3", - :location => "vm_location_3", - :uid_ems => "vm_uid_ems_3", - :vendor => "amazon", - :raw_power_state => "unknown", - }], - :extra_hardware => [{ - :vm_or_template_id => @vm3.id, - :bitness => 64, - :virtualization_type => "virtualization_type_3", - :guest_os => nil, - }], - :extra_disks => [{ - :hardware_id => @vm3.hardware.id, - :device_name => "disk_name_3", - :device_type => "disk", - }, { - :hardware_id => @vm3.hardware.id, - :device_name => "disk_name_31", - :device_type => "disk", - }] + :extra_vms => [ + { + :ems_ref => "vm_ems_ref_3", + :name => "vm_name_3", + :location => "vm_location_3", + :uid_ems => "vm_uid_ems_3", + :vendor => "amazon", + :raw_power_state => "unknown", + } + ], + :extra_hardware => [ + { + :vm_or_template_id => @vm3.id, + :bitness => 64, + :virtualization_type => "virtualization_type_3", + :guest_os => nil, + } + ], + :extra_disks => [ + { + :hardware_id => @vm3.hardware.id, + :device_name => "disk_name_3", + :device_type => "disk", + }, { + :hardware_id => @vm3.hardware.id, + :device_name => "disk_name_31", + :device_type => "disk", + } + ] ) ### Fourth refresh ### @@ -208,8 +220,8 @@ @vm3 = Vm.find_by(:ems_ref => "vm_ems_ref_3") - initialize_dto_collections([:disks]) - @data[:disks] = ::ManagerRefresh::DtoCollection.new( + initialize_inventory_collections([:disks]) + @data[:disks] = ::ManagerRefresh::InventoryCollection.new( Disk, :association => :disks, :parent => @vm3, @@ -219,9 +231,9 @@ @disk_data_32 = disk_data(32).merge( :hardware => @data[:hardwares].lazy_find(vm_data(3)[:ems_ref])) - add_data_to_dto_collection(@data[:disks], @disk_data_3, @disk_data_32) + add_data_to_inventory_collection(@data[:disks], @disk_data_3, @disk_data_32) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert all data were filled @@ -237,39 +249,45 @@ expect(@vm3.key_pairs.pluck(:id)).to match_array([@key_pair2.id]) assert_everything_is_collected( - :extra_vms => [{ - :ems_ref => "vm_ems_ref_3", - :name => "vm_name_3", - :location => "vm_location_3", - :uid_ems => "vm_uid_ems_3", - :vendor => "amazon", - :raw_power_state => "unknown", - }], - :extra_hardware => [{ - :vm_or_template_id => @vm3.id, - :bitness => 64, - :virtualization_type => "virtualization_type_3", - :guest_os => nil, - }], - :extra_disks => [{ - :hardware_id => @vm3.hardware.id, - :device_name => "disk_name_3", - :device_type => "disk", - }, { - :hardware_id => @vm3.hardware.id, - :device_name => "disk_name_32", - :device_type => "disk", - }] + :extra_vms => [ + { + :ems_ref => "vm_ems_ref_3", + :name => "vm_name_3", + :location => "vm_location_3", + :uid_ems => "vm_uid_ems_3", + :vendor => "amazon", + :raw_power_state => "unknown", + } + ], + :extra_hardware => [ + { + :vm_or_template_id => @vm3.id, + :bitness => 64, + :virtualization_type => "virtualization_type_3", + :guest_os => nil, + } + ], + :extra_disks => [ + { + :hardware_id => @vm3.hardware.id, + :device_name => "disk_name_3", + :device_type => "disk", + }, { + :hardware_id => @vm3.hardware.id, + :device_name => "disk_name_32", + :device_type => "disk", + } + ] ) end it "do a targeted refresh that will create/update vm, then create/update/delete Vm's hardware and disks using arel" do # Get the relations - initialize_all_dto_collections - initialize_dto_collection_data + initialize_all_inventory_collections + initialize_inventory_collection_data - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert all data were filled @@ -278,18 +296,18 @@ ### Second refresh ### # Do a targeted refresh for couple of VMs, hardwares and disks using arel comparison - initialize_dto_collections([:vms, :hardwares, :disks]) + initialize_inventory_collections([:vms, :hardwares, :disks]) vm_refs = ["vm_ems_ref_3", "vm_ems_ref_4"] - @data[:vms] = ::ManagerRefresh::DtoCollection.new( + @data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :arel => @ems.vms.where(:ems_ref => vm_refs)) - @data[:hardwares] = ::ManagerRefresh::DtoCollection.new( + @data[:hardwares] = ::ManagerRefresh::InventoryCollection.new( Hardware, :arel => @ems.hardwares.joins(:vm_or_template).where(:vms => {:ems_ref => vm_refs}), :manager_ref => [:vm_or_template]) - @data[:disks] = ::ManagerRefresh::DtoCollection.new( + @data[:disks] = ::ManagerRefresh::InventoryCollection.new( Disk, :arel => @ems.disks.joins(:hardware => :vm_or_template).where(:hardware => {:vms => {:ems_ref => vm_refs}}), :manager_ref => [:hardware, :device_name]) @@ -306,14 +324,14 @@ @disk_data_31 = disk_data(31).merge( :hardware => @data[:hardwares].lazy_find(vm_data(3)[:ems_ref])) - # Fill DtoCollections with data - add_data_to_dto_collection(@data[:vms], - @vm_data_3) - add_data_to_dto_collection(@data[:hardwares], - @hardware_data_3) - add_data_to_dto_collection(@data[:disks], @disk_data_3, @disk_data_31) + # Fill InventoryCollections with data + add_data_to_inventory_collection(@data[:vms], + @vm_data_3) + add_data_to_inventory_collection(@data[:hardwares], + @hardware_data_3) + add_data_to_inventory_collection(@data[:disks], @disk_data_3, @disk_data_31) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert all data were filled @@ -329,49 +347,55 @@ expect(@vm3.key_pairs.pluck(:id)).to match_array([@key_pair2.id]) assert_everything_is_collected( - :extra_vms => [{ - :ems_ref => "vm_ems_ref_3", - :name => "vm_name_3", - :location => "vm_location_3", - :uid_ems => "vm_uid_ems_3", - :vendor => "amazon", - :raw_power_state => "unknown", - }], - :extra_hardware => [{ - :vm_or_template_id => @vm3.id, - :bitness => 64, - :virtualization_type => "virtualization_type_3", - :guest_os => nil, - }], - :extra_disks => [{ - :hardware_id => @vm3.hardware.id, - :device_name => "disk_name_3", - :device_type => "disk", - }, { - :hardware_id => @vm3.hardware.id, - :device_name => "disk_name_31", - :device_type => "disk", - }] + :extra_vms => [ + { + :ems_ref => "vm_ems_ref_3", + :name => "vm_name_3", + :location => "vm_location_3", + :uid_ems => "vm_uid_ems_3", + :vendor => "amazon", + :raw_power_state => "unknown", + } + ], + :extra_hardware => [ + { + :vm_or_template_id => @vm3.id, + :bitness => 64, + :virtualization_type => "virtualization_type_3", + :guest_os => nil, + } + ], + :extra_disks => [ + { + :hardware_id => @vm3.hardware.id, + :device_name => "disk_name_3", + :device_type => "disk", + }, { + :hardware_id => @vm3.hardware.id, + :device_name => "disk_name_31", + :device_type => "disk", + } + ] ) ### Third refresh ### # Do a targeted refresh again with some new data and some data missing - initialize_dto_collections([:vms, :hardwares, :disks]) + initialize_inventory_collections([:vms, :hardwares, :disks]) vm_refs = ["vm_ems_ref_3", "vm_ems_ref_5"] - @data[:vms] = ::ManagerRefresh::DtoCollection.new( + @data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :arel => @ems.vms.where(:ems_ref => vm_refs)) - @data[:hardwares] = ::ManagerRefresh::DtoCollection.new( + @data[:hardwares] = ::ManagerRefresh::InventoryCollection.new( Hardware, :arel => @ems.hardwares.joins(:vm_or_template).where(:vms => {:ems_ref => vm_refs}), :manager_ref => [:vm_or_template]) - @data[:disks] = ::ManagerRefresh::DtoCollection.new( + @data[:disks] = ::ManagerRefresh::InventoryCollection.new( Disk, :arel => @ems.disks.joins(:hardware => :vm_or_template).where(:hardware => {:vms => {:ems_ref => vm_refs}}), :manager_ref => [:hardware, :device_name]) - @data[:image_hardwares] = ::ManagerRefresh::DtoCollection.new( + @data[:image_hardwares] = ::ManagerRefresh::InventoryCollection.new( Hardware, :arel => @ems.hardwares, :manager_ref => [:vm_or_template], @@ -388,16 +412,16 @@ @disk_data_5 = disk_data(5).merge( :hardware => @data[:hardwares].lazy_find(vm_data(5)[:ems_ref])) - # Fill DtoCollections with data - add_data_to_dto_collection(@data[:vms], - @vm_data_3, - @vm_data_5) - add_data_to_dto_collection(@data[:hardwares], - @hardware_data_5) - add_data_to_dto_collection(@data[:disks], - @disk_data_5) + # Fill InventoryCollections with data + add_data_to_inventory_collection(@data[:vms], + @vm_data_3, + @vm_data_5) + add_data_to_inventory_collection(@data[:hardwares], + @hardware_data_5) + add_data_to_inventory_collection(@data[:disks], + @disk_data_5) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert all data were filled @@ -416,33 +440,38 @@ expect(@vm5.key_pairs.pluck(:id)).to match_array([@key_pair2.id]) assert_everything_is_collected( - :extra_vms => [{ - :ems_ref => "vm_ems_ref_3", - :name => "vm_name_3", - :location => "vm_location_3", - :uid_ems => "vm_uid_ems_3", - :vendor => "amazon", - :raw_power_state => "unknown", - }, { - :ems_ref => "vm_ems_ref_5", - :name => "vm_name_5", - :location => "vm_location_5", - :uid_ems => "vm_uid_ems_5", - :vendor => "amazon", - :raw_power_state => "unknown", - } + :extra_vms => [ + { + :ems_ref => "vm_ems_ref_3", + :name => "vm_name_3", + :location => "vm_location_3", + :uid_ems => "vm_uid_ems_3", + :vendor => "amazon", + :raw_power_state => "unknown", + }, { + :ems_ref => "vm_ems_ref_5", + :name => "vm_name_5", + :location => "vm_location_5", + :uid_ems => "vm_uid_ems_5", + :vendor => "amazon", + :raw_power_state => "unknown", + } + ], + :extra_hardware => [ + { + :vm_or_template_id => @vm5.id, + :bitness => 64, + :virtualization_type => "virtualization_type_5", + :guest_os => "linux_generic_2", + } ], - :extra_hardware => [{ - :vm_or_template_id => @vm5.id, - :bitness => 64, - :virtualization_type => "virtualization_type_5", - :guest_os => "linux_generic_2", - }], - :extra_disks => [{ - :hardware_id => @vm5.hardware.id, - :device_name => "disk_name_5", - :device_type => "disk", - }] + :extra_disks => [ + { + :hardware_id => @vm5.hardware.id, + :device_name => "disk_name_5", + :device_type => "disk", + } + ] ) end end @@ -547,67 +576,73 @@ def assert_everything_is_collected(extra_vms: [], extra_hardware: [], extra_disk } ) - vms = [{ - :ems_ref => "vm_ems_ref_1", - :name => "vm_name_1", - :location => "vm_location_1", - :uid_ems => "vm_uid_ems_1", - :vendor => "amazon", - :raw_power_state => "unknown", - }, { - :ems_ref => "vm_ems_ref_2", - :name => "vm_name_2", - :location => "vm_location_2", - :uid_ems => "vm_uid_ems_2", - :vendor => "amazon", - :raw_power_state => "unknown", - }] + vms = [ + { + :ems_ref => "vm_ems_ref_1", + :name => "vm_name_1", + :location => "vm_location_1", + :uid_ems => "vm_uid_ems_1", + :vendor => "amazon", + :raw_power_state => "unknown", + }, { + :ems_ref => "vm_ems_ref_2", + :name => "vm_name_2", + :location => "vm_location_2", + :uid_ems => "vm_uid_ems_2", + :vendor => "amazon", + :raw_power_state => "unknown", + } + ] vms += extra_vms assert_all_records_match_hashes([Vm.all, @ems.vms], *vms) - hardware = [{ - :vm_or_template_id => @vm1.id, - :bitness => 64, - :virtualization_type => "virtualization_type_1", - :guest_os => "linux_generic_1", - }, { - :vm_or_template_id => @vm2.id, - :bitness => 64, - :virtualization_type => "virtualization_type_2", - :guest_os => "linux_generic_2", - }, { - :vm_or_template_id => @miq_template1.id, - :bitness => nil, - :virtualization_type => nil, - :guest_os => "linux_generic_1", - }, { - :vm_or_template_id => @miq_template2.id, - :bitness => nil, - :virtualization_type => nil, - :guest_os => "linux_generic_2", - }] + hardware = [ + { + :vm_or_template_id => @vm1.id, + :bitness => 64, + :virtualization_type => "virtualization_type_1", + :guest_os => "linux_generic_1", + }, { + :vm_or_template_id => @vm2.id, + :bitness => 64, + :virtualization_type => "virtualization_type_2", + :guest_os => "linux_generic_2", + }, { + :vm_or_template_id => @miq_template1.id, + :bitness => nil, + :virtualization_type => nil, + :guest_os => "linux_generic_1", + }, { + :vm_or_template_id => @miq_template2.id, + :bitness => nil, + :virtualization_type => nil, + :guest_os => "linux_generic_2", + } + ] hardware += extra_hardware assert_all_records_match_hashes([Hardware.all, @ems.hardwares], *hardware) - disks = [{ - :hardware_id => @vm1.hardware.id, - :device_name => "disk_name_1", - :device_type => "disk", - }, { - :hardware_id => @vm1.hardware.id, - :device_name => "disk_name_12", - :device_type => "disk", - }, { - :hardware_id => @vm1.hardware.id, - :device_name => "disk_name_13", - :device_type => "disk", - }, { - :hardware_id => @vm2.hardware.id, - :device_name => "disk_name_2", - :device_type => "disk", - }] + disks = [ + { + :hardware_id => @vm1.hardware.id, + :device_name => "disk_name_1", + :device_type => "disk", + }, { + :hardware_id => @vm1.hardware.id, + :device_name => "disk_name_12", + :device_type => "disk", + }, { + :hardware_id => @vm1.hardware.id, + :device_name => "disk_name_13", + :device_type => "disk", + }, { + :hardware_id => @vm2.hardware.id, + :device_name => "disk_name_2", + :device_type => "disk", + } + ] disks += extra_disks assert_all_records_match_hashes([Disk.all, @ems.disks], *disks) @@ -627,29 +662,29 @@ def all_collections %i(orchestration_stacks orchestration_stacks_resources vms miq_templates key_pairs hardwares disks) end - def initialize_all_dto_collections - # Initialize the DtoCollections + def initialize_all_inventory_collections + # Initialize the InventoryCollections @data = {} all_collections.each do |collection| - @data[collection] = ::ManagerRefresh::DtoCollection.new(*send("#{collection}_init_data")) + @data[collection] = ::ManagerRefresh::InventoryCollection.new(*send("#{collection}_init_data")) end end - def initialize_dto_collections(only_collections) - # Initialize the DtoCollections + def initialize_inventory_collections(only_collections) + # Initialize the InventoryCollections @data = {} only_collections.each do |collection| - @data[collection] = ::ManagerRefresh::DtoCollection.new(*send("#{collection}_init_data", - :extra_attributes => { - :complete => false})) + @data[collection] = ::ManagerRefresh::InventoryCollection.new(*send("#{collection}_init_data", + :extra_attributes => { + :complete => false})) end (all_collections - only_collections).each do |collection| - @data[collection] = ::ManagerRefresh::DtoCollection.new(*send("#{collection}_init_data", - :extra_attributes => { - :complete => false, - :strategy => :local_db_cache_all - })) + @data[collection] = ::ManagerRefresh::InventoryCollection.new(*send("#{collection}_init_data", + :extra_attributes => { + :complete => false, + :strategy => :local_db_cache_all + })) end end @@ -730,8 +765,8 @@ def custom_association_attributes [:parent, :genealogy_parent, :genealogy_parent_object] end - def initialize_dto_collection_data - # Initialize the DtoCollections data + def initialize_inventory_collection_data + # Initialize the InventoryCollections data @orchestration_stack_data_0_1 = orchestration_stack_data("0_1").merge( # TODO(lsmola) not possible until we have an enhanced transitive edges check # :parent => @data[:orchestration_stacks].lazy_find(orchestration_stack_data("0_0")[:ems_ref])) @@ -785,26 +820,26 @@ def initialize_dto_collection_data @disk_data_2 = disk_data(2).merge( :hardware => @data[:hardwares].lazy_find(vm_data(2)[:ems_ref])) - # Fill DtoCollections with data - add_data_to_dto_collection(@data[:orchestration_stacks], - @orchestration_stack_data_0_1, - @orchestration_stack_data_1_11, - @orchestration_stack_data_1_12) - add_data_to_dto_collection(@data[:orchestration_stacks_resources], - @orchestration_stack_resource_data_1_11, - @orchestration_stack_resource_data_1_12) - add_data_to_dto_collection(@data[:vms], - @vm_data_1, - @vm_data_2) - add_data_to_dto_collection(@data[:miq_templates], - @image_data_1, - @image_data_2) - add_data_to_dto_collection(@data[:hardwares], - @hardware_data_1, - @hardware_data_2, - @image_hardware_data_1, - @image_hardware_data_2) - add_data_to_dto_collection(@data[:key_pairs], @key_pair_data_1, @key_pair_data_2, @key_pair_data_21) - add_data_to_dto_collection(@data[:disks], @disk_data_1, @disk_data_12, @disk_data_13, @disk_data_2) + # Fill InventoryCollections with data + add_data_to_inventory_collection(@data[:orchestration_stacks], + @orchestration_stack_data_0_1, + @orchestration_stack_data_1_11, + @orchestration_stack_data_1_12) + add_data_to_inventory_collection(@data[:orchestration_stacks_resources], + @orchestration_stack_resource_data_1_11, + @orchestration_stack_resource_data_1_12) + add_data_to_inventory_collection(@data[:vms], + @vm_data_1, + @vm_data_2) + add_data_to_inventory_collection(@data[:miq_templates], + @image_data_1, + @image_data_2) + add_data_to_inventory_collection(@data[:hardwares], + @hardware_data_1, + @hardware_data_2, + @image_hardware_data_1, + @image_hardware_data_2) + add_data_to_inventory_collection(@data[:key_pairs], @key_pair_data_1, @key_pair_data_2, @key_pair_data_21) + add_data_to_inventory_collection(@data[:disks], @disk_data_1, @disk_data_12, @disk_data_13, @disk_data_2) end end diff --git a/spec/models/manager_refresh/save_inventory/single_dto_collection_spec.rb b/spec/models/manager_refresh/save_inventory/single_inventory_collection_spec.rb similarity index 70% rename from spec/models/manager_refresh/save_inventory/single_dto_collection_spec.rb rename to spec/models/manager_refresh/save_inventory/single_inventory_collection_spec.rb index 53f6632b9cc..489ae95832e 100644 --- a/spec/models/manager_refresh/save_inventory/single_dto_collection_spec.rb +++ b/spec/models/manager_refresh/save_inventory/single_inventory_collection_spec.rb @@ -7,36 +7,37 @@ ###################################################################################################################### # - # Testing SaveInventory for one DtoCollection with Vm data and various DtoCollection constructor attributes, to verify - # that saving of one isolated DtoCollection works correctly for Full refresh, Targeted refresh, Skeletal refresh or - # any other variations of refreshes that needs to save partial or complete collection with partial or complete data. + # Testing SaveInventory for one InventoryCollection with Vm data and various InventoryCollection constructor + # attributes, to verify that saving of one isolated InventoryCollection works correctly for Full refresh, Targeted + # refresh, Skeletal refresh or any other variations of refreshes that needs to save partial or complete collection + # with partial or complete data. # ###################################################################################################################### # Test all settings for ManagerRefresh::SaveInventory - [{:dto_saving_strategy => nil}, - {:dto_saving_strategy => :recursive}, - ].each do |dto_settings| - context "with settings #{dto_settings}" do + [{:inventory_object_saving_strategy => nil}, + {:inventory_object_saving_strategy => :recursive}, + ].each do |inventory_object_settings| + context "with settings #{inventory_object_settings}" do before :each do @zone = FactoryGirl.create(:zone) @ems = FactoryGirl.create(:ems_cloud, :zone => @zone) allow(@ems.class).to receive(:ems_type).and_return(:mock) - allow(Settings.ems_refresh).to receive(:mock).and_return(dto_settings) + allow(Settings.ems_refresh).to receive(:mock).and_return(inventory_object_settings) end context 'with no Vms in the DB' do it 'creates VMs' do - # Initialize the DtoCollections + # Initialize the InventoryCollections data = {} - data[:vms] = ::ManagerRefresh::DtoCollection.new( + data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) - # Fill the DtoCollections with data - add_data_to_dto_collection(data[:vms], vm_data(1), vm_data(2)) + # Fill the InventoryCollections with data + add_data_to_inventory_collection(data[:vms], vm_data(1), vm_data(2)) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, data) # Assert saved data @@ -47,17 +48,17 @@ end it 'creates and updates VMs' do - # Initialize the DtoCollections + # Initialize the InventoryCollections data = {} - data[:vms] = ::ManagerRefresh::DtoCollection.new( + data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) - # Fill the DtoCollections with data - add_data_to_dto_collection(data[:vms], - vm_data(1), - vm_data(2)) + # Fill the InventoryCollections with data + add_data_to_inventory_collection(data[:vms], + vm_data(1), + vm_data(2)) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, data) # Assert that saved data have the updated values, checking id to make sure the original records are updated @@ -71,17 +72,17 @@ vm2 = Vm.find_by(:ems_ref => "vm_ems_ref_2") # Second saving with the updated data - # Initialize the DtoCollections + # Initialize the InventoryCollections data = {} - data[:vms] = ::ManagerRefresh::DtoCollection.new( + data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) - # Fill the DtoCollections with data, that have a modified name - add_data_to_dto_collection(data[:vms], - vm_data(1).merge(:name => "vm_changed_name_1"), - vm_data(2).merge(:name => "vm_changed_name_2")) + # Fill the InventoryCollections with data, that have a modified name + add_data_to_inventory_collection(data[:vms], + vm_data(1).merge(:name => "vm_changed_name_1"), + vm_data(2).merge(:name => "vm_changed_name_2")) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, data) # Assert that saved data have the updated values, checking id to make sure the original records are updated @@ -99,11 +100,11 @@ @vm2 = FactoryGirl.create(:vm_cloud, vm_data(2).merge(:ext_management_system => @ems)) end - context 'with VM DtoCollection with default settings' do + context 'with VM InventoryCollection with default settings' do before :each do - # Initialize the DtoCollections + # Initialize the InventoryCollections @data = {} - @data[:vms] = ::ManagerRefresh::DtoCollection.new( + @data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) end @@ -116,12 +117,12 @@ end it 'updates existing VMs' do - # Fill the DtoCollections with data, that have a modified name - add_data_to_dto_collection(@data[:vms], - vm_data(1).merge(:name => "vm_changed_name_1"), - vm_data(2).merge(:name => "vm_changed_name_2")) + # Fill the InventoryCollections with data, that have a modified name + add_data_to_inventory_collection(@data[:vms], + vm_data(1).merge(:name => "vm_changed_name_1"), + vm_data(2).merge(:name => "vm_changed_name_2")) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert that saved data have the updated values, checking id to make sure the original records are updated @@ -132,13 +133,13 @@ end it 'creates new VMs' do - # Fill the DtoCollections with data, that have a new VM - add_data_to_dto_collection(@data[:vms], - vm_data(1).merge(:name => "vm_changed_name_1"), - vm_data(2).merge(:name => "vm_changed_name_2"), - vm_data(3).merge(:name => "vm_changed_name_3")) + # Fill the InventoryCollections with data, that have a new VM + add_data_to_inventory_collection(@data[:vms], + vm_data(1).merge(:name => "vm_changed_name_1"), + vm_data(2).merge(:name => "vm_changed_name_2"), + vm_data(3).merge(:name => "vm_changed_name_3")) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert that saved data contain the new VM @@ -150,11 +151,11 @@ end it 'deletes missing VMs' do - # Fill the DtoCollections with data, that are missing one VM - add_data_to_dto_collection(@data[:vms], - vm_data(1).merge(:name => "vm_changed_name_1")) + # Fill the InventoryCollections with data, that are missing one VM + add_data_to_inventory_collection(@data[:vms], + vm_data(1).merge(:name => "vm_changed_name_1")) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert that saved data do miss the deleted VM @@ -164,12 +165,12 @@ end it 'deletes missing and creates new VMs' do - # Fill the DtoCollections with data, that have one new VM and are missing one VM - add_data_to_dto_collection(@data[:vms], - vm_data(1).merge(:name => "vm_changed_name_1"), - vm_data(3).merge(:name => "vm_changed_name_3")) + # Fill the InventoryCollections with data, that have one new VM and are missing one VM + add_data_to_inventory_collection(@data[:vms], + vm_data(1).merge(:name => "vm_changed_name_1"), + vm_data(3).merge(:name => "vm_changed_name_3")) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert that saved data have the new VM and miss the deleted VM @@ -180,11 +181,11 @@ end end - context 'with VM DtoCollection with :delete_method => :disconnect_inv' do + context 'with VM InventoryCollection with :delete_method => :disconnect_inv' do before :each do - # Initialize the DtoCollections + # Initialize the InventoryCollections @data = {} - @data[:vms] = ::ManagerRefresh::DtoCollection.new( + @data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms, @@ -192,12 +193,12 @@ end it 'disconnects a missing VM instead of deleting it' do - # Fill the DtoCollections with data, that have a modified name, new VM and a missing VM - add_data_to_dto_collection(@data[:vms], - vm_data(1).merge(:name => "vm_changed_name_1"), - vm_data(3).merge(:name => "vm_changed_name_3")) + # Fill the InventoryCollections with data, that have a modified name, new VM and a missing VM + add_data_to_inventory_collection(@data[:vms], + vm_data(1).merge(:name => "vm_changed_name_1"), + vm_data(3).merge(:name => "vm_changed_name_3")) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert that DB still contains the disconnected VMs @@ -215,7 +216,7 @@ end end - context 'with VM DtoCollection blacklist or whitelist used' do + context 'with VM InventoryCollection blacklist or whitelist used' do let :changed_data do [ vm_data(1).merge(:name => "vm_changed_name_1", @@ -236,15 +237,15 @@ # TODO(lsmola) fixed attributes should contain also other attributes, like inclusion validation of :vendor # column it 'recognizes correct presence validators' do - dto_collection = ::ManagerRefresh::DtoCollection.new( + inventory_collection = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms, :attributes_blacklist => [:ems_ref, :uid_ems, :name, :location]) # Check that :name and :location do have validate presence, those attributes will not be blacklisted - presence_validators = dto_collection.model_class.validators - .detect { |x| x.kind_of? ActiveRecord::Validations::PresenceValidator }.attributes + presence_validators = inventory_collection.model_class.validators + .detect { |x| x.kind_of? ActiveRecord::Validations::PresenceValidator }.attributes expect(presence_validators).to include(:name) expect(presence_validators).to include(:location) @@ -252,63 +253,63 @@ it 'does not blacklist fixed attributes with default manager_ref' do # Fixed attributes are attributes used for unique ID of the DTO or attributes with presence validation - dto_collection = ::ManagerRefresh::DtoCollection.new( + inventory_collection = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms, :attributes_blacklist => [:ems_ref, :uid_ems, :name, :location, :vendor, :raw_power_state]) - expect(dto_collection.attributes_blacklist).to match_array([:vendor, :uid_ems, :raw_power_state]) + expect(inventory_collection.attributes_blacklist).to match_array([:vendor, :uid_ems, :raw_power_state]) end it 'has fixed and internal attributes amongst whitelisted_attributes with default manager_ref' do # Fixed attributes are attributes used for unique ID of the DTO or attributes with presence validation - dto_collection = ::ManagerRefresh::DtoCollection.new( + inventory_collection = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms, :attributes_whitelist => [:raw_power_state]) - expect(dto_collection.attributes_whitelist).to match_array([:__feedback_edge_set_parent, :ems_ref, - :name, :location, :raw_power_state]) + expect(inventory_collection.attributes_whitelist).to match_array([:__feedback_edge_set_parent, :ems_ref, + :name, :location, :raw_power_state]) end it 'does not blacklist fixed attributes when changing manager_ref' do - dto_collection = ::ManagerRefresh::DtoCollection.new( + inventory_collection = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :manager_ref => [:uid_ems], :parent => @ems, :association => :vms, :attributes_blacklist => [:ems_ref, :uid_ems, :name, :location, :vendor, :raw_power_state]) - expect(dto_collection.attributes_blacklist).to match_array([:vendor, :ems_ref, :raw_power_state]) + expect(inventory_collection.attributes_blacklist).to match_array([:vendor, :ems_ref, :raw_power_state]) end it 'has fixed and internal attributes amongst whitelisted_attributes when changing manager_ref' do # Fixed attributes are attributes used for unique ID of the DTO or attributes with presence validation - dto_collection = ::ManagerRefresh::DtoCollection.new( + inventory_collection = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :manager_ref => [:uid_ems], :parent => @ems, :association => :vms, :attributes_whitelist => [:raw_power_state]) - expect(dto_collection.attributes_whitelist).to match_array([:__feedback_edge_set_parent, :uid_ems, :name, - :location, :raw_power_state]) + expect(inventory_collection.attributes_whitelist).to match_array([:__feedback_edge_set_parent, :uid_ems, + :name, :location, :raw_power_state]) end it 'saves all attributes with blacklist and whitelist disabled' do - # Initialize the DtoCollections + # Initialize the InventoryCollections @data = {} - @data[:vms] = ::ManagerRefresh::DtoCollection.new( + @data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) - # Fill the DtoCollections with data, that have a modified name, new VM and a missing VM - add_data_to_dto_collection(@data[:vms], *changed_data) + # Fill the InventoryCollections with data, that have a modified name, new VM and a missing VM + add_data_to_inventory_collection(@data[:vms], *changed_data) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert that saved data don;t have the blacklisted attributes updated nor filled @@ -335,18 +336,18 @@ end it 'does not save blacklisted attributes (excluding fixed attributes)' do - # Initialize the DtoCollections + # Initialize the InventoryCollections @data = {} - @data[:vms] = ::ManagerRefresh::DtoCollection.new( + @data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms, :attributes_blacklist => [:name, :location, :raw_power_state]) - # Fill the DtoCollections with data, that have a modified name, new VM and a missing VM - add_data_to_dto_collection(@data[:vms], *changed_data) + # Fill the InventoryCollections with data, that have a modified name, new VM and a missing VM + add_data_to_inventory_collection(@data[:vms], *changed_data) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert that saved data don;t have the blacklisted attributes updated nor filled @@ -373,19 +374,19 @@ end it 'saves only whitelisted attributes (including fixed attributes)' do - # Initialize the DtoCollections + # Initialize the InventoryCollections @data = {} - @data[:vms] = ::ManagerRefresh::DtoCollection.new( + @data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms, # TODO(lsmola) vendor is not getting caught by fixed attributes :attributes_whitelist => [:uid_ems, :vendor]) - # Fill the DtoCollections with data, that have a modified name, new VM and a missing VM - add_data_to_dto_collection(@data[:vms], *changed_data) + # Fill the InventoryCollections with data, that have a modified name, new VM and a missing VM + add_data_to_inventory_collection(@data[:vms], *changed_data) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert that saved data don;t have the blacklisted attributes updated nor filled @@ -412,9 +413,9 @@ end it 'saves correct set of attributes when both whilelist and blacklist are used' do - # Initialize the DtoCollections + # Initialize the InventoryCollections @data = {} - @data[:vms] = ::ManagerRefresh::DtoCollection.new( + @data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms, @@ -422,10 +423,10 @@ :attributes_whitelist => [:uid_ems, :raw_power_state, :vendor], :attributes_blacklist => [:name, :ems_ref, :raw_power_state]) - # Fill the DtoCollections with data, that have a modified name, new VM and a missing VM - add_data_to_dto_collection(@data[:vms], *changed_data) + # Fill the InventoryCollections with data, that have a modified name, new VM and a missing VM + add_data_to_inventory_collection(@data[:vms], *changed_data) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert that saved data don;t have the blacklisted attributes updated nor filled @@ -452,11 +453,11 @@ end end - context 'with VM DtoCollection with :complete => false' do + context 'with VM InventoryCollection with :complete => false' do before :each do - # Initialize the DtoCollections + # Initialize the InventoryCollections @data = {} - @data[:vms] = ::ManagerRefresh::DtoCollection.new( + @data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms, @@ -464,12 +465,12 @@ end it 'updates only existing VMs and creates new VMs, does not delete or update missing VMs' do - # Fill the DtoCollections with data, that have a new VM - add_data_to_dto_collection(@data[:vms], - vm_data(1).merge(:name => "vm_changed_name_1"), - vm_data(3).merge(:name => "vm_changed_name_3")) + # Fill the InventoryCollections with data, that have a new VM + add_data_to_inventory_collection(@data[:vms], + vm_data(1).merge(:name => "vm_changed_name_1"), + vm_data(3).merge(:name => "vm_changed_name_3")) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, @data) # Assert that saved data contain the new VM, but no VM was deleted @@ -481,23 +482,23 @@ end end - context 'with VM DtoCollection with changed parent and association' do + context 'with VM InventoryCollection with changed parent and association' do it 'deletes missing and creates new VMs with AvailabilityZone parent, ' do availability_zone = FactoryGirl.create(:availability_zone, :ext_management_system => @ems) @vm1.update_attributes(:availability_zone => availability_zone) @vm2.update_attributes(:availability_zone => availability_zone) - # Initialize the DtoCollections + # Initialize the InventoryCollections data = {} - data[:vms] = ::ManagerRefresh::DtoCollection.new( + data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => availability_zone, :association => :vms) - # Fill the DtoCollections with data, that have one new VM and are missing one VM - add_data_to_dto_collection(data[:vms], - vm_data(1).merge(:name => "vm_changed_name_1", :ext_management_system => @ems), - vm_data(3).merge(:name => "vm_changed_name_3", :ext_management_system => @ems)) + # Fill the InventoryCollections with data, that have one new VM and are missing one VM + add_data_to_inventory_collection(data[:vms], + vm_data(1).merge(:name => "vm_changed_name_1", :ext_management_system => @ems), + vm_data(3).merge(:name => "vm_changed_name_3", :ext_management_system => @ems)) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, data) # Assert that saved data have the new VM and miss the deleted VM @@ -512,17 +513,17 @@ @vm1.update_attributes(:cloud_tenant => cloud_tenant) @vm2.update_attributes(:cloud_tenant => cloud_tenant) - # Initialize the DtoCollections + # Initialize the InventoryCollections data = {} - data[:vms] = ::ManagerRefresh::DtoCollection.new( + data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => cloud_tenant, :association => :vms) - # Fill the DtoCollections with data, that have one new VM and are missing one VM - add_data_to_dto_collection(data[:vms], - vm_data(1).merge(:name => "vm_changed_name_1", :ext_management_system => @ems), - vm_data(3).merge(:name => "vm_changed_name_3", :ext_management_system => @ems)) + # Fill the InventoryCollections with data, that have one new VM and are missing one VM + add_data_to_inventory_collection(data[:vms], + vm_data(1).merge(:name => "vm_changed_name_1", :ext_management_system => @ems), + vm_data(3).merge(:name => "vm_changed_name_3", :ext_management_system => @ems)) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, data) # Assert that saved data have the new VM and miss the deleted VM @@ -537,17 +538,17 @@ @vm1.update_attributes(:cloud_tenant => cloud_tenant) @vm2.update_attributes(:cloud_tenant => cloud_tenant) - # Initialize the DtoCollections + # Initialize the InventoryCollections data = {} - data[:vms] = ::ManagerRefresh::DtoCollection.new( + data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => cloud_tenant, :association => :vms) - # Fill the DtoCollections with data, that have one new VM and are missing one VM - add_data_to_dto_collection(data[:vms], - vm_data(1).merge(:name => "vm_changed_name_1"), - vm_data(3).merge(:name => "vm_changed_name_3")) + # Fill the InventoryCollections with data, that have one new VM and are missing one VM + add_data_to_inventory_collection(data[:vms], + vm_data(1).merge(:name => "vm_changed_name_1"), + vm_data(3).merge(:name => "vm_changed_name_3")) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, data) # Assert that saved data have the new VM and miss the deleted VM @@ -567,20 +568,20 @@ @vm1.update_attributes(:cloud_tenant => cloud_tenant) @vm2.update_attributes(:cloud_tenant => cloud_tenant) - # Initialize the DtoCollections + # Initialize the InventoryCollections data = {} - data[:vms] = ::ManagerRefresh::DtoCollection.new( + data[:vms] = ::ManagerRefresh::InventoryCollection.new( ManageIQ::Providers::CloudManager::Vm, :parent => cloud_tenant, :association => :vms, :complete => false) - # Fill the DtoCollections with data, that have one new VM and are missing one VM - add_data_to_dto_collection(data[:vms], - vm_data(1).merge(:name => "vm_changed_name_1"), - vm_data(3).merge(:name => "vm_changed_name_3")) + # Fill the InventoryCollections with data, that have one new VM and are missing one VM + add_data_to_inventory_collection(data[:vms], + vm_data(1).merge(:name => "vm_changed_name_1"), + vm_data(3).merge(:name => "vm_changed_name_3")) - # Invoke the DtoCollections saving + # Invoke the InventoryCollections saving ManagerRefresh::SaveInventory.save_inventory(@ems, data) # Assert that saved data have the new VM and miss the deleted VM diff --git a/spec/models/manager_refresh/save_inventory/spec_helper.rb b/spec/models/manager_refresh/save_inventory/spec_helper.rb index b962fb8eb53..8a6aaf5686c 100644 --- a/spec/models/manager_refresh/save_inventory/spec_helper.rb +++ b/spec/models/manager_refresh/save_inventory/spec_helper.rb @@ -10,8 +10,8 @@ def sliced_records_of(model_class, attributes) model_class.to_a.map { |x| x.slice(*attributes).symbolize_keys } end - def add_data_to_dto_collection(dto_collection, *args) - # Creates Dto object from each arg and adds it into the DtoCollection - args.each { |data| dto_collection << dto_collection.new_dto(data) } + def add_data_to_inventory_collection(inventory_collection, *args) + # Creates InventoryObject object from each arg and adds it into the InventoryCollection + args.each { |data| inventory_collection << inventory_collection.new_inventory_object(data) } end end