Skip to content

Commit

Permalink
make wait_for_tasks configurable in NotRunning foreman tasks check
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Jun 17, 2024
1 parent e90ef3a commit eae4f00
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 22 deletions.
23 changes: 18 additions & 5 deletions definitions/checks/foreman_tasks/not_running.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
58 changes: 41 additions & 17 deletions test/definitions/checks/foreman_tasks/not_running_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit eae4f00

Please sign in to comment.