Skip to content

Commit

Permalink
stop workers during online backup
Browse files Browse the repository at this point in the history
this ensures more consistent on-disk data
  • Loading branch information
evgeni committed Jun 17, 2024
1 parent 51ecb87 commit db07fba
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 14 deletions.
4 changes: 4 additions & 0 deletions definitions/features/dynflow_sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def services
end
end

def workers
services.reject { |service| service.name.end_with?('@orchestrator') }
end

private

def instance_priority(instance)
Expand Down
36 changes: 25 additions & 11 deletions definitions/scenarios/backup.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
module ForemanMaintain::Scenarios
class Backup < ForemanMaintain::Scenario
class BackupBase < ForemanMaintain::Scenario
private

def strategy
context.get(:strategy)
end

def online_worker_services
services = []
services += feature(:dynflow_sidekiq).workers if feature(:dynflow_sidekiq)
services += feature(:pulpcore).configured_workers if feature(:pulpcore)
services
end
end

class Backup < BackupBase
metadata do
description 'Backup'
manual_detection
Expand Down Expand Up @@ -107,6 +122,9 @@ def include_dumps
end

def add_online_backup_steps
services = online_worker_services
add_step(Procedures::Service::Stop.new(:only => services)) unless services.empty?

add_step_with_context(Procedures::Backup::ConfigFiles, :ignore_changed_files => true,
:online_backup => true)
add_step_with_context(Procedures::Backup::Pulp, :ensure_unchanged => true)
Expand All @@ -115,10 +133,8 @@ def add_online_backup_steps
Procedures::Backup::Online::ForemanDB,
Procedures::Backup::Online::PulpcoreDB
)
end

def strategy
context.get(:strategy)
add_step(Procedures::Service::Start.new(:only => services)) unless services.empty?
end

def include_db_dumps?
Expand All @@ -130,7 +146,7 @@ def wait_for_tasks?
end
end

class BackupRescueCleanup < ForemanMaintain::Scenario
class BackupRescueCleanup < BackupBase
metadata do
description 'Failed backup cleanup'
manual_detection
Expand All @@ -145,6 +161,10 @@ def compose
add_step_with_context(Procedures::Service::Start)
add_steps_with_context(find_procedures(:maintenance_mode_off))
end
if strategy == :online
services = online_worker_services
add_step(Procedures::Service::Start.new(:only => services)) unless services.empty?
end
add_step_with_context(Procedures::Backup::Clean)
end

Expand All @@ -154,11 +174,5 @@ def set_context_mapping
context.map(:preserve_dir,
Procedures::Backup::Clean => :preserve_dir)
end

private

def strategy
context.get(:strategy)
end
end
end
41 changes: 38 additions & 3 deletions test/definitions/scenarios/backup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ module Scenarios
db.any_instance.stubs(:local?).returns(true)
end
end

assume_feature_present(:pulpcore) do |feature|
feature.any_instance.stubs(:configured_workers).returns([existing_pulpcore_worker])
end

assume_feature_present(:dynflow_sidekiq) do |feature|
feature.any_instance.stubs(:workers).returns([existing_dynflow_worker])
end
end

let(:existing_pulpcore_worker) { existing_system_service('pulpcore-worker@1', 10) }
let(:existing_dynflow_worker) { existing_system_service('dynflow-sidekiq@worker-1', 10) }

let(:checks) do
[Checks::ForemanTasks::NotRunning,
Expand Down Expand Up @@ -77,13 +87,21 @@ module Scenarios
refute_scenario_has_step(scenario, Procedures::Backup::AccessibilityConfirmation)
assert_scenario_has_step(scenario, Procedures::Backup::PrepareDirectory)
assert_scenario_has_step(scenario, Procedures::Backup::Metadata)
refute_scenario_has_step(scenario, Procedures::Service::Stop)
assert_scenario_has_step(scenario, Procedures::Service::Stop) do |step|
assert_includes(step.common_options[:only], existing_pulpcore_worker)
assert_includes(step.common_options[:only], existing_dynflow_worker)
assert_equal(step.common_options[:only].length, 2)
end
assert_scenario_has_step(scenario, Procedures::Backup::ConfigFiles)
assert_scenario_has_step(scenario, Procedures::Backup::Pulp)
assert_scenario_has_step(scenario, Procedures::Backup::Online::CandlepinDB)
assert_scenario_has_step(scenario, Procedures::Backup::Online::ForemanDB)
assert_scenario_has_step(scenario, Procedures::Backup::Online::PulpcoreDB)
refute_scenario_has_step(scenario, Procedures::Service::Start)
assert_scenario_has_step(scenario, Procedures::Service::Start) do |step|
assert_includes(step.common_options[:only], existing_pulpcore_worker)
assert_includes(step.common_options[:only], existing_dynflow_worker)
assert_equal(step.common_options[:only].length, 2)
end
assert_scenario_has_step(scenario, Procedures::Backup::CompressData)
end
end
Expand All @@ -107,6 +125,19 @@ module Scenarios
describe ForemanMaintain::Scenarios::BackupRescueCleanup do
include DefinitionsTestHelper

before do
assume_feature_present(:pulpcore) do |feature|
feature.any_instance.stubs(:configured_workers).returns([existing_pulpcore_worker])
end

assume_feature_present(:dynflow_sidekiq) do |feature|
feature.any_instance.stubs(:workers).returns([existing_dynflow_worker])
end
end

let(:existing_pulpcore_worker) { existing_system_service('pulpcore-worker@1', 10) }
let(:existing_dynflow_worker) { existing_system_service('dynflow-sidekiq@worker-1', 10) }

describe 'offline' do
let(:scenario) do
ForemanMaintain::Scenarios::BackupRescueCleanup.new(:backup_dir => '.',
Expand All @@ -126,7 +157,11 @@ module Scenarios
end

it 'composes all steps' do
refute_scenario_has_step(scenario, Procedures::Service::Start)
assert_scenario_has_step(scenario, Procedures::Service::Start) do |step|
assert_includes(step.common_options[:only], existing_pulpcore_worker)
assert_includes(step.common_options[:only], existing_dynflow_worker)
assert_equal(step.common_options[:only].length, 2)
end
assert_scenario_has_step(scenario, Procedures::Backup::Clean)
end
end
Expand Down

0 comments on commit db07fba

Please sign in to comment.