Skip to content

Commit

Permalink
Refactor DelegatedAction
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adamruzicka committed Apr 15, 2024
1 parent 953da9d commit 3c94df6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
16 changes: 5 additions & 11 deletions app/lib/actions/helpers/with_delegated_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,8 +35,6 @@ def delegated_output
{}
when ::Actions::ProxyAction
action.proxy_output(true)
else
action.output
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/lib/actions/proxy_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/api/tasks_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions test/unit/actions/proxy_action_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3c94df6

Please sign in to comment.