-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add "no running tasks" check for Pulpcore
- Loading branch information
Showing
4 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Checks::Pulpcore | ||
class NoRunningTasks < ForemanMaintain::Check | ||
metadata do | ||
for_feature :pulpcore | ||
description 'Check for running pulpcore tasks' | ||
tags :pre_upgrade | ||
param :wait_for_tasks, | ||
'Wait for tasks to finish or fail directly', | ||
:required => false | ||
end | ||
|
||
def run | ||
tasks = feature(:pulpcore).running_tasks | ||
assert( | ||
tasks.empty?, | ||
failure_message(tasks.length), | ||
:next_steps => calculate_next_steps | ||
) | ||
end | ||
|
||
private | ||
|
||
def failure_message(task_count) | ||
"There are #{task_count} active task(s) in the system." \ | ||
"\nPlease wait for these to complete." | ||
end | ||
|
||
def calculate_next_steps | ||
@wait_for_tasks ? [Procedures::Pulpcore::WaitForTasks.new] : [] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Procedures::Pulpcore | ||
class WaitForTasks < ForemanMaintain::Procedure | ||
metadata do | ||
for_feature :pulpcore | ||
description 'Fetch tasks status and wait till they finish' | ||
advanced_run false | ||
end | ||
|
||
def run | ||
with_spinner("waiting for tasks to finish") do |spinner| | ||
feature(:pulpcore).wait_for_tasks(spinner) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'test_helper' | ||
|
||
describe Checks::Pulpcore::NoRunningTasks do | ||
include DefinitionsTestHelper | ||
|
||
context 'with default params' do | ||
subject do | ||
Checks::Pulpcore::NoRunningTasks.new | ||
end | ||
|
||
it 'passes when not active tasks are present' do | ||
assume_feature_present(:pulpcore, :running_tasks => []) | ||
result = run_check(subject) | ||
assert result.success?, 'Check expected to succeed' | ||
end | ||
|
||
it 'fails when running/paused tasks are present' do | ||
assume_feature_present(:pulpcore, :running_tasks => ['a_task']) | ||
result = run_check(subject) | ||
assert result.fail?, 'Check expected to fail' | ||
msg = 'There are 1 active task(s) in the system.' | ||
msg += "\nPlease wait for these to complete." | ||
assert_match msg, result.output | ||
assert_empty subject.next_steps.map(&:class) | ||
end | ||
end | ||
|
||
context 'with wait_for_tasks=>true' do | ||
subject do | ||
Checks::Pulpcore::NoRunningTasks.new(:wait_for_tasks => true) | ||
end | ||
|
||
it 'passes when not active tasks are present' do | ||
assume_feature_present(:pulpcore, :running_tasks => []) | ||
result = run_check(subject) | ||
assert result.success?, 'Check expected to succeed' | ||
end | ||
|
||
it 'fails when running/paused tasks are present' do | ||
assume_feature_present(:pulpcore, :running_tasks => ['a_task']) | ||
result = run_check(subject) | ||
assert result.fail?, 'Check expected to fail' | ||
msg = 'There are 1 active task(s) in the system.' | ||
msg += "\nPlease wait for these to complete." | ||
assert_match msg, result.output | ||
assert_equal [Procedures::Pulpcore::WaitForTasks], | ||
subject.next_steps.map(&:class) | ||
end | ||
end | ||
end |