diff --git a/.github/workflows/ruby_tests.yml b/.github/workflows/ruby_tests.yml index 98b48f72d..1212ce979 100644 --- a/.github/workflows/ruby_tests.yml +++ b/.github/workflows/ruby_tests.yml @@ -23,3 +23,4 @@ jobs: uses: theforeman/actions/.github/workflows/foreman_plugin.yml@v0 with: plugin: foreman_ansible + foreman_version: refs/pull/10131/head 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_playbooks_controller.rb b/app/controllers/api/v2/ansible_playbooks_controller.rb index 6d475bb3f..4dc482b2d 100644 --- a/app/controllers/api/v2/ansible_playbooks_controller.rb +++ b/app/controllers/api/v2/ansible_playbooks_controller.rb @@ -39,7 +39,7 @@ def action_permission end def plan_ansible_sync(proxy_id, playbooks_names) - ForemanTasks.async_task(ImportPlaybooksJob::Async::SyncPlaybooks, proxy_id, playbooks_names) + ForemanTasks.async_task(Actions::SyncPlaybooks, proxy_id, playbooks_names) end private 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/sync_playbooks.rb deleted file mode 100644 index 3a2cd526f..000000000 --- a/app/jobs/sync_playbooks.rb +++ /dev/null @@ -1,25 +0,0 @@ -module ImportPlaybooksJob - module Async - class SyncPlaybooks < ::Actions::EntryAction - def plan(proxy_id, playbooks_names) - plan_self(proxy_id: proxy_id, playbooks_names: playbooks_names) - end - - def run - playbooks_importer = ForemanAnsible::PlaybooksImporter.new(proxy) - output[:result] = playbooks_importer.import_playbooks(playbooks_names) - ForemanAnsible::ImportPlaybooksSuccessNotification.deliver!(task) - rescue StandardError => e - ForemanAnsible::ImportPlaybooksErrorNotification.new(e, task).deliver! - end - - def proxy - SmartProxy.find(input[:proxy_id]) - end - - def playbooks_names - input[:playbooks_names] - end - end - end -end 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/lib/actions/sync_playbooks.rb b/app/lib/actions/sync_playbooks.rb new file mode 100644 index 000000000..0c434bc4c --- /dev/null +++ b/app/lib/actions/sync_playbooks.rb @@ -0,0 +1,23 @@ +module Actions + class SyncPlaybooks < ::Actions::EntryAction + def plan(proxy_id, playbooks_names) + plan_self(proxy_id: proxy_id, playbooks_names: playbooks_names) + end + + def run + playbooks_importer = ForemanAnsible::PlaybooksImporter.new(proxy) + output[:result] = playbooks_importer.import_playbooks(playbooks_names) + ForemanAnsible::ImportPlaybooksSuccessNotification.deliver!(task) + rescue StandardError => e + ForemanAnsible::ImportPlaybooksErrorNotification.new(e, task).deliver! + end + + def proxy + SmartProxy.find(input[:proxy_id]) + end + + def playbooks_names + input[:playbooks_names] + end + end +end 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/gemfile.d/foreman_remote_execution.local.rb b/gemfile.d/foreman_remote_execution.local.rb new file mode 100644 index 000000000..5c1d5125c --- /dev/null +++ b/gemfile.d/foreman_remote_execution.local.rb @@ -0,0 +1 @@ +gem 'foreman_remote_execution', github: 'ofedoren/foreman_remote_execution', branch: 'feat-37453-support-zeitwerk' diff --git a/gemfile.d/foreman_tasks.local.rb b/gemfile.d/foreman_tasks.local.rb new file mode 100644 index 000000000..de8127696 --- /dev/null +++ b/gemfile.d/foreman_tasks.local.rb @@ -0,0 +1 @@ +gem 'foreman-tasks', github: 'ofedoren/foreman-tasks', branch: 'feat-37452-support-zeitwerk' diff --git a/lib/foreman_ansible/register.rb b/lib/foreman_ansible/register.rb index 97e973527..926d1715a 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.12.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