From 617b637731a9c6a637bf21ac54e5f8c52f76ad8d Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Wed, 13 Jun 2018 09:59:01 +0200 Subject: [PATCH 1/3] Fixes embedded ansible persisters dependencies From old to new interface --- .../embedded_ansible/inventory/persister/automation_manager.rb | 3 +-- .../inventory/persister/configuration_script_source.rb | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/models/manageiq/providers/embedded_ansible/inventory/persister/automation_manager.rb b/app/models/manageiq/providers/embedded_ansible/inventory/persister/automation_manager.rb index 4460dfadcfe..0c46b2ce215 100644 --- a/app/models/manageiq/providers/embedded_ansible/inventory/persister/automation_manager.rb +++ b/app/models/manageiq/providers/embedded_ansible/inventory/persister/automation_manager.rb @@ -1,3 +1,2 @@ -class ManageIQ::Providers::EmbeddedAnsible::Inventory::Persister::AutomationManager < ManagerRefresh::Inventory::Persister - include ManageIQ::Providers::AnsibleTower::Shared::Inventory::Persister::AutomationManager +class ManageIQ::Providers::EmbeddedAnsible::Inventory::Persister::AutomationManager < ManageIQ::Providers::AnsibleTower::Inventory::Persister::AutomationManager end diff --git a/app/models/manageiq/providers/embedded_ansible/inventory/persister/configuration_script_source.rb b/app/models/manageiq/providers/embedded_ansible/inventory/persister/configuration_script_source.rb index e0375d79eae..21a6f3560f6 100644 --- a/app/models/manageiq/providers/embedded_ansible/inventory/persister/configuration_script_source.rb +++ b/app/models/manageiq/providers/embedded_ansible/inventory/persister/configuration_script_source.rb @@ -1,3 +1,2 @@ -class ManageIQ::Providers::EmbeddedAnsible::Inventory::Persister::ConfigurationScriptSource < ManagerRefresh::Inventory::Persister - include ManageIQ::Providers::AnsibleTower::Shared::Inventory::Persister::ConfigurationScriptSource +class ManageIQ::Providers::EmbeddedAnsible::Inventory::Persister::ConfigurationScriptSource < ManageIQ::Providers::AnsibleTower::Inventory::Persister::ConfigurationScriptSource end From 84de5d26ccfee39ade1c38ae11c8118972c456dc Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Wed, 18 Jul 2018 12:19:35 +0200 Subject: [PATCH 2/3] IC Builder auto_model_class for automation managers manager module forced to AutomationManager --- app/models/manager_refresh/inventory_collection/builder.rb | 6 +++++- .../inventory_collection/builder/automation_manager.rb | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/manager_refresh/inventory_collection/builder.rb b/app/models/manager_refresh/inventory_collection/builder.rb index a2b7c4779c4..b16016e093a 100644 --- a/app/models/manager_refresh/inventory_collection/builder.rb +++ b/app/models/manager_refresh/inventory_collection/builder.rb @@ -207,7 +207,7 @@ def auto_model_class model_class = begin # a) Provider specific class provider_module = ManageIQ::Providers::Inflector.provider_module(@persister_class).name - manager_module = self.class.name.split('::').last + manager_module = auto_model_class_manager_module class_name = "#{provider_module}::#{manager_module}::#{@name.to_s.classify}" class_name.safe_constantize @@ -223,6 +223,10 @@ def auto_model_class end end + def auto_model_class_manager_module + self.class.name.split('::').last + end + # Enables/disables auto_model_class and exception check # @param skip [Boolean] def skip_model_class(skip = true) diff --git a/app/models/manager_refresh/inventory_collection/builder/automation_manager.rb b/app/models/manager_refresh/inventory_collection/builder/automation_manager.rb index afea37551bf..a53fdc08885 100644 --- a/app/models/manager_refresh/inventory_collection/builder/automation_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/automation_manager.rb @@ -48,6 +48,10 @@ def vms protected + def auto_model_class_manager_module + 'AutomationManager' + end + def default_manager_ref add_properties(:manager_ref => %i(manager_ref)) end From e67709bb12fde27d596e44e5cb56f38a4e2a2c10 Mon Sep 17 00:00:00 2001 From: Martin Slemr Date: Wed, 18 Jul 2018 16:00:39 +0200 Subject: [PATCH 3/3] InventoryCollection Builder fix for safe_constantize Safe_constantize can autoload different classes than expected. --- .../inventory_collection/builder.rb | 14 ++++++++------ .../builder/automation_manager.rb | 4 ---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/models/manager_refresh/inventory_collection/builder.rb b/app/models/manager_refresh/inventory_collection/builder.rb index b16016e093a..4a9bcf484f5 100644 --- a/app/models/manager_refresh/inventory_collection/builder.rb +++ b/app/models/manager_refresh/inventory_collection/builder.rb @@ -207,10 +207,16 @@ def auto_model_class model_class = begin # a) Provider specific class provider_module = ManageIQ::Providers::Inflector.provider_module(@persister_class).name - manager_module = auto_model_class_manager_module + manager_module = self.class.name.split('::').last class_name = "#{provider_module}::#{manager_module}::#{@name.to_s.classify}" - class_name.safe_constantize + + inferred_class = class_name.safe_constantize + + # safe_constantize can return different similar class ( some Rails auto-magic :/ ) + if inferred_class.to_s == class_name + inferred_class + end rescue ::ManageIQ::Providers::Inflector::ObjectNotNamespacedError nil end @@ -223,10 +229,6 @@ def auto_model_class end end - def auto_model_class_manager_module - self.class.name.split('::').last - end - # Enables/disables auto_model_class and exception check # @param skip [Boolean] def skip_model_class(skip = true) diff --git a/app/models/manager_refresh/inventory_collection/builder/automation_manager.rb b/app/models/manager_refresh/inventory_collection/builder/automation_manager.rb index a53fdc08885..afea37551bf 100644 --- a/app/models/manager_refresh/inventory_collection/builder/automation_manager.rb +++ b/app/models/manager_refresh/inventory_collection/builder/automation_manager.rb @@ -48,10 +48,6 @@ def vms protected - def auto_model_class_manager_module - 'AutomationManager' - end - def default_manager_ref add_properties(:manager_ref => %i(manager_ref)) end