foreman_maintain 0.1.6 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +48 -10
- data/bin/foreman-maintain-rotate-tar +18 -0
- data/definitions/checks/backup/certs_tar_exist.rb +24 -0
- data/definitions/checks/backup/directory_ready.rb +21 -0
- data/definitions/checks/candlepin/db_up.rb +29 -0
- data/definitions/checks/check_epel_repository.rb +21 -0
- data/definitions/checks/foreman/db_up.rb +29 -0
- data/definitions/checks/hammer_ping.rb +3 -1
- data/definitions/checks/mongo/db_up.rb +29 -0
- data/definitions/checks/mongo/tools_installed.rb +31 -0
- data/definitions/checks/repositories/validate.rb +0 -3
- data/definitions/checks/root_user.rb +12 -0
- data/definitions/features/candlepin.rb +16 -0
- data/definitions/features/candlepin_database.rb +3 -1
- data/definitions/features/downstream.rb +21 -22
- data/definitions/features/foreman_database.rb +2 -0
- data/definitions/features/foreman_proxy.rb +70 -7
- data/definitions/features/foreman_server.rb +29 -0
- data/definitions/features/foreman_tasks.rb +5 -1
- data/definitions/features/hammer.rb +158 -3
- data/definitions/features/installer.rb +106 -0
- data/definitions/features/instance.rb +39 -0
- data/definitions/features/katello.rb +43 -0
- data/definitions/features/mongo.rb +159 -0
- data/definitions/features/pulp.rb +30 -0
- data/definitions/features/puppet.rb +21 -0
- data/definitions/features/puppet_server.rb +2 -6
- data/definitions/features/service.rb +134 -0
- data/definitions/features/sync_plans.rb +1 -1
- data/definitions/features/tar.rb +69 -0
- data/definitions/procedures/backup/accessibility_confirmation.rb +14 -0
- data/definitions/procedures/backup/clean.rb +16 -0
- data/definitions/procedures/backup/compress_data.rb +26 -0
- data/definitions/procedures/backup/config_files.rb +36 -0
- data/definitions/procedures/backup/metadata.rb +56 -0
- data/definitions/procedures/backup/offline/candlepin_db.rb +57 -0
- data/definitions/procedures/backup/offline/foreman_db.rb +57 -0
- data/definitions/procedures/backup/offline/mongo.rb +56 -0
- data/definitions/procedures/backup/online/candlepin_db.rb +20 -0
- data/definitions/procedures/backup/online/foreman_db.rb +20 -0
- data/definitions/procedures/backup/online/mongo.rb +21 -0
- data/definitions/procedures/backup/online/pg_global_objects.rb +23 -0
- data/definitions/procedures/backup/online/safety_confirmation.rb +25 -0
- data/definitions/procedures/backup/prepare_directory.rb +29 -0
- data/definitions/procedures/backup/pulp.rb +68 -0
- data/definitions/procedures/backup/snapshot/clean_mount.rb +24 -0
- data/definitions/procedures/backup/snapshot/logical_volume_confirmation.rb +47 -0
- data/definitions/procedures/backup/snapshot/mount_base.rb +27 -0
- data/definitions/procedures/backup/snapshot/mount_candlepin_db.rb +48 -0
- data/definitions/procedures/backup/snapshot/mount_foreman_db.rb +48 -0
- data/definitions/procedures/backup/snapshot/mount_mongo.rb +35 -0
- data/definitions/procedures/backup/snapshot/mount_pulp.rb +24 -0
- data/definitions/procedures/backup/snapshot/prepare_mount.rb +16 -0
- data/definitions/procedures/foreman_tasks/fetch_tasks_status.rb +1 -0
- data/definitions/procedures/hammer_setup.rb +4 -39
- data/definitions/procedures/installer/upgrade.rb +1 -21
- data/definitions/procedures/repositories/setup.rb +0 -4
- data/definitions/procedures/service/base.rb +31 -0
- data/definitions/procedures/service/disable.rb +14 -0
- data/definitions/procedures/service/enable.rb +14 -0
- data/definitions/procedures/service/list.rb +26 -0
- data/definitions/procedures/service/restart.rb +49 -0
- data/definitions/procedures/service/start.rb +14 -0
- data/definitions/procedures/service/status.rb +14 -0
- data/definitions/procedures/service/stop.rb +14 -0
- data/definitions/scenarios/backup.rb +242 -0
- data/definitions/scenarios/services.rb +156 -0
- data/definitions/scenarios/upgrade_to_satellite_6_2.rb +2 -2
- data/definitions/scenarios/upgrade_to_satellite_6_2_z.rb +2 -2
- data/definitions/scenarios/upgrade_to_satellite_6_3.rb +2 -2
- data/definitions/scenarios/upgrade_to_satellite_6_3_z.rb +2 -2
- data/definitions/scenarios/upgrade_to_satellite_6_4.rb +79 -0
- data/definitions/scenarios/upgrade_to_satellite_6_4_z.rb +79 -0
- data/lib/foreman_maintain.rb +5 -0
- data/lib/foreman_maintain/cli.rb +4 -0
- data/lib/foreman_maintain/cli/backup_command.rb +157 -0
- data/lib/foreman_maintain/cli/base.rb +18 -8
- data/lib/foreman_maintain/cli/service_command.rb +112 -0
- data/lib/foreman_maintain/cli/transform_clamp_options.rb +1 -1
- data/lib/foreman_maintain/concerns/base_database.rb +57 -5
- data/lib/foreman_maintain/concerns/hammer.rb +0 -9
- data/lib/foreman_maintain/concerns/metadata.rb +3 -1
- data/lib/foreman_maintain/concerns/reporter.rb +12 -0
- data/lib/foreman_maintain/concerns/system_helpers.rb +45 -2
- data/lib/foreman_maintain/detector.rb +3 -3
- data/lib/foreman_maintain/error.rb +12 -0
- data/lib/foreman_maintain/executable.rb +29 -6
- data/lib/foreman_maintain/feature.rb +15 -0
- data/lib/foreman_maintain/param.rb +4 -3
- data/lib/foreman_maintain/reporter.rb +6 -2
- data/lib/foreman_maintain/reporter/cli_reporter.rb +26 -10
- data/lib/foreman_maintain/runner.rb +26 -15
- data/lib/foreman_maintain/runner/execution.rb +5 -1
- data/lib/foreman_maintain/scenario.rb +11 -3
- data/lib/foreman_maintain/upgrade_runner.rb +0 -2
- data/lib/foreman_maintain/utils.rb +2 -2
- data/lib/foreman_maintain/utils/command_runner.rb +0 -2
- data/lib/foreman_maintain/utils/hash_tools.rb +21 -0
- data/lib/foreman_maintain/utils/mongo_core.rb +37 -0
- data/lib/foreman_maintain/version.rb +1 -1
- metadata +58 -8
- data/definitions/features/katello_service.rb +0 -118
- data/definitions/procedures/katello_service/restart.rb +0 -24
- data/definitions/procedures/katello_service/start.rb +0 -19
- data/definitions/procedures/katello_service/stop.rb +0 -17
- data/lib/foreman_maintain/utils/facter.rb +0 -21
- data/lib/foreman_maintain/utils/hammer.rb +0 -79
@@ -1,50 +1,15 @@
|
|
1
1
|
class Procedures::HammerSetup < ForemanMaintain::Procedure
|
2
2
|
metadata do
|
3
3
|
description 'Setup hammer'
|
4
|
+
for_feature :hammer
|
4
5
|
end
|
5
6
|
|
6
7
|
def run
|
7
|
-
|
8
|
-
|
9
|
-
hammer.run_command('architecture list') # if not setup properly, an error will be risen
|
8
|
+
result = feature(:hammer).setup_admin_access
|
9
|
+
logger.info 'Hammer was configured successfully.' if result
|
10
10
|
end
|
11
11
|
|
12
12
|
def necessary?
|
13
|
-
!hammer.
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def setup_from_default
|
19
|
-
used_default_file = hammer.setup_from_default
|
20
|
-
if used_default_file
|
21
|
-
puts "Using defaults from #{used_default_file}"
|
22
|
-
true
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def setup_from_answers
|
27
|
-
loop do
|
28
|
-
username, password = ask_for_credentials
|
29
|
-
break if username.nil?
|
30
|
-
if hammer.setup_from_answers(username, password)
|
31
|
-
return true
|
32
|
-
else
|
33
|
-
puts 'Invalid credentials'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def ask_for_credentials
|
39
|
-
username = ask('Hammer username [admin]:')
|
40
|
-
return if username.nil?
|
41
|
-
username = 'admin' if username.empty?
|
42
|
-
password = ask('Hammer password:', :password => true)
|
43
|
-
return if password.nil?
|
44
|
-
[username.strip, password.strip]
|
45
|
-
end
|
46
|
-
|
47
|
-
def hammer
|
48
|
-
ForemanMaintain::Utils::Hammer.instance
|
13
|
+
!feature(:hammer).check_connection
|
49
14
|
end
|
50
15
|
end
|
@@ -1,27 +1,7 @@
|
|
1
1
|
module Procedures::Installer
|
2
2
|
class Upgrade < ForemanMaintain::Procedure
|
3
3
|
def run
|
4
|
-
|
5
|
-
end
|
6
|
-
|
7
|
-
private
|
8
|
-
|
9
|
-
def upgrade_command?
|
10
|
-
if package_version('satellite-installer') || package_version('katello-installer')
|
11
|
-
'--upgrade'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def installer_command
|
16
|
-
if feature(:downstream)
|
17
|
-
if feature(:downstream).current_minor_version <= '6.1'
|
18
|
-
'katello-installer'
|
19
|
-
else
|
20
|
-
'satellite-installer'
|
21
|
-
end
|
22
|
-
else
|
23
|
-
'foreman-installer'
|
24
|
-
end
|
4
|
+
feature(:installer).upgrade(:interactive => true)
|
25
5
|
end
|
26
6
|
end
|
27
7
|
end
|
@@ -2,10 +2,6 @@ module Procedures::Repositories
|
|
2
2
|
class Setup < ForemanMaintain::Procedure
|
3
3
|
metadata do
|
4
4
|
description 'Setup repositories'
|
5
|
-
preparation_steps do
|
6
|
-
Procedures::Packages::Install.new(:packages => [ForemanMaintain::Utils::Facter.package])
|
7
|
-
end
|
8
|
-
|
9
5
|
confine do
|
10
6
|
feature(:downstream) || feature(:upstream)
|
11
7
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Procedures
|
2
|
+
module Service
|
3
|
+
class Base < ForemanMaintain::Procedure
|
4
|
+
metadata do
|
5
|
+
advanced_run false
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.common_params(context)
|
9
|
+
context.instance_eval do
|
10
|
+
param :only, 'A comma-separated list of services to include', :array => true
|
11
|
+
param :exclude, 'A comma-separated list of services to skip', :array => true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def run_service_action(action, options)
|
16
|
+
action_noun = feature(:service).action_noun(action).capitalize
|
17
|
+
puts "#{action_noun} the following service(s):\n"
|
18
|
+
services = feature(:service).filtered_services(options)
|
19
|
+
feature(:service).list_services(services)
|
20
|
+
|
21
|
+
with_spinner('') do |spinner|
|
22
|
+
feature(:service).handle_services(spinner, action, options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def common_options
|
27
|
+
{ :only => @only, :exclude => @exclude }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'procedures/service/base'
|
2
|
+
|
3
|
+
module Procedures::Service
|
4
|
+
class Disable < Base
|
5
|
+
metadata do
|
6
|
+
description 'Disable applicable services'
|
7
|
+
Base.common_params(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
run_service_action('disable', common_options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'procedures/service/base'
|
2
|
+
|
3
|
+
module Procedures::Service
|
4
|
+
class Enable < Base
|
5
|
+
metadata do
|
6
|
+
description 'Enable applicable services'
|
7
|
+
Base.common_params(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
run_service_action('enable', common_options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'procedures/service/base'
|
2
|
+
|
3
|
+
module Procedures::Service
|
4
|
+
class List < Base
|
5
|
+
metadata do
|
6
|
+
description 'List applicable services'
|
7
|
+
Base.common_params(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
services = feature(:service).filtered_services(common_options)
|
12
|
+
unit_files = unit_files_list(services)
|
13
|
+
puts unit_files + "\n"
|
14
|
+
end
|
15
|
+
|
16
|
+
def unit_files_list(services)
|
17
|
+
if systemd_installed?
|
18
|
+
regex = services.map { |service| "^#{service}.service" }.join('\|')
|
19
|
+
execute("systemctl list-unit-files | grep '#{regex}'")
|
20
|
+
else
|
21
|
+
regex = services.map { |service| "^#{service} " }.join('\|')
|
22
|
+
execute("chkconfig --list 2>&1 | grep '#{regex}'")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'procedures/service/base'
|
2
|
+
|
3
|
+
module Procedures::Service
|
4
|
+
class Restart < Base
|
5
|
+
metadata do
|
6
|
+
description 'Restart applicable services'
|
7
|
+
Base.common_params(self)
|
8
|
+
param :wait_for_hammer_ping,
|
9
|
+
'Wait for hammer ping to return successfully before terminating'
|
10
|
+
end
|
11
|
+
|
12
|
+
RETRIES_FOR_SERVICES_RESTART = 5
|
13
|
+
PING_RETRY_INTERVAL = 30
|
14
|
+
|
15
|
+
def run
|
16
|
+
run_service_action('stop', common_options)
|
17
|
+
run_service_action('start', common_options)
|
18
|
+
hammer_ping_retry if @wait_for_hammer_ping
|
19
|
+
end
|
20
|
+
|
21
|
+
def hammer_ping_retry
|
22
|
+
with_spinner('Checking hammer ping') do |spinner|
|
23
|
+
RETRIES_FOR_SERVICES_RESTART.times do |retry_count|
|
24
|
+
spinner.update retry_message(retry_count)
|
25
|
+
result = feature(:hammer).hammer_ping_cmd
|
26
|
+
if result[:success]
|
27
|
+
spinner.update 'Hammer ping returned successfully!'
|
28
|
+
break
|
29
|
+
elsif retry_count < (RETRIES_FOR_SERVICES_RESTART - 1)
|
30
|
+
apply_sleep_before_retry(spinner, result)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
rescue StandardError => e
|
35
|
+
logger.error e.message
|
36
|
+
end
|
37
|
+
|
38
|
+
def retry_message(retry_count)
|
39
|
+
"Try #{retry_count + 1}/#{RETRIES_FOR_SERVICES_RESTART}: " \
|
40
|
+
'checking status of hammer ping'
|
41
|
+
end
|
42
|
+
|
43
|
+
def apply_sleep_before_retry(spinner, result)
|
44
|
+
puts "\n#{result[:message]}"
|
45
|
+
spinner.update "Waiting #{PING_RETRY_INTERVAL} seconds before retry."
|
46
|
+
sleep PING_RETRY_INTERVAL
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'procedures/service/base'
|
2
|
+
|
3
|
+
module Procedures::Service
|
4
|
+
class Start < Base
|
5
|
+
metadata do
|
6
|
+
description 'Start applicable services'
|
7
|
+
Base.common_params(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
run_service_action('start', common_options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'procedures/service/base'
|
2
|
+
|
3
|
+
module Procedures::Service
|
4
|
+
class Status < Base
|
5
|
+
metadata do
|
6
|
+
description 'Get status of applicable services'
|
7
|
+
Base.common_params(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
run_service_action('status', common_options)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,242 @@
|
|
1
|
+
module ForemanMaintain::Scenarios
|
2
|
+
class Backup < ForemanMaintain::Scenario
|
3
|
+
metadata do
|
4
|
+
description 'Backup'
|
5
|
+
manual_detection
|
6
|
+
tags :backup
|
7
|
+
run_strategy :fail_fast
|
8
|
+
param :strategy, 'Backup strategy. One of [:online, :offline, :snapshot]',
|
9
|
+
:required => true
|
10
|
+
param :backup_dir, 'Directory where to backup to', :required => true
|
11
|
+
param :mount_dir, 'Snapshot mount directory'
|
12
|
+
param :include_db_dumps, 'Include dumps of local dbs as part of offline'
|
13
|
+
param :preserve_dir, 'Directory where to backup to'
|
14
|
+
param :incremental_dir, 'Changes since specified backup only'
|
15
|
+
param :proxy_features, 'List of proxy features to backup (default: all)', :array => true
|
16
|
+
param :snapshot_mount_dir, 'Snapshot mount directory'
|
17
|
+
param :snapshot_block_size, 'Snapshot block size'
|
18
|
+
param :skip_pulp_content, 'Skip Pulp content during backup'
|
19
|
+
param :tar_volume_size, 'Size of tar volume (indicates splitting)'
|
20
|
+
end
|
21
|
+
|
22
|
+
# rubocop:disable Metrics/MethodLength
|
23
|
+
def compose
|
24
|
+
check_valid_startegy
|
25
|
+
safety_confirmation
|
26
|
+
accessibility_confirmation
|
27
|
+
prepare_directory
|
28
|
+
logical_volume_confirmation
|
29
|
+
add_step_with_context(Procedures::Backup::Metadata)
|
30
|
+
add_step_with_context(Procedures::Backup::ConfigFiles)
|
31
|
+
|
32
|
+
case strategy
|
33
|
+
when :online
|
34
|
+
add_online_backup_steps
|
35
|
+
when :offline
|
36
|
+
add_offline_backup_steps
|
37
|
+
when :snapshot
|
38
|
+
add_snaphot_backup_steps
|
39
|
+
end
|
40
|
+
add_step_with_context(Procedures::Backup::CompressData)
|
41
|
+
end
|
42
|
+
# rubocop:enable Metrics/MethodLength
|
43
|
+
|
44
|
+
# rubocop:disable Metrics/MethodLength
|
45
|
+
def set_context_mapping
|
46
|
+
context.map(:backup_dir,
|
47
|
+
Checks::Backup::DirectoryReady => :backup_dir,
|
48
|
+
Procedures::Backup::PrepareDirectory => :backup_dir,
|
49
|
+
Procedures::Backup::Metadata => :backup_dir,
|
50
|
+
Procedures::Backup::ConfigFiles => :backup_dir,
|
51
|
+
Procedures::Backup::CompressData => :backup_dir,
|
52
|
+
Procedures::Backup::Pulp => :backup_dir,
|
53
|
+
Procedures::Backup::Online::Mongo => :backup_dir,
|
54
|
+
Procedures::Backup::Online::PgGlobalObjects => :backup_dir,
|
55
|
+
Procedures::Backup::Online::CandlepinDB => :backup_dir,
|
56
|
+
Procedures::Backup::Online::ForemanDB => :backup_dir,
|
57
|
+
Procedures::Backup::Offline::CandlepinDB => :backup_dir,
|
58
|
+
Procedures::Backup::Offline::ForemanDB => :backup_dir,
|
59
|
+
Procedures::Backup::Offline::Mongo => :backup_dir,
|
60
|
+
Procedures::Backup::Snapshot::LogicalVolumeConfirmation => :backup_dir,
|
61
|
+
Procedures::Backup::Snapshot::MountCandlepinDB => :backup_dir,
|
62
|
+
Procedures::Backup::Snapshot::MountForemanDB => :backup_dir,
|
63
|
+
Procedures::Backup::Snapshot::MountMongo => :backup_dir)
|
64
|
+
context.map(:preserve_dir,
|
65
|
+
Checks::Backup::DirectoryReady => :preserve_dir,
|
66
|
+
Procedures::Backup::PrepareDirectory => :preserve_dir)
|
67
|
+
context.map(:incremental_dir,
|
68
|
+
Procedures::Backup::PrepareDirectory => :incremental_dir,
|
69
|
+
Procedures::Backup::Metadata => :incremental_dir)
|
70
|
+
context.map(:proxy_features,
|
71
|
+
Procedures::Backup::ConfigFiles => :proxy_features)
|
72
|
+
context.map(:snapshot_mount_dir,
|
73
|
+
Procedures::Backup::Snapshot::PrepareMount => :mount_dir,
|
74
|
+
Procedures::Backup::Snapshot::MountMongo => :mount_dir,
|
75
|
+
Procedures::Backup::Snapshot::MountPulp => :mount_dir,
|
76
|
+
Procedures::Backup::Snapshot::CleanMount => :mount_dir,
|
77
|
+
Procedures::Backup::Snapshot::MountCandlepinDB => :mount_dir,
|
78
|
+
Procedures::Backup::Snapshot::MountForemanDB => :mount_dir,
|
79
|
+
Procedures::Backup::Offline::Mongo => :mount_dir,
|
80
|
+
Procedures::Backup::Pulp => :mount_dir,
|
81
|
+
Procedures::Backup::Offline::CandlepinDB => :mount_dir,
|
82
|
+
Procedures::Backup::Offline::ForemanDB => :mount_dir)
|
83
|
+
context.map(:snapshot_block_size,
|
84
|
+
Procedures::Backup::Snapshot::MountMongo => :block_size,
|
85
|
+
Procedures::Backup::Snapshot::MountPulp => :block_size,
|
86
|
+
Procedures::Backup::Snapshot::MountForemanDB => :block_size,
|
87
|
+
Procedures::Backup::Snapshot::MountCandlepinDB => :block_size)
|
88
|
+
context.map(:skip_pulp_content,
|
89
|
+
Procedures::Backup::Pulp => :skip,
|
90
|
+
Procedures::Backup::Snapshot::LogicalVolumeConfirmation => :skip_pulp,
|
91
|
+
Procedures::Backup::Snapshot::MountPulp => :skip)
|
92
|
+
context.map(:tar_volume_size,
|
93
|
+
Procedures::Backup::Pulp => :tar_volume_size)
|
94
|
+
end
|
95
|
+
# rubocop:enable Metrics/MethodLength
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def prepare_directory
|
100
|
+
add_steps_with_context(
|
101
|
+
Procedures::Backup::PrepareDirectory,
|
102
|
+
Checks::Backup::DirectoryReady
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
def logical_volume_confirmation
|
107
|
+
if strategy == :snapshot
|
108
|
+
add_step_with_context(Procedures::Backup::Snapshot::LogicalVolumeConfirmation)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def accessibility_confirmation
|
113
|
+
if [:offline, :snapshot].include?(strategy)
|
114
|
+
add_step_with_context(Procedures::Backup::AccessibilityConfirmation)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def safety_confirmation
|
119
|
+
if online_backup? || include_db_dumps?
|
120
|
+
add_step_with_context(Procedures::Backup::Online::SafetyConfirmation)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def check_valid_startegy
|
125
|
+
unless [:online, :offline, :snapshot].include? strategy
|
126
|
+
raise ArgumentError, "Unsupported strategy '#{strategy}'"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def add_offline_backup_steps
|
131
|
+
include_dumps if include_db_dumps?
|
132
|
+
add_steps_with_context(
|
133
|
+
Procedures::MaintenanceMode::Enable,
|
134
|
+
Procedures::Service::Stop,
|
135
|
+
Procedures::Backup::Pulp,
|
136
|
+
Procedures::Backup::Offline::Mongo,
|
137
|
+
Procedures::Backup::Offline::CandlepinDB,
|
138
|
+
Procedures::Backup::Offline::ForemanDB,
|
139
|
+
Procedures::Service::Start,
|
140
|
+
Procedures::MaintenanceMode::Disable
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
def include_dumps
|
145
|
+
if feature(:instance).postgresql_local?
|
146
|
+
add_step_with_context(Procedures::Backup::Online::PgGlobalObjects)
|
147
|
+
end
|
148
|
+
if feature(:instance).database_local?(:candlepin_database)
|
149
|
+
add_step_with_context(Procedures::Backup::Online::CandlepinDB)
|
150
|
+
end
|
151
|
+
if feature(:instance).database_local?(:foreman_database)
|
152
|
+
add_step_with_context(Procedures::Backup::Online::ForemanDB)
|
153
|
+
end
|
154
|
+
if feature(:instance).database_local?(:mongo)
|
155
|
+
add_step_with_context(Procedures::Backup::Online::Mongo)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# rubocop:disable Metrics/MethodLength
|
160
|
+
def add_snaphot_backup_steps
|
161
|
+
add_steps_with_context(
|
162
|
+
Procedures::Backup::Snapshot::PrepareMount,
|
163
|
+
Procedures::MaintenanceMode::Enable,
|
164
|
+
Procedures::Service::Stop,
|
165
|
+
Procedures::Backup::Snapshot::MountMongo,
|
166
|
+
Procedures::Backup::Snapshot::MountPulp,
|
167
|
+
Procedures::Backup::Snapshot::MountCandlepinDB,
|
168
|
+
Procedures::Backup::Snapshot::MountForemanDB,
|
169
|
+
Procedures::Service::Start,
|
170
|
+
Procedures::MaintenanceMode::Disable,
|
171
|
+
Procedures::Backup::Pulp
|
172
|
+
)
|
173
|
+
if feature(:instance).database_local?(:candlepin_database)
|
174
|
+
add_step_with_context(Procedures::Backup::Offline::CandlepinDB)
|
175
|
+
end
|
176
|
+
if feature(:instance).database_local?(:foreman_database)
|
177
|
+
add_step_with_context(Procedures::Backup::Offline::ForemanDB)
|
178
|
+
end
|
179
|
+
if feature(:instance).database_local?(:mongo)
|
180
|
+
add_step_with_context(Procedures::Backup::Offline::Mongo)
|
181
|
+
end
|
182
|
+
add_step_with_context(Procedures::Backup::Snapshot::CleanMount)
|
183
|
+
end
|
184
|
+
# rubocop:enable Metrics/MethodLength
|
185
|
+
|
186
|
+
def add_online_backup_steps
|
187
|
+
add_step_with_context(Procedures::Backup::Pulp, :ensure_unchanged => true)
|
188
|
+
add_steps_with_context(
|
189
|
+
Procedures::Backup::Online::Mongo,
|
190
|
+
Procedures::Backup::Online::PgGlobalObjects,
|
191
|
+
Procedures::Backup::Online::CandlepinDB,
|
192
|
+
Procedures::Backup::Online::ForemanDB
|
193
|
+
)
|
194
|
+
end
|
195
|
+
|
196
|
+
def strategy
|
197
|
+
context.get(:strategy)
|
198
|
+
end
|
199
|
+
|
200
|
+
def include_db_dumps?
|
201
|
+
!!context.get(:include_db_dumps)
|
202
|
+
end
|
203
|
+
|
204
|
+
def online_backup?
|
205
|
+
strategy == :online
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
class BackupRescueCleanup < ForemanMaintain::Scenario
|
210
|
+
metadata do
|
211
|
+
description 'Failed backup cleanup'
|
212
|
+
manual_detection
|
213
|
+
run_strategy :fail_slow
|
214
|
+
tags :backup
|
215
|
+
param :backup_dir, 'Directory where to backup to', :required => true
|
216
|
+
param :mount_dir, 'Snapshot mount directory'
|
217
|
+
param :preserve_dir, 'Directory where to backup to'
|
218
|
+
end
|
219
|
+
|
220
|
+
def compose
|
221
|
+
add_step_with_context(Procedures::Service::Start) if strategy != :online
|
222
|
+
add_step_with_context(Procedures::MaintenanceMode::Disable) if strategy != :online
|
223
|
+
add_step_with_context(Procedures::Backup::Snapshot::CleanMount) if strategy == :snapshot
|
224
|
+
add_step_with_context(Procedures::Backup::Clean)
|
225
|
+
end
|
226
|
+
|
227
|
+
def set_context_mapping
|
228
|
+
context.map(:snapshot_mount_dir,
|
229
|
+
Procedures::Backup::Snapshot::CleanMount => :mount_dir)
|
230
|
+
context.map(:backup_dir,
|
231
|
+
Procedures::Backup::Clean => :backup_dir)
|
232
|
+
context.map(:preserve_dir,
|
233
|
+
Procedures::Backup::Clean => :preserve_dir)
|
234
|
+
end
|
235
|
+
|
236
|
+
private
|
237
|
+
|
238
|
+
def strategy
|
239
|
+
context.get(:strategy)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|