From 3e9c44591d60a37d00fa52a8008c8a3fcbbb7516 Mon Sep 17 00:00:00 2001 From: Oleh Fedorenko Date: Tue, 14 May 2024 14:55:06 +0000 Subject: [PATCH] Fixes #37451 - Support Zeitwerk loader --- app/controllers/ansible_roles_controller.rb | 2 +- app/controllers/ansible_variables_controller.rb | 2 +- app/controllers/api/v2/ansible_roles_controller.rb | 2 +- app/controllers/ui_ansible_roles_controller.rb | 2 +- .../async}/sync_playbooks.rb | 0 app/jobs/sync_roles_and_variables.rb | 2 +- app/services/foreman_ansible/api_roles_importer.rb | 2 +- app/services/foreman_ansible/ui_roles_importer.rb | 2 +- foreman_ansible.gemspec | 4 ++-- lib/foreman_ansible/engine.rb | 14 ++++---------- lib/foreman_ansible/register.rb | 2 +- .../ansible_variables_controller_test.rb | 2 +- .../functional/ui_ansible_roles_controller_test.rb | 2 +- test/unit/services/ui_roles_importer_test.rb | 6 +++--- 14 files changed, 19 insertions(+), 25 deletions(-) rename app/jobs/{ => import_playbooks_job/async}/sync_playbooks.rb (100%) diff --git a/app/controllers/ansible_roles_controller.rb b/app/controllers/ansible_roles_controller.rb index b4764c9ce..d225881fc 100644 --- a/app/controllers/ansible_roles_controller.rb +++ b/app/controllers/ansible_roles_controller.rb @@ -46,7 +46,7 @@ def default_order end def create_importer - @importer = ForemanAnsible::UiRolesImporter.new(@proxy) + @importer = ForemanAnsible::UIRolesImporter.new(@proxy) @variables_importer = ForemanAnsible::VariablesImporter.new(@proxy) end diff --git a/app/controllers/ansible_variables_controller.rb b/app/controllers/ansible_variables_controller.rb index 007de0625..254eafecb 100644 --- a/app/controllers/ansible_variables_controller.rb +++ b/app/controllers/ansible_variables_controller.rb @@ -92,7 +92,7 @@ def import_new_roles def create_importer @importer = ForemanAnsible::VariablesImporter.new(@proxy) - @importer_roles = ForemanAnsible::UiRolesImporter.new(@proxy) + @importer_roles = ForemanAnsible::UIRolesImporter.new(@proxy) end def find_required_proxy diff --git a/app/controllers/api/v2/ansible_roles_controller.rb b/app/controllers/api/v2/ansible_roles_controller.rb index 50e9d58c2..6baed48b3 100644 --- a/app/controllers/api/v2/ansible_roles_controller.rb +++ b/app/controllers/api/v2/ansible_roles_controller.rb @@ -98,7 +98,7 @@ def find_proxy # rubocop:enable Layout/DotPosition def create_importer - @roles_importer = ForemanAnsible::UiRolesImporter.new(@proxy) + @roles_importer = ForemanAnsible::UIRolesImporter.new(@proxy) @variables_importer = ForemanAnsible::VariablesImporter.new(@proxy) @importer = ForemanAnsible::ApiRolesImporter.new(@proxy) end diff --git a/app/controllers/ui_ansible_roles_controller.rb b/app/controllers/ui_ansible_roles_controller.rb index 364bedc97..4dcaef9a9 100644 --- a/app/controllers/ui_ansible_roles_controller.rb +++ b/app/controllers/ui_ansible_roles_controller.rb @@ -1,4 +1,4 @@ -class UiAnsibleRolesController < ::Api::V2::BaseController +class UIAnsibleRolesController < ::Api::V2::BaseController def resource_name(resource = 'AnsibleRole') super resource end diff --git a/app/jobs/sync_playbooks.rb b/app/jobs/import_playbooks_job/async/sync_playbooks.rb similarity index 100% rename from app/jobs/sync_playbooks.rb rename to app/jobs/import_playbooks_job/async/sync_playbooks.rb diff --git a/app/jobs/sync_roles_and_variables.rb b/app/jobs/sync_roles_and_variables.rb index 85056c85a..268bf75a4 100644 --- a/app/jobs/sync_roles_and_variables.rb +++ b/app/jobs/sync_roles_and_variables.rb @@ -2,7 +2,7 @@ class SyncRolesAndVariables < ::ApplicationJob queue_as :default def perform(changed, proxy) - roles_importer = ForemanAnsible::UiRolesImporter.new(proxy) + roles_importer = ForemanAnsible::UIRolesImporter.new(proxy) variables_importer = ForemanAnsible::VariablesImporter.new(proxy) roles_importer.finish_import(changed) variables_importer.import_variables_roles(changed) if changed['new'] || changed['old'] diff --git a/app/services/foreman_ansible/api_roles_importer.rb b/app/services/foreman_ansible/api_roles_importer.rb index 9deaf411f..ea59515d2 100644 --- a/app/services/foreman_ansible/api_roles_importer.rb +++ b/app/services/foreman_ansible/api_roles_importer.rb @@ -6,7 +6,7 @@ class ApiRolesImporter < RolesImporter include ::ForemanAnsible::AnsibleRolesDataPreparations def import!(role_names) - @roles_importer = ForemanAnsible::UiRolesImporter.new(@ansible_proxy) + @roles_importer = ForemanAnsible::UIRolesImporter.new(@ansible_proxy) @variables_importer = ForemanAnsible::VariablesImporter.new(@ansible_proxy) params = { 'changed' => {} } roles = prepare_ansible_import_rows(@roles_importer.import!, @variables_importer, false) diff --git a/app/services/foreman_ansible/ui_roles_importer.rb b/app/services/foreman_ansible/ui_roles_importer.rb index 7908d1569..f68dea13a 100644 --- a/app/services/foreman_ansible/ui_roles_importer.rb +++ b/app/services/foreman_ansible/ui_roles_importer.rb @@ -2,7 +2,7 @@ module ForemanAnsible # imports ansible roles through UI - class UiRolesImporter < RolesImporter + class UIRolesImporter < RolesImporter def import! import_role_names end diff --git a/foreman_ansible.gemspec b/foreman_ansible.gemspec index 351436b09..713db1865 100644 --- a/foreman_ansible.gemspec +++ b/foreman_ansible.gemspec @@ -20,8 +20,8 @@ Gem::Specification.new do |s| s.add_dependency 'acts_as_list', '~> 1.0.3' s.add_dependency 'deface', '< 2.0' - s.add_dependency 'foreman_remote_execution', '>= 9.0', '< 14' - s.add_dependency 'foreman-tasks', '>= 7.0', '< 10' + s.add_dependency 'foreman_remote_execution', '>= 14.0', '< 15' + s.add_dependency 'foreman-tasks', '>= 10.0', '< 11' s.add_development_dependency 'theforeman-rubocop', '~> 0.1.0' end diff --git a/lib/foreman_ansible/engine.rb b/lib/foreman_ansible/engine.rb index fad1a4c8e..55eed5640 100644 --- a/lib/foreman_ansible/engine.rb +++ b/lib/foreman_ansible/engine.rb @@ -11,16 +11,10 @@ module ForemanAnsible class Engine < ::Rails::Engine engine_name 'foreman_ansible' - config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"] - config.autoload_paths += Dir["#{config.root}/app/models"] - config.autoload_paths += Dir["#{config.root}/app/helpers"] - config.autoload_paths += Dir["#{config.root}/app/overrides"] - config.autoload_paths += Dir["#{config.root}/app/services"] - config.autoload_paths += Dir["#{config.root}/app/views"] - config.autoload_paths += Dir["#{config.root}/app/lib"] - - initializer 'foreman_ansible.register_plugin', :before => :finisher_hook do - require 'foreman_ansible/register' + initializer 'foreman_ansible.register_plugin', :before => :finisher_hook do |app| + app.reloader.to_prepare do + require 'foreman_ansible/register' + end end initializer('foreman_ansible.require_dynflow', diff --git a/lib/foreman_ansible/register.rb b/lib/foreman_ansible/register.rb index 97e973527..8827f8447 100644 --- a/lib/foreman_ansible/register.rb +++ b/lib/foreman_ansible/register.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true Foreman::Plugin.register :foreman_ansible do - requires_foreman '>= 3.10.0' + requires_foreman '>= 3.13.0' register_gettext settings do diff --git a/test/functional/ansible_variables_controller_test.rb b/test/functional/ansible_variables_controller_test.rb index 64d9d1ba0..dc099597f 100644 --- a/test/functional/ansible_variables_controller_test.rb +++ b/test/functional/ansible_variables_controller_test.rb @@ -25,7 +25,7 @@ class AnsibleVariablesControllerTest < ActionController::TestCase test 'there are no problems when the import hash is empty' do ForemanAnsible::VariablesImporter.any_instance. expects(:import_variable_names).returns({}) - ForemanAnsible::UiRolesImporter.any_instance. + ForemanAnsible::UIRolesImporter.any_instance. expects(:import_role_names).returns({}) get :import, diff --git a/test/functional/ui_ansible_roles_controller_test.rb b/test/functional/ui_ansible_roles_controller_test.rb index 37f4fa260..f4f871a95 100644 --- a/test/functional/ui_ansible_roles_controller_test.rb +++ b/test/functional/ui_ansible_roles_controller_test.rb @@ -1,6 +1,6 @@ require 'test_plugin_helper' -class UiAnsibleRolesControllerTest < ActionController::TestCase +class UIAnsibleRolesControllerTest < ActionController::TestCase setup do @role = FactoryBot.create(:ansible_role) end diff --git a/test/unit/services/ui_roles_importer_test.rb b/test/unit/services/ui_roles_importer_test.rb index e6a73f776..bd7571a04 100644 --- a/test/unit/services/ui_roles_importer_test.rb +++ b/test/unit/services/ui_roles_importer_test.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true require 'test_plugin_helper' -# unit tests for UiRolesImporter -class UiRolesImporterTest < ActiveSupport::TestCase +# unit tests for UIRolesImporter +class UIRolesImporterTest < ActiveSupport::TestCase setup do changed_roles - @importer = ForemanAnsible::UiRolesImporter.new + @importer = ForemanAnsible::UIRolesImporter.new end test 'should create new role' do