From 3c94df6496aac49cf3ab6b004f1a9308c4b2ce46 Mon Sep 17 00:00:00 2001 From: Adam Ruzicka Date: Thu, 4 Apr 2024 16:54:14 +0200 Subject: [PATCH] Refactor DelegatedAction Previously it was intented to be used to either run an action class localy or running the same action class remotely on the proxy. This first case is no longer used anywhere. --- app/lib/actions/helpers/with_delegated_action.rb | 16 +++++----------- app/lib/actions/proxy_action.rb | 2 +- test/controllers/api/tasks_controller_test.rb | 3 +-- test/unit/actions/proxy_action_test.rb | 3 +-- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/app/lib/actions/helpers/with_delegated_action.rb b/app/lib/actions/helpers/with_delegated_action.rb index 687cc0b8b..78f9c3ed6 100644 --- a/app/lib/actions/helpers/with_delegated_action.rb +++ b/app/lib/actions/helpers/with_delegated_action.rb @@ -3,18 +3,14 @@ module Helpers module WithDelegatedAction include ::Actions::Helpers::WithContinuousOutput - def plan_delegated_action(proxy, klass, options, proxy_action_class: ::Actions::ProxyAction) + def plan_delegated_action(proxy, options, proxy_action_class: ::Actions::ProxyAction) case proxy - when :not_defined - if klass.is_a?(String) - raise Foreman::Exception, _('No proxy defined for execution') - else - delegated_action = plan_action(klass, options) - end + when ::SmartProxy + delegated_action = plan_action(proxy_action_class, proxy, options) when :not_available raise Foreman::Exception, _('All proxies with the required feature are unavailable at the moment') - when ::SmartProxy - delegated_action = plan_action(proxy_action_class, proxy, klass, options) + else + raise Foreman::Exception, _('No proxy defined for execution') end input[:delegated_action_id] = delegated_action.id @@ -39,8 +35,6 @@ def delegated_output {} when ::Actions::ProxyAction action.proxy_output(true) - else - action.output end end diff --git a/app/lib/actions/proxy_action.rb b/app/lib/actions/proxy_action.rb index 208016796..3b9101de3 100644 --- a/app/lib/actions/proxy_action.rb +++ b/app/lib/actions/proxy_action.rb @@ -32,7 +32,7 @@ def backtrace fields! exception: type { variants NilClass, Exception } end - def plan(proxy, _klass, options) + def plan(proxy, options) plan_self(options) prepare_remote_task(proxy).save! end diff --git a/test/controllers/api/tasks_controller_test.rb b/test/controllers/api/tasks_controller_test.rb index 9b9f0860d..8dfd988e5 100644 --- a/test/controllers/api/tasks_controller_test.rb +++ b/test/controllers/api/tasks_controller_test.rb @@ -181,8 +181,7 @@ def self.while_suspended .expects(:proxy) .returns(Support::DummyProxyAction.proxy) - triggered = ForemanTasks.trigger(Support::DummyProxyAction, - Support::DummyProxyAction.proxy, + triggered = ForemanTasks.trigger(Support::DummyProxyAction.proxy, 'Proxy::DummyAction', 'foo' => 'bar') Support::DummyProxyAction.proxy.task_triggered.wait(5) diff --git a/test/unit/actions/proxy_action_test.rb b/test/unit/actions/proxy_action_test.rb index 3b2b0df99..25710fbf0 100644 --- a/test/unit/actions/proxy_action_test.rb +++ b/test/unit/actions/proxy_action_test.rb @@ -17,8 +17,7 @@ class ProxyActionTest < ActiveSupport::TestCase Setting.stubs(:[]).with('foreman_tasks_proxy_action_retry_interval') Setting.stubs(:[]).with('foreman_tasks_proxy_action_retry_count') Setting.stubs(:[]).with('foreman_tasks_proxy_batch_trigger').returns(batch_triggering) - @action = create_and_plan_action(Support::DummyProxyAction, - Support::DummyProxyAction.proxy, + @action = create_and_plan_action(Support::DummyProxyAction.proxy, 'Proxy::DummyAction', 'foo' => 'bar', 'secrets' => secrets,