diff --git a/definitions/checks/foreman_tasks/not_running.rb b/definitions/checks/foreman_tasks/not_running.rb index cc093b69a..6cc7f6433 100644 --- a/definitions/checks/foreman_tasks/not_running.rb +++ b/definitions/checks/foreman_tasks/not_running.rb @@ -6,17 +6,17 @@ class NotRunning < ForemanMaintain::Check tags :pre_upgrade after :foreman_tasks_not_paused before :check_old_foreman_tasks + param :wait_for_tasks, + 'Wait for tasks to finish or fail directly', + :required => false, + :default => true end def run task_count = feature(:foreman_tasks).running_tasks_count assert(task_count == 0, failure_message(task_count), - :next_steps => - [Procedures::ForemanTasks::FetchTasksStatus.new(:state => 'running'), - Procedures::ForemanTasks::UiInvestigate.new( - 'search_query' => search_query_for_running_tasks - )]) + :next_steps => calculate_next_steps) end private @@ -30,5 +30,18 @@ def failure_message(task_count) "There are #{task_count} active task(s) in the system." \ "\nPlease wait for these to complete or cancel them from the Monitor tab." end + + def calculate_next_steps + steps = [] + if @wait_for_tasks + steps << Procedures::ForemanTasks::FetchTasksStatus.new(:state => 'running') + unless assumeyes? + steps << Procedures::ForemanTasks::UiInvestigate.new( + 'search_query' => search_query_for_running_tasks + ) + end + end + steps + end end end diff --git a/test/definitions/checks/foreman_tasks/not_running_test.rb b/test/definitions/checks/foreman_tasks/not_running_test.rb index a308f02f9..3db35fa08 100644 --- a/test/definitions/checks/foreman_tasks/not_running_test.rb +++ b/test/definitions/checks/foreman_tasks/not_running_test.rb @@ -3,25 +3,49 @@ describe Checks::ForemanTasks::NotRunning do include DefinitionsTestHelper - subject do - Checks::ForemanTasks::NotRunning.new - end + context 'with default params' do + subject do + Checks::ForemanTasks::NotRunning.new + end + + it 'passes when not active tasks are present' do + assume_feature_present(:foreman_tasks, :running_tasks_count => 0) + result = run_check(subject) + assert result.success?, 'Check expected to succeed' + end - it 'passes when not active tasks are present' do - assume_feature_present(:foreman_tasks, :running_tasks_count => 0) - result = run_check(subject) - assert result.success?, 'Check expected to succeed' + it 'fails when running/paused tasks are present' do + assume_feature_present(:foreman_tasks, :running_tasks_count => 5) + result = run_check(subject) + assert result.fail?, 'Check expected to fail' + msg = 'There are 5 active task(s) in the system.' + msg += "\nPlease wait for these to complete or cancel them from the Monitor tab." + assert_match msg, result.output + assert_equal [Procedures::ForemanTasks::FetchTasksStatus, + Procedures::ForemanTasks::UiInvestigate], + subject.next_steps.map(&:class) + end end - it 'fails when running/paused tasks are present' do - assume_feature_present(:foreman_tasks, :running_tasks_count => 5) - result = run_check(subject) - assert result.fail?, 'Check expected to fail' - msg = 'There are 5 active task(s) in the system.' - msg += "\nPlease wait for these to complete or cancel them from the Monitor tab." - assert_match msg, result.output - assert_equal [Procedures::ForemanTasks::FetchTasksStatus, - Procedures::ForemanTasks::UiInvestigate], - subject.next_steps.map(&:class) + context 'with wait_for_tasks=>false' do + subject do + Checks::ForemanTasks::NotRunning.new(:wait_for_tasks => false) + end + + it 'passes when not active tasks are present' do + assume_feature_present(:foreman_tasks, :running_tasks_count => 0) + result = run_check(subject) + assert result.success?, 'Check expected to succeed' + end + + it 'fails when running/paused tasks are present' do + assume_feature_present(:foreman_tasks, :running_tasks_count => 5) + result = run_check(subject) + assert result.fail?, 'Check expected to fail' + msg = 'There are 5 active task(s) in the system.' + msg += "\nPlease wait for these to complete or cancel them from the Monitor tab." + assert_match msg, result.output + assert_empty subject.next_steps.map(&:class) + end end end