Skip to content

Commit

Permalink
check for running tasks before a backup is done
Browse files Browse the repository at this point in the history
optionally allow waiting for them to complete
  • Loading branch information
evgeni committed Jun 17, 2024
1 parent eae4f00 commit 51ecb87
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions definitions/scenarios/backup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ class Backup < ForemanMaintain::Scenario
param :proxy_features, 'List of proxy features to backup (default: all)', :array => true
param :skip_pulp_content, 'Skip Pulp content during backup'
param :tar_volume_size, 'Size of tar volume (indicates splitting)'
param :wait_for_tasks, 'Wait for running tasks to complete instead of aborting'
end

def compose
check_valid_strategy
add_step(Checks::ForemanTasks::NotRunning.new(:wait_for_tasks => wait_for_tasks?))
add_step(Checks::Pulpcore::NoRunningTasks.new(:wait_for_tasks => wait_for_tasks?))
safety_confirmation
add_step_with_context(Procedures::Backup::AccessibilityConfirmation) if strategy == :offline
add_step_with_context(Procedures::Backup::PrepareDirectory)
Expand Down Expand Up @@ -121,6 +124,10 @@ def strategy
def include_db_dumps?
!!context.get(:include_db_dumps)
end

def wait_for_tasks?
!!context.get(:wait_for_tasks)
end
end

class BackupRescueCleanup < ForemanMaintain::Scenario
Expand Down
2 changes: 2 additions & 0 deletions lib/foreman_maintain/cli/backup_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def common_backup_options
option '--features', 'FEATURES',
"#{proxy_name} features to include in the backup. " \
'Valid features are tftp, dns, dhcp, openscap, and all.', :multivalued => true
option '--wait-for-tasks', :flag, 'Wait for running tasks to complete instead of aborting'
end
# rubocop:enable Metrics/MethodLength

Expand Down Expand Up @@ -89,6 +90,7 @@ def backup_scenario(options, strategy)
:tar_volume_size => split_pulp_tar,
:skip_pulp_content => skip_pulp_content?,
:incremental_dir => incremental,
:wait_for_tasks => wait_for_tasks?,
}.merge(options))
end

Expand Down
46 changes: 46 additions & 0 deletions test/definitions/scenarios/backup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@ module Scenarios
end
end


let(:checks) do
[Checks::ForemanTasks::NotRunning,
Checks::Pulpcore::NoRunningTasks]
end

describe 'offline' do
let(:scenario) do
ForemanMaintain::Scenarios::Backup.new(:backup_dir => '.', :strategy => :offline)
end

it 'composes all steps' do
checks.each do |check|
assert_scenario_has_step(scenario, check) do |step|
refute step.options['wait_for_tasks']
end
end
assert_scenario_has_step(scenario, Procedures::Backup::AccessibilityConfirmation)
assert_scenario_has_step(scenario, Procedures::Backup::PrepareDirectory)
assert_scenario_has_step(scenario, Procedures::Backup::Metadata)
Expand All @@ -36,12 +47,32 @@ module Scenarios
end
end

describe 'offline with wait_for_tasks' do
let(:scenario) do
ForemanMaintain::Scenarios::Backup.new(:backup_dir => '.', :strategy => :offline,
:wait_for_tasks => true)
end

it 'composes all steps' do
checks.each do |check|
assert_scenario_has_step(scenario, check) do |step|
assert step.options['wait_for_tasks']
end
end
end
end

describe 'online' do
let(:scenario) do
ForemanMaintain::Scenarios::Backup.new(:backup_dir => '.', :strategy => :online)
end

it 'composes all steps' do
checks.each do |check|
assert_scenario_has_step(scenario, check) do |step|
refute step.options['wait_for_tasks']
end
end
assert_scenario_has_step(scenario, Procedures::Backup::Online::SafetyConfirmation)
refute_scenario_has_step(scenario, Procedures::Backup::AccessibilityConfirmation)
assert_scenario_has_step(scenario, Procedures::Backup::PrepareDirectory)
Expand All @@ -56,6 +87,21 @@ module Scenarios
assert_scenario_has_step(scenario, Procedures::Backup::CompressData)
end
end

describe 'online with wait_for_tasks' do
let(:scenario) do
ForemanMaintain::Scenarios::Backup.new(:backup_dir => '.', :strategy => :online,
:wait_for_tasks => true)
end

it 'composes all steps' do
checks.each do |check|
assert_scenario_has_step(scenario, check) do |step|
assert step.options['wait_for_tasks']
end
end
end
end
end

describe ForemanMaintain::Scenarios::BackupRescueCleanup do
Expand Down

0 comments on commit 51ecb87

Please sign in to comment.