From d9fcb073ca76a69098827d13c1b1657e4315503c Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Thu, 2 Feb 2017 12:43:05 +0100 Subject: [PATCH 1/4] Move model_class to kwargs in InventoryCollection init Move model_class to kwargs in InventoryCollection init --- app/models/manager_refresh/inventory_collection.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/manager_refresh/inventory_collection.rb b/app/models/manager_refresh/inventory_collection.rb index e11d71eb3a6..1d6e9e050cf 100644 --- a/app/models/manager_refresh/inventory_collection.rb +++ b/app/models/manager_refresh/inventory_collection.rb @@ -9,7 +9,7 @@ class InventoryCollection delegate :each, :size, :to => :to_a - def initialize(model_class, manager_ref: nil, association: nil, parent: nil, strategy: nil, saved: nil, + def initialize(model_class: nil, manager_ref: nil, association: nil, parent: nil, strategy: nil, saved: nil, custom_save_block: nil, delete_method: nil, data_index: nil, data: nil, dependency_attributes: nil, attributes_blacklist: nil, attributes_whitelist: nil, complete: nil, update_only: nil, check_changed: nil, custom_manager_uuid: nil, custom_db_finder: nil, arel: nil, builder_params: {}) @@ -257,7 +257,7 @@ def whitelist_attributes!(attributes) def clone # 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, + self.class.new(:model_class => model_class, :manager_ref => manager_ref, :association => association, :parent => parent, From b6a1279e5b73129a43deb471040b983dacdffc35 Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Thu, 2 Feb 2017 12:43:47 +0100 Subject: [PATCH 2/4] Changed specs after moving model_class to kwargs Changed specs after moving model_class to kwargs --- ...lic_graph_of_inventory_collections_spec.rb | 18 ++--- .../graph_of_inventory_collections_spec.rb | 34 ++++---- ...ntory_collections_targeted_refresh_spec.rb | 77 ++++++++++--------- .../single_inventory_collection_spec.rb | 38 ++++----- 4 files changed, 86 insertions(+), 81 deletions(-) diff --git a/spec/models/manager_refresh/save_inventory/acyclic_graph_of_inventory_collections_spec.rb b/spec/models/manager_refresh/save_inventory/acyclic_graph_of_inventory_collections_spec.rb index 44dabfa3cd4..3c3e8ce2924 100644 --- a/spec/models/manager_refresh/save_inventory/acyclic_graph_of_inventory_collections_spec.rb +++ b/spec/models/manager_refresh/save_inventory/acyclic_graph_of_inventory_collections_spec.rb @@ -354,11 +354,11 @@ # Initialize the InventoryCollections @data = {} @data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) @data[:hardwares] = ::ManagerRefresh::InventoryCollection.new( - Hardware, + :model_class => Hardware, :parent => @ems, :association => :hardwares, :manager_ref => [:vm_or_template]) @@ -472,35 +472,35 @@ def initialize_data_and_inventory_collections # Initialize the InventoryCollections @data = {} @data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) @data[:key_pairs] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::AuthKeyPair, + :model_class => ManageIQ::Providers::CloudManager::AuthKeyPair, :parent => @ems, :association => :key_pairs, :manager_ref => [:name]) @data[:miq_templates] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Template, + :model_class => ManageIQ::Providers::CloudManager::Template, :parent => @ems, :association => :miq_templates) @data[:hardwares] = ::ManagerRefresh::InventoryCollection.new( - Hardware, + :model_class => Hardware, :parent => @ems, :association => :hardwares, :manager_ref => [:vm_or_template]) @data[:disks] = ::ManagerRefresh::InventoryCollection.new( - Disk, + :model_class => Disk, :parent => @ems, :association => :disks, :manager_ref => [:hardware, :device_name]) @data[:networks] = ::ManagerRefresh::InventoryCollection.new( - Network, + :model_class => Network, :parent => @ems, :association => :networks, :manager_ref => [:hardware, :description]) @data[:flavors] = ::ManagerRefresh::InventoryCollection.new( - Flavor, + :model_class => Flavor, :parent => @ems, :association => :flavors, :manager_ref => [:name]) diff --git a/spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_spec.rb b/spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_spec.rb index 731e9d81c46..4bf74a38ce2 100644 --- a/spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_spec.rb +++ b/spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_spec.rb @@ -433,15 +433,15 @@ it 'test network_port -> stack -> resource -> stack' do @data = {} @data[:orchestration_stacks] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::OrchestrationStack, + :model_class => ManageIQ::Providers::CloudManager::OrchestrationStack, :parent => @ems, :association => :orchestration_stacks) @data[:orchestration_stacks_resources] = ::ManagerRefresh::InventoryCollection.new( - OrchestrationStackResource, + :model_class => OrchestrationStackResource, :parent => @ems, :association => :orchestration_stacks_resources) @data[:network_ports] = ::ManagerRefresh::InventoryCollection.new( - NetworkPort, + :model_class => NetworkPort, :parent => @ems.network_manager, :association => :network_ports) @@ -503,15 +503,15 @@ it 'test network_port -> stack -> resource -> stack reverted' do @data = {} @data[:network_ports] = ::ManagerRefresh::InventoryCollection.new( - NetworkPort, + :model_class => NetworkPort, :parent => @ems.network_manager, :association => :network_ports) @data[:orchestration_stacks_resources] = ::ManagerRefresh::InventoryCollection.new( - OrchestrationStackResource, + :model_class => OrchestrationStackResource, :parent => @ems, :association => :orchestration_stacks_resources) @data[:orchestration_stacks] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::OrchestrationStack, + :model_class => ManageIQ::Providers::CloudManager::OrchestrationStack, :parent => @ems, :association => :orchestration_stacks) @@ -575,7 +575,7 @@ # data dependencies and saving it according to the tree. @data = {} @data[:network_ports] = ::ManagerRefresh::InventoryCollection.new( - NetworkPort, + :model_class => NetworkPort, :parent => @ems.network_manager, :association => :network_ports) @@ -616,15 +616,15 @@ # edge correctly and this cycle is solvable. @data = {} @data[:orchestration_stacks] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::OrchestrationStack, + :model_class => ManageIQ::Providers::CloudManager::OrchestrationStack, :parent => @ems, :association => :orchestration_stacks) @data[:orchestration_stacks_resources] = ::ManagerRefresh::InventoryCollection.new( - OrchestrationStackResource, + :model_class => OrchestrationStackResource, :parent => @ems, :association => :orchestration_stacks_resources) @data[:network_ports] = ::ManagerRefresh::InventoryCollection.new( - NetworkPort, + :model_class => NetworkPort, :parent => @ems.network_manager, :association => :network_ports) @@ -686,15 +686,15 @@ it 'test network_port -> stack -> resource -> stack and network_port -> resource -> stack -> resource -> stack ' do @data = {} @data[:orchestration_stacks] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::OrchestrationStack, + :model_class => ManageIQ::Providers::CloudManager::OrchestrationStack, :parent => @ems, :association => :orchestration_stacks) @data[:orchestration_stacks_resources] = ::ManagerRefresh::InventoryCollection.new( - OrchestrationStackResource, + :model_class => OrchestrationStackResource, :parent => @ems, :association => :orchestration_stacks_resources) @data[:network_ports] = ::ManagerRefresh::InventoryCollection.new( - NetworkPort, + :model_class => NetworkPort, :parent => @ems.network_manager, :association => :network_ports) @@ -982,11 +982,11 @@ def initialize_inventory_collections # Initialize the InventoryCollections @data = {} @data[:orchestration_stacks] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::OrchestrationStack, + :model_class => ManageIQ::Providers::CloudManager::OrchestrationStack, :parent => @ems, :association => :orchestration_stacks) @data[:orchestration_stacks_resources] = ::ManagerRefresh::InventoryCollection.new( - OrchestrationStackResource, + :model_class => OrchestrationStackResource, :parent => @ems, :association => :orchestration_stacks_resources) end @@ -996,11 +996,11 @@ def initialize_inventory_collections_reversed # the order of the InventoryCollections @data = {} @data[:orchestration_stacks_resources] = ::ManagerRefresh::InventoryCollection.new( - OrchestrationStackResource, + :model_class => OrchestrationStackResource, :parent => @ems, :association => :orchestration_stacks_resources) @data[:orchestration_stacks] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::OrchestrationStack, + :model_class => ManageIQ::Providers::CloudManager::OrchestrationStack, :parent => @ems, :association => :orchestration_stacks) end diff --git a/spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_targeted_refresh_spec.rb b/spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_targeted_refresh_spec.rb index 5de5eae3fd6..415fe94d4d7 100644 --- a/spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_targeted_refresh_spec.rb +++ b/spec/models/manager_refresh/save_inventory/graph_of_inventory_collections_targeted_refresh_spec.rb @@ -155,7 +155,7 @@ initialize_inventory_collections([:disks]) @data[:disks] = ::ManagerRefresh::InventoryCollection.new( - Disk, + :model_class => Disk, :association => :disks, :parent => @vm3, :manager_ref => [:hardware, :device_name] @@ -222,7 +222,7 @@ initialize_inventory_collections([:disks]) @data[:disks] = ::ManagerRefresh::InventoryCollection.new( - Disk, + :model_class => Disk, :association => :disks, :parent => @vm3, :manager_ref => [:hardware, :device_name]) @@ -301,14 +301,14 @@ vm_refs = ["vm_ems_ref_3", "vm_ems_ref_4"] @data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, - :arel => @ems.vms.where(:ems_ref => vm_refs)) + :model_class => ManageIQ::Providers::CloudManager::Vm, + :arel => @ems.vms.where(:ems_ref => vm_refs)) @data[:hardwares] = ::ManagerRefresh::InventoryCollection.new( - Hardware, + :model_class => Hardware, :arel => @ems.hardwares.joins(:vm_or_template).where(:vms => {:ems_ref => vm_refs}), :manager_ref => [:vm_or_template]) @data[:disks] = ::ManagerRefresh::InventoryCollection.new( - Disk, + :model_class => Disk, :arel => @ems.disks.joins(:hardware => :vm_or_template).where('hardware' => {'vms' => {'ems_ref' => vm_refs}}), :manager_ref => [:hardware, :device_name]) @@ -385,18 +385,18 @@ vm_refs = ["vm_ems_ref_3", "vm_ems_ref_5"] @data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, - :arel => @ems.vms.where(:ems_ref => vm_refs)) + :model_class => ManageIQ::Providers::CloudManager::Vm, + :arel => @ems.vms.where(:ems_ref => vm_refs)) @data[:hardwares] = ::ManagerRefresh::InventoryCollection.new( - Hardware, + :model_class => Hardware, :arel => @ems.hardwares.joins(:vm_or_template).where(:vms => {:ems_ref => vm_refs}), :manager_ref => [:vm_or_template]) @data[:disks] = ::ManagerRefresh::InventoryCollection.new( - Disk, + :model_class => 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::InventoryCollection.new( - Hardware, + :model_class => Hardware, :arel => @ems.hardwares, :manager_ref => [:vm_or_template], :strategy => :local_db_cache_all, @@ -670,7 +670,7 @@ def initialize_all_inventory_collections # Initialize the InventoryCollections @data = {} all_collections.each do |collection| - @data[collection] = ::ManagerRefresh::InventoryCollection.new(*send("#{collection}_init_data")) + @data[collection] = ::ManagerRefresh::InventoryCollection.new(send("#{collection}_init_data")) end end @@ -678,48 +678,53 @@ def initialize_inventory_collections(only_collections) # Initialize the InventoryCollections @data = {} only_collections.each do |collection| - @data[collection] = ::ManagerRefresh::InventoryCollection.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::InventoryCollection.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 def orchestration_stacks_init_data(extra_attributes: {}) - init_data(ManageIQ::Providers::CloudManager::OrchestrationStack, - :orchestration_stacks, + extra_attributes[:model_class] = ManageIQ::Providers::CloudManager::OrchestrationStack + + init_data(:orchestration_stacks, extra_attributes) end def orchestration_stacks_resources_init_data(extra_attributes: {}) - init_data(OrchestrationStackResource, - :orchestration_stacks_resources, + extra_attributes[:model_class] = OrchestrationStackResource + + init_data(:orchestration_stacks_resources, extra_attributes) end def vms_init_data(extra_attributes: {}) - init_data(ManageIQ::Providers::CloudManager::Vm, - :vms, + extra_attributes[:model_class] = ManageIQ::Providers::CloudManager::Vm + + init_data(:vms, extra_attributes) end def miq_templates_init_data(extra_attributes: {}) - init_data(ManageIQ::Providers::CloudManager::Template, - :miq_templates, + extra_attributes[:model_class] = ManageIQ::Providers::CloudManager::Template + + init_data(:miq_templates, extra_attributes) end def key_pairs_init_data(extra_attributes: {}) extra_attributes[:manager_ref] = [:name] - init_data(ManageIQ::Providers::CloudManager::AuthKeyPair, - :key_pairs, + extra_attributes[:model_class] = ManageIQ::Providers::CloudManager::AuthKeyPair + + init_data(:key_pairs, extra_attributes) end @@ -731,8 +736,8 @@ def hardwares_init_data(extra_attributes: {}) end extra_attributes[:manager_ref] = [:vm_or_template] - init_data(Hardware, - :hardwares, + extra_attributes[:model_class] = Hardware + init_data(:hardwares, extra_attributes) end @@ -744,19 +749,19 @@ def disks_init_data(extra_attributes: {}) end extra_attributes[:manager_ref] = [:hardware, :device_name] - init_data(Disk, - :disks, + extra_attributes[:model_class] = Disk + init_data(:disks, extra_attributes) end - def init_data(model_class, association, extra_attributes) + def init_data(association, extra_attributes) init_data = { :parent => @ems, :association => association } init_data.merge!(extra_attributes) - return model_class, init_data + init_data end def association_attributes(model_class) diff --git a/spec/models/manager_refresh/save_inventory/single_inventory_collection_spec.rb b/spec/models/manager_refresh/save_inventory/single_inventory_collection_spec.rb index 994b49cdb41..c72f109337e 100644 --- a/spec/models/manager_refresh/save_inventory/single_inventory_collection_spec.rb +++ b/spec/models/manager_refresh/save_inventory/single_inventory_collection_spec.rb @@ -32,7 +32,7 @@ # Initialize the InventoryCollections data = {} data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) # Fill the InventoryCollections with data add_data_to_inventory_collection(data[:vms], vm_data(1), vm_data(2)) @@ -51,7 +51,7 @@ # Initialize the InventoryCollections data = {} data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) # Fill the InventoryCollections with data add_data_to_inventory_collection(data[:vms], @@ -75,7 +75,7 @@ # Initialize the InventoryCollections data = {} data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) # Fill the InventoryCollections with data, that have a modified name add_data_to_inventory_collection(data[:vms], @@ -105,7 +105,7 @@ # Initialize the InventoryCollections @data = {} @data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) end it 'has correct records in the DB' do @@ -186,7 +186,7 @@ # Initialize the InventoryCollections @data = {} @data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms, :delete_method => :disconnect_inv) @@ -238,7 +238,7 @@ # column it 'recognizes correct presence validators' do inventory_collection = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms, :attributes_blacklist => [:ems_ref, :uid_ems, :name, :location]) @@ -254,7 +254,7 @@ 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 inventory_collection = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms, :attributes_blacklist => [:ems_ref, :uid_ems, :name, :location, :vendor, :raw_power_state]) @@ -265,7 +265,7 @@ 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 inventory_collection = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms, :attributes_whitelist => [:raw_power_state, :ext_management_system]) @@ -277,7 +277,7 @@ it 'does not blacklist fixed attributes when changing manager_ref' do inventory_collection = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, + :model_class => ManageIQ::Providers::CloudManager::Vm, :manager_ref => [:uid_ems], :parent => @ems, :association => :vms, @@ -289,7 +289,7 @@ 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 inventory_collection = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, + :model_class => ManageIQ::Providers::CloudManager::Vm, :manager_ref => [:uid_ems], :parent => @ems, :association => :vms, @@ -304,7 +304,7 @@ # Initialize the InventoryCollections @data = {} @data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms) @@ -341,7 +341,7 @@ # Initialize the InventoryCollections @data = {} @data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms, :attributes_blacklist => [:name, :location, :raw_power_state]) @@ -379,7 +379,7 @@ # Initialize the InventoryCollections @data = {} @data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms, # TODO(lsmola) vendor is not getting caught by fixed attributes @@ -418,7 +418,7 @@ # Initialize the InventoryCollections @data = {} @data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms, # TODO(lsmola) vendor is not getting caught by fixed attributes @@ -460,7 +460,7 @@ # Initialize the InventoryCollections @data = {} @data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => @ems, :association => :vms, :complete => false) @@ -493,7 +493,7 @@ # Initialize the InventoryCollections data = {} data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, :parent => availability_zone, :association => :vms) + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => availability_zone, :association => :vms) # Fill the InventoryCollections with data, that have one new VM and are missing one VM add_data_to_inventory_collection(data[:vms], @@ -522,7 +522,7 @@ # Initialize the InventoryCollections data = {} data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, :parent => cloud_tenant, :association => :vms) + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => cloud_tenant, :association => :vms) # Fill the InventoryCollections with data, that have one new VM and are missing one VM add_data_to_inventory_collection(data[:vms], @@ -551,7 +551,7 @@ # Initialize the InventoryCollections data = {} data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, :parent => cloud_tenant, :association => :vms) + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => cloud_tenant, :association => :vms) # Fill the InventoryCollections with data, that have one new VM and are missing one VM add_data_to_inventory_collection(data[:vms], @@ -584,7 +584,7 @@ # Initialize the InventoryCollections data = {} data[:vms] = ::ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::CloudManager::Vm, + :model_class => ManageIQ::Providers::CloudManager::Vm, :parent => cloud_tenant, :association => :vms, :complete => false) From d4ced2bc791f89e8ccae848a0535b02ac7207b62 Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Thu, 2 Feb 2017 14:37:49 +0100 Subject: [PATCH 3/4] Make model_class optional Make model_class optional --- .../manager_refresh/inventory_collection.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/models/manager_refresh/inventory_collection.rb b/app/models/manager_refresh/inventory_collection.rb index 1d6e9e050cf..11ea0fe029c 100644 --- a/app/models/manager_refresh/inventory_collection.rb +++ b/app/models/manager_refresh/inventory_collection.rb @@ -211,7 +211,9 @@ def filtered_dependency_attributes end def fixed_attributes - presence_validators = model_class.validators.detect { |x| x.kind_of? ActiveRecord::Validations::PresenceValidator } + if model_class + presence_validators = model_class.validators.detect { |x| x.kind_of? ActiveRecord::Validations::PresenceValidator } + end # Attributes that has to be always on the entity, so attributes making unique index of the record + attributes # that have presence validation fixed_attributes = manager_ref @@ -272,30 +274,40 @@ def clone end def association_to_foreign_key_mapping + return {} unless model_class + @association_to_foreign_key_mapping ||= model_class.reflect_on_all_associations.each_with_object({}) do |x, obj| obj[x.name] = x.foreign_key end end def foreign_key_to_association_mapping + return {} unless model_class + @foreign_key_to_association_mapping ||= model_class.reflect_on_all_associations.each_with_object({}) do |x, obj| obj[x.foreign_key] = x.name end end def association_to_foreign_type_mapping + return {} unless model_class + @association_to_foreign_type_mapping ||= model_class.reflect_on_all_associations.each_with_object({}) do |x, obj| obj[x.name] = x.foreign_type if x.polymorphic? end end def foreign_type_to_association_mapping + return {} unless model_class + @foreign_type_to_association_mapping ||= model_class.reflect_on_all_associations.each_with_object({}) do |x, obj| obj[x.foreign_type] = x.name if x.polymorphic? end end def base_class_name + return "" unless model_class + @base_class_name ||= model_class.base_class.name end @@ -305,7 +317,9 @@ def to_s strategy_name = ", strategy: #{strategy}" if strategy - "InventoryCollection:<#{@model_class}>#{whitelist}#{blacklist}#{strategy_name}" + name = model_class || association + + "InventoryCollection:<#{name}>#{whitelist}#{blacklist}#{strategy_name}" end def inspect From a0d96360e20cd95dd6fc1d9fcdca22631b869840 Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Wed, 8 Feb 2017 14:38:14 +0100 Subject: [PATCH 4/4] Ansible has to use kwargs for model_class Ansible has to use kwargs for model_class --- .../ansible_tower/inventory/target/automation_manager.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/manageiq/providers/ansible_tower/inventory/target/automation_manager.rb b/app/models/manageiq/providers/ansible_tower/inventory/target/automation_manager.rb index 9a2991d9edc..7cb23608c0e 100644 --- a/app/models/manageiq/providers/ansible_tower/inventory/target/automation_manager.rb +++ b/app/models/manageiq/providers/ansible_tower/inventory/target/automation_manager.rb @@ -1,7 +1,7 @@ class ManageIQ::Providers::AnsibleTower::Inventory::Target::AutomationManager < ManagerRefresh::Inventory::Target def inventory_groups collections[:inventory_groups] ||= ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::AutomationManager::InventoryRootGroup, + :model_class => ManageIQ::Providers::AutomationManager::InventoryRootGroup, :association => :inventory_root_groups, :parent => @root, :builder_params => {:manager => @root} @@ -10,7 +10,7 @@ def inventory_groups def configured_systems collections[:configured_systems] ||= ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::AnsibleTower::AutomationManager::ConfiguredSystem, + :model_class => ManageIQ::Providers::AnsibleTower::AutomationManager::ConfiguredSystem, :association => :configured_systems, :parent => @root, :manager_ref => [:manager_ref], @@ -20,7 +20,7 @@ def configured_systems def configuration_scripts collections[:configuration_scripts] ||= ManagerRefresh::InventoryCollection.new( - ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript, + :model_class => ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript, :association => :configuration_scripts, :parent => @root, :manager_ref => [:manager_ref],