foreman_maintain 0.5.4 → 0.6.4
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 +4 -0
- data/definitions/checks/check_hotfix_installed.rb +2 -1
- data/definitions/checks/disk/performance.rb +25 -10
- data/definitions/checks/foreman/validate_external_db_version.rb +28 -0
- data/definitions/checks/original_assets.rb +1 -0
- data/definitions/checks/pulpcore/db_up.rb +29 -0
- data/definitions/checks/repositories/check_non_rh_repository.rb +23 -0
- data/definitions/checks/repositories/check_upstream_repository.rb +2 -1
- data/definitions/checks/repositories/validate.rb +2 -1
- data/definitions/features/apache.rb +19 -0
- data/definitions/features/dynflow_sidekiq.rb +39 -0
- data/definitions/features/foreman_database.rb +5 -3
- data/definitions/features/foreman_proxy.rb +15 -4
- data/definitions/features/foreman_server.rb +9 -3
- data/definitions/features/foreman_tasks.rb +1 -1
- data/definitions/features/installer.rb +9 -2
- data/definitions/features/instance.rb +10 -3
- data/definitions/features/mongo.rb +1 -1
- data/definitions/features/{pulp.rb → pulp2.rb} +1 -1
- data/definitions/features/pulpcore.rb +28 -0
- data/definitions/features/pulpcore_database.rb +39 -0
- data/definitions/features/redis.rb +34 -0
- data/definitions/features/service.rb +10 -3
- data/definitions/features/tar.rb +18 -13
- data/definitions/procedures/backup/config_files.rb +43 -10
- data/definitions/procedures/backup/offline/pulpcore_db.rb +57 -0
- data/definitions/procedures/backup/online/pulpcore_db.rb +20 -0
- data/definitions/procedures/backup/pulp.rb +3 -3
- data/definitions/procedures/backup/snapshot/logical_volume_confirmation.rb +2 -1
- data/definitions/procedures/backup/snapshot/mount_pulp.rb +3 -3
- data/definitions/procedures/backup/snapshot/mount_pulpcore_db.rb +48 -0
- data/definitions/procedures/content/prepare.rb +12 -0
- data/definitions/procedures/content/switchover.rb +22 -0
- data/definitions/procedures/hammer_setup.rb +1 -1
- data/definitions/procedures/installer/run.rb +3 -1
- data/definitions/procedures/installer/upgrade.rb +6 -1
- data/definitions/procedures/packages/update.rb +1 -1
- data/definitions/procedures/pulp/migrate.rb +1 -1
- data/definitions/procedures/pulpcore/migrate.rb +25 -0
- data/definitions/procedures/restore/configs.rb +7 -0
- data/definitions/procedures/restore/drop_databases.rb +11 -1
- data/definitions/procedures/restore/mongo_dump.rb +2 -2
- data/definitions/procedures/restore/pulpcore_dump.rb +30 -0
- data/definitions/procedures/service/base.rb +1 -1
- data/definitions/procedures/service/stop.rb +1 -1
- data/definitions/scenarios/backup.rb +18 -3
- data/definitions/scenarios/content.rb +27 -0
- data/definitions/scenarios/packages.rb +36 -16
- data/definitions/scenarios/restore.rb +7 -1
- data/definitions/scenarios/upgrade_to_capsule_6_7.rb +88 -0
- data/definitions/scenarios/upgrade_to_capsule_6_7_z.rb +88 -0
- data/definitions/scenarios/upgrade_to_capsule_6_8.rb +88 -0
- data/definitions/scenarios/upgrade_to_capsule_6_8_z.rb +88 -0
- data/definitions/scenarios/upgrade_to_satellite_6_2.rb +13 -5
- data/definitions/scenarios/upgrade_to_satellite_6_2_z.rb +13 -5
- data/definitions/scenarios/upgrade_to_satellite_6_3.rb +13 -5
- data/definitions/scenarios/upgrade_to_satellite_6_3_z.rb +13 -5
- data/definitions/scenarios/upgrade_to_satellite_6_4.rb +13 -5
- data/definitions/scenarios/upgrade_to_satellite_6_4_z.rb +13 -5
- data/definitions/scenarios/upgrade_to_satellite_6_5.rb +13 -5
- data/definitions/scenarios/upgrade_to_satellite_6_5_z.rb +13 -5
- data/definitions/scenarios/upgrade_to_satellite_6_6.rb +13 -5
- data/definitions/scenarios/upgrade_to_satellite_6_6_z.rb +13 -5
- data/definitions/scenarios/upgrade_to_satellite_6_7.rb +13 -5
- data/definitions/scenarios/upgrade_to_satellite_6_7_z.rb +13 -5
- data/definitions/scenarios/upgrade_to_satellite_6_8.rb +88 -0
- data/definitions/scenarios/upgrade_to_satellite_6_8_z.rb +88 -0
- data/lib/foreman_maintain.rb +31 -0
- data/lib/foreman_maintain/cli.rb +2 -0
- data/lib/foreman_maintain/cli/content_command.rb +17 -0
- data/lib/foreman_maintain/cli/upgrade_command.rb +10 -0
- data/lib/foreman_maintain/concerns/base_database.rb +16 -1
- data/lib/foreman_maintain/concerns/downstream.rb +13 -8
- data/lib/foreman_maintain/concerns/system_helpers.rb +9 -7
- data/lib/foreman_maintain/package_manager/dnf.rb +11 -5
- data/lib/foreman_maintain/package_manager/yum.rb +15 -5
- data/lib/foreman_maintain/reporter/cli_reporter.rb +3 -3
- data/lib/foreman_maintain/upgrade_runner.rb +20 -26
- data/lib/foreman_maintain/utils/backup.rb +58 -62
- data/lib/foreman_maintain/utils/service/abstract.rb +8 -1
- data/lib/foreman_maintain/utils/service/systemd.rb +26 -2
- data/lib/foreman_maintain/version.rb +1 -1
- metadata +26 -4
- data/definitions/checks/check_epel_repository.rb +0 -21
@@ -0,0 +1,88 @@
|
|
1
|
+
module Scenarios::Satellite_6_8_z
|
2
|
+
class Abstract < ForemanMaintain::Scenario
|
3
|
+
def self.upgrade_metadata(&block)
|
4
|
+
metadata do
|
5
|
+
tags :upgrade_scenario
|
6
|
+
confine do
|
7
|
+
feature(:satellite) &&
|
8
|
+
(feature(:satellite).current_minor_version == '6.8' || \
|
9
|
+
ForemanMaintain.upgrade_in_progress == '6.8.z')
|
10
|
+
end
|
11
|
+
instance_eval(&block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def target_version
|
16
|
+
'6.8.z'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class PreUpgradeCheck < Abstract
|
21
|
+
upgrade_metadata do
|
22
|
+
description 'Checks before upgrading to Satellite 6.8.z'
|
23
|
+
tags :pre_upgrade_checks
|
24
|
+
run_strategy :fail_slow
|
25
|
+
end
|
26
|
+
|
27
|
+
def compose
|
28
|
+
add_steps(find_checks(:default))
|
29
|
+
add_steps(find_checks(:pre_upgrade))
|
30
|
+
add_step(Checks::Repositories::Validate.new(:version => '6.8'))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class PreMigrations < Abstract
|
35
|
+
upgrade_metadata do
|
36
|
+
description 'Procedures before migrating to Satellite 6.8.z'
|
37
|
+
tags :pre_migrations
|
38
|
+
end
|
39
|
+
|
40
|
+
def compose
|
41
|
+
add_steps(find_procedures(:pre_migrations))
|
42
|
+
add_step(Procedures::Service::Stop.new)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Migrations < Abstract
|
47
|
+
upgrade_metadata do
|
48
|
+
description 'Migration scripts to Satellite 6.8.z'
|
49
|
+
tags :migrations
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_context_mapping
|
53
|
+
context.map(:assumeyes, Procedures::Installer::Upgrade => :assumeyes)
|
54
|
+
end
|
55
|
+
|
56
|
+
def compose
|
57
|
+
add_step(Procedures::Repositories::Setup.new(:version => '6.8'))
|
58
|
+
add_step(Procedures::Packages::UnlockVersions.new)
|
59
|
+
add_step(Procedures::Packages::Update.new(:assumeyes => true))
|
60
|
+
add_step_with_context(Procedures::Installer::Upgrade)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class PostMigrations < Abstract
|
65
|
+
upgrade_metadata do
|
66
|
+
description 'Procedures after migrating to Satellite 6.8.z'
|
67
|
+
tags :post_migrations
|
68
|
+
end
|
69
|
+
|
70
|
+
def compose
|
71
|
+
add_step(Procedures::Service::Start.new)
|
72
|
+
add_steps(find_procedures(:post_migrations))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class PostUpgradeChecks < Abstract
|
77
|
+
upgrade_metadata do
|
78
|
+
description 'Checks after upgrading to Satellite 6.8.z'
|
79
|
+
tags :post_upgrade_checks
|
80
|
+
run_strategy :fail_slow
|
81
|
+
end
|
82
|
+
|
83
|
+
def compose
|
84
|
+
add_steps(find_checks(:default))
|
85
|
+
add_steps(find_checks(:post_upgrade))
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/foreman_maintain.rb
CHANGED
@@ -139,5 +139,36 @@ module ForemanMaintain
|
|
139
139
|
rescue StandardError => e
|
140
140
|
logger.error "Invalid Storage label i.e #{label}. Error - #{e.message}"
|
141
141
|
end
|
142
|
+
|
143
|
+
def upgrade_in_progress
|
144
|
+
storage[:upgrade_target_version]
|
145
|
+
end
|
146
|
+
|
147
|
+
def pkg_and_cmd_name
|
148
|
+
instance_feature = ForemanMaintain.available_features(:label => :instance).first
|
149
|
+
if instance_feature.downstream
|
150
|
+
return %w[satellite-maintain satellite-maintain]
|
151
|
+
end
|
152
|
+
|
153
|
+
[main_package_name, 'foreman-maintain']
|
154
|
+
end
|
155
|
+
|
156
|
+
def perform_self_upgrade
|
157
|
+
package_name, command = pkg_and_cmd_name
|
158
|
+
|
159
|
+
puts "Checking for new version of #{package_name}..."
|
160
|
+
if ForemanMaintain.package_manager.update_available?(main_package_name)
|
161
|
+
puts "\nUpdating #{package_name} package."
|
162
|
+
ForemanMaintain.package_manager.update(main_package_name, :assumeyes => true)
|
163
|
+
puts "\nThe #{package_name} package successfully updated."\
|
164
|
+
"\nRe-run #{command} with required options!"
|
165
|
+
exit 0
|
166
|
+
end
|
167
|
+
puts "Nothing to update, can't find new version of #{package_name}."
|
168
|
+
end
|
169
|
+
|
170
|
+
def main_package_name
|
171
|
+
'rubygem-foreman_maintain'
|
172
|
+
end
|
142
173
|
end
|
143
174
|
end
|
data/lib/foreman_maintain/cli.rb
CHANGED
@@ -10,6 +10,7 @@ require 'foreman_maintain/cli/service_command'
|
|
10
10
|
require 'foreman_maintain/cli/restore_command'
|
11
11
|
require 'foreman_maintain/cli/maintenance_mode_command'
|
12
12
|
require 'foreman_maintain/cli/packages_command'
|
13
|
+
require 'foreman_maintain/cli/content_command'
|
13
14
|
|
14
15
|
module ForemanMaintain
|
15
16
|
module Cli
|
@@ -23,6 +24,7 @@ module ForemanMaintain
|
|
23
24
|
subcommand 'restore', 'Restore a backup', RestoreCommand
|
24
25
|
subcommand 'packages', 'Lock/Unlock package protection, install, update', PackagesCommand
|
25
26
|
subcommand 'advanced', 'Advanced tools for server maintenance', AdvancedCommand
|
27
|
+
subcommand 'content', 'Content related commands', ContentCommand
|
26
28
|
subcommand 'maintenance-mode', 'Control maintenance-mode for application',
|
27
29
|
MaintenanceModeCommand
|
28
30
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ForemanMaintain
|
2
|
+
module Cli
|
3
|
+
class ContentCommand < Base
|
4
|
+
subcommand 'prepare', 'Prepare content for Pulp 3' do
|
5
|
+
def execute
|
6
|
+
run_scenarios_and_exit(Scenarios::Content::Prepare.new)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
subcommand 'switchover', 'Switch support for certain content from Pulp 2 to Pulp 3' do
|
11
|
+
def execute
|
12
|
+
run_scenarios_and_exit(Scenarios::Content::Switchover.new)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -6,6 +6,11 @@ module ForemanMaintain
|
|
6
6
|
:required => false
|
7
7
|
end
|
8
8
|
|
9
|
+
def self.disable_self_upgrade_option
|
10
|
+
option '--disable-self-upgrade', :flag, 'Disable automatic self upgrade',
|
11
|
+
:default => false
|
12
|
+
end
|
13
|
+
|
9
14
|
def current_target_version
|
10
15
|
current_target_version = ForemanMaintain::UpgradeRunner.current_target_version
|
11
16
|
if current_target_version && target_version && target_version != current_target_version
|
@@ -56,8 +61,10 @@ module ForemanMaintain
|
|
56
61
|
subcommand 'check', 'Run pre-upgrade checks before upgrading to specified version' do
|
57
62
|
target_version_option
|
58
63
|
interactive_option
|
64
|
+
disable_self_upgrade_option
|
59
65
|
|
60
66
|
def execute
|
67
|
+
ForemanMaintain.perform_self_upgrade unless disable_self_upgrade?
|
61
68
|
upgrade_runner.run_phase(:pre_upgrade_checks)
|
62
69
|
exit upgrade_runner.exit_code
|
63
70
|
end
|
@@ -66,6 +73,8 @@ module ForemanMaintain
|
|
66
73
|
subcommand 'run', 'Run full upgrade to a specified version' do
|
67
74
|
target_version_option
|
68
75
|
interactive_option
|
76
|
+
disable_self_upgrade_option
|
77
|
+
|
69
78
|
option '--phase', 'phase', 'run only a specific phase', :required => false do |phase|
|
70
79
|
unless UpgradeRunner::PHASES.include?(phase.to_sym)
|
71
80
|
raise Error::UsageError, "Unknown phase #{phase}"
|
@@ -74,6 +83,7 @@ module ForemanMaintain
|
|
74
83
|
end
|
75
84
|
|
76
85
|
def execute
|
86
|
+
ForemanMaintain.perform_self_upgrade unless disable_self_upgrade?
|
77
87
|
if phase
|
78
88
|
upgrade_runner.run_phase(phase.to_sym)
|
79
89
|
else
|
@@ -2,7 +2,11 @@ module ForemanMaintain
|
|
2
2
|
module Concerns
|
3
3
|
module BaseDatabase
|
4
4
|
def data_dir
|
5
|
-
'
|
5
|
+
if check_min_version('foreman', '2.0')
|
6
|
+
'/var/opt/rh/rh-postgresql12/lib/pgsql/data/'
|
7
|
+
else
|
8
|
+
'/var/lib/pgsql/data/'
|
9
|
+
end
|
6
10
|
end
|
7
11
|
|
8
12
|
def configuration
|
@@ -146,6 +150,17 @@ module ForemanMaintain
|
|
146
150
|
end
|
147
151
|
end
|
148
152
|
|
153
|
+
def db_version(config = configuration)
|
154
|
+
if ping(config)
|
155
|
+
# Note - t removes headers, -A removes alignment whitespace
|
156
|
+
server_version_cmd = psql_command(config) + ' -c "SHOW server_version" -t -A'
|
157
|
+
version_string = execute!(server_version_cmd, :hidden_patterns => [config['password']])
|
158
|
+
version(version_string)
|
159
|
+
else
|
160
|
+
raise_service_error
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
149
164
|
private
|
150
165
|
|
151
166
|
def base_command(config, command = 'psql')
|
@@ -97,16 +97,21 @@ module ForemanMaintain
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def common_repos(rh_version_major, full_version)
|
100
|
-
|
101
|
-
|
100
|
+
repos_arrary = common_repos_array(rh_version_major, full_version)
|
101
|
+
return repos_arrary.first(1) if feature(:capsule)
|
102
102
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
103
|
+
repos_arrary
|
104
|
+
end
|
105
|
+
|
106
|
+
def common_repos_array(rh_version_major, full_version)
|
107
|
+
["rhel-#{rh_version_major}-server-satellite-maintenance-6#{use_beta}-rpms",
|
108
|
+
"rhel-#{rh_version_major}-server-satellite-tools-#{full_version}#{use_beta}-rpms"]
|
109
|
+
end
|
110
|
+
|
111
|
+
def use_beta
|
112
|
+
return '-beta' if ENV['FOREMAN_MAINTAIN_USE_BETA'] == '1'
|
108
113
|
|
109
|
-
|
114
|
+
nil
|
110
115
|
end
|
111
116
|
|
112
117
|
def main_rh_repos(rh_version_major)
|
@@ -53,10 +53,15 @@ module ForemanMaintain
|
|
53
53
|
execute?("command -v #{command_name}")
|
54
54
|
end
|
55
55
|
|
56
|
-
def
|
56
|
+
def execute_runner(command, options = {})
|
57
57
|
command_runner = Utils::CommandRunner.new(logger, command, options)
|
58
58
|
execution.puts '' if command_runner.interactive? && respond_to?(:execution)
|
59
59
|
command_runner.run
|
60
|
+
command_runner
|
61
|
+
end
|
62
|
+
|
63
|
+
def execute!(command, options = {})
|
64
|
+
command_runner = execute_runner(command, options)
|
60
65
|
if command_runner.success?
|
61
66
|
command_runner.output
|
62
67
|
else
|
@@ -65,15 +70,12 @@ module ForemanMaintain
|
|
65
70
|
end
|
66
71
|
|
67
72
|
def execute(command, options = {})
|
68
|
-
|
69
|
-
execution.puts '' if command_runner.interactive? && respond_to?(:execution)
|
70
|
-
command_runner.run
|
71
|
-
command_runner.output
|
73
|
+
execute_runner(command, options).output
|
72
74
|
end
|
73
75
|
|
74
76
|
def execute_with_status(command, options = {})
|
75
|
-
|
76
|
-
[
|
77
|
+
command_runner = execute_runner(command, options)
|
78
|
+
[command_runner.exit_status, command_runner.output]
|
77
79
|
end
|
78
80
|
|
79
81
|
def file_exists?(filename)
|
@@ -1,17 +1,23 @@
|
|
1
1
|
module ForemanMaintain::PackageManager
|
2
2
|
class Dnf < Yum
|
3
|
-
def clean_cache
|
4
|
-
dnf_action('clean', 'all')
|
3
|
+
def clean_cache(assumeyes: false)
|
4
|
+
dnf_action('clean', 'all', :assumeyes => assumeyes)
|
5
5
|
super
|
6
6
|
end
|
7
7
|
|
8
8
|
private
|
9
9
|
|
10
|
-
def dnf_action(action, packages, assumeyes: false)
|
10
|
+
def dnf_action(action, packages, with_status: false, assumeyes: false)
|
11
11
|
yum_options = []
|
12
12
|
yum_options << '-y' if assumeyes
|
13
|
-
|
14
|
-
|
13
|
+
if with_status
|
14
|
+
sys.execute_with_status("dnf #{yum_options.join(' ')} #{action} #{packages.join(' ')}",
|
15
|
+
:interactive => !assumeyes)
|
16
|
+
else
|
17
|
+
sys.execute!("dnf #{yum_options.join(' ')} #{action} #{packages.join(' ')}",
|
18
|
+
:interactive => !assumeyes)
|
19
|
+
|
20
|
+
end
|
15
21
|
end
|
16
22
|
end
|
17
23
|
end
|
@@ -57,8 +57,13 @@ module ForemanMaintain::PackageManager
|
|
57
57
|
yum_action('update', packages, :assumeyes => assumeyes)
|
58
58
|
end
|
59
59
|
|
60
|
-
def clean_cache
|
61
|
-
yum_action('clean', 'all')
|
60
|
+
def clean_cache(assumeyes: false)
|
61
|
+
yum_action('clean', 'all', :assumeyes => assumeyes)
|
62
|
+
end
|
63
|
+
|
64
|
+
def update_available?(package)
|
65
|
+
cmd_output = yum_action('check-update -q', package, :with_status => true, :assumeyes => false)
|
66
|
+
cmd_output[0] == 100
|
62
67
|
end
|
63
68
|
|
64
69
|
def files_not_owned_by_package(directory)
|
@@ -96,14 +101,19 @@ module ForemanMaintain::PackageManager
|
|
96
101
|
File.open(protector_config_file, 'w') { |file| file.puts config }
|
97
102
|
end
|
98
103
|
|
99
|
-
def yum_action(action, packages, assumeyes: false)
|
104
|
+
def yum_action(action, packages, with_status: false, assumeyes: false)
|
100
105
|
yum_options = []
|
101
106
|
packages = [packages].flatten(1)
|
102
107
|
yum_options << '-y' if assumeyes
|
103
108
|
yum_options_s = yum_options.empty? ? '' : ' ' + yum_options.join(' ')
|
104
109
|
packages_s = packages.empty? ? '' : ' ' + packages.join(' ')
|
105
|
-
|
106
|
-
|
110
|
+
if with_status
|
111
|
+
sys.execute_with_status("yum#{yum_options_s} #{action}#{packages_s}",
|
112
|
+
:interactive => !assumeyes)
|
113
|
+
else
|
114
|
+
sys.execute!("yum#{yum_options_s} #{action}#{packages_s}",
|
115
|
+
:interactive => !assumeyes)
|
116
|
+
end
|
107
117
|
end
|
108
118
|
|
109
119
|
def install_extras(src, dest, override: false)
|
@@ -16,7 +16,6 @@ module ForemanMaintain
|
|
16
16
|
@spinner_chars = %w[| / - \\]
|
17
17
|
@current_line = ''
|
18
18
|
@puts_needed = false
|
19
|
-
start_spinner
|
20
19
|
end
|
21
20
|
|
22
21
|
def update(line)
|
@@ -42,8 +41,6 @@ module ForemanMaintain
|
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
45
|
-
private
|
46
|
-
|
47
44
|
def start_spinner
|
48
45
|
@thread = Thread.new do
|
49
46
|
loop do
|
@@ -53,6 +50,8 @@ module ForemanMaintain
|
|
53
50
|
end
|
54
51
|
end
|
55
52
|
|
53
|
+
private
|
54
|
+
|
56
55
|
def spin
|
57
56
|
@mutex.synchronize do
|
58
57
|
return unless @active
|
@@ -80,6 +79,7 @@ module ForemanMaintain
|
|
80
79
|
@line_char = '-'
|
81
80
|
@cell_char = '|'
|
82
81
|
@spinner = Spinner.new(self)
|
82
|
+
@spinner.start_spinner if @stdout.tty?
|
83
83
|
@last_line = ''
|
84
84
|
end
|
85
85
|
|
@@ -15,29 +15,8 @@ module ForemanMaintain
|
|
15
15
|
def available_targets
|
16
16
|
# when some upgrade is in progress, we don't allow upgrade to different version
|
17
17
|
return [current_target_version] if current_target_version
|
18
|
-
versions_to_tags.inject([]) do |available_targets, (version, tag)|
|
19
|
-
if !find_scenarios(:tags => [tag]).empty?
|
20
|
-
available_targets << version
|
21
|
-
else
|
22
|
-
available_targets
|
23
|
-
end
|
24
|
-
end.sort
|
25
|
-
end
|
26
|
-
|
27
|
-
def versions_to_tags
|
28
|
-
@versions_to_tags ||= {}
|
29
|
-
end
|
30
|
-
|
31
|
-
# registers target version to specific tag
|
32
|
-
def register_version(version, tag)
|
33
|
-
if versions_to_tags.key?(version) && versions_to_tags[version] != tag
|
34
|
-
raise "Version #{version} already registered to tag #{versions_to_tags[version]}"
|
35
|
-
end
|
36
|
-
@versions_to_tags[version] = tag
|
37
|
-
end
|
38
18
|
|
39
|
-
|
40
|
-
versions_to_tags.clear
|
19
|
+
find_scenarios(:tags => :upgrade_scenario).map(&:target_version).uniq.sort
|
41
20
|
end
|
42
21
|
|
43
22
|
def current_target_version
|
@@ -57,25 +36,35 @@ module ForemanMaintain
|
|
57
36
|
|
58
37
|
def initialize(version, reporter, options = {})
|
59
38
|
super(reporter, [], options)
|
60
|
-
@tag = self.class.versions_to_tags[version]
|
61
|
-
raise "Unknown version #{version}" unless tag
|
62
39
|
@version = version
|
40
|
+
scenarios_present = find_scenarios(:tags => :upgrade_scenario).any?(&matching_version_test)
|
41
|
+
raise "Unknown version #{version}" unless scenarios_present
|
42
|
+
|
63
43
|
@scenario_cache = {}
|
64
44
|
self.phase = :pre_upgrade_checks
|
65
45
|
end
|
66
46
|
|
67
47
|
def scenario(phase)
|
68
48
|
return @scenario_cache[phase] if @scenario_cache.key?(phase)
|
69
|
-
|
70
|
-
|
49
|
+
|
50
|
+
condition = { :tags => [:upgrade_scenario, phase] }
|
51
|
+
matching_scenarios = find_scenarios(condition).select(&matching_version_test)
|
71
52
|
raise "Too many scenarios match #{condition.inspect}" if matching_scenarios.size > 1
|
53
|
+
|
72
54
|
@scenario_cache[phase] = matching_scenarios.first
|
73
55
|
end
|
74
56
|
|
57
|
+
def matching_version_test
|
58
|
+
proc do |scenario|
|
59
|
+
scenario.respond_to?(:target_version) && scenario.target_version == @version
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
75
63
|
def run
|
76
64
|
self.class.current_target_version = @version
|
77
65
|
PHASES.each do |phase|
|
78
66
|
return run_rollback if quit?
|
67
|
+
|
79
68
|
if skip?(phase)
|
80
69
|
skip_phase(phase)
|
81
70
|
else
|
@@ -127,6 +116,7 @@ module ForemanMaintain
|
|
127
116
|
# deserializes the state of the run from the storage
|
128
117
|
def load
|
129
118
|
return unless storage[:serialized]
|
119
|
+
|
130
120
|
load_from_hash(storage[:serialized])
|
131
121
|
end
|
132
122
|
|
@@ -134,6 +124,7 @@ module ForemanMaintain
|
|
134
124
|
with_non_empty_scenario(phase) do |scenario|
|
135
125
|
confirm_scenario(scenario)
|
136
126
|
return if quit?
|
127
|
+
|
137
128
|
self.phase = phase
|
138
129
|
run_scenario(scenario)
|
139
130
|
# if we started from the :pre_upgrade_checks, ensure to ask before
|
@@ -158,6 +149,7 @@ module ForemanMaintain
|
|
158
149
|
# rubocop:disable Metrics/MethodLength
|
159
150
|
def rollback_pre_migrations
|
160
151
|
raise "Unexpected phase #{phase}, expecting pre_migrations" unless phase == :pre_migrations
|
152
|
+
|
161
153
|
rollback_needed = scenario(:pre_migrations).steps.any? { |s| s.executed? && s.success? }
|
162
154
|
if rollback_needed
|
163
155
|
@quit = false
|
@@ -198,6 +190,7 @@ module ForemanMaintain
|
|
198
190
|
unless @scenario_cache.empty?
|
199
191
|
raise "Some scenarios are already initialized: #{@scenario_cache.keys}"
|
200
192
|
end
|
193
|
+
|
201
194
|
self.phase = hash[:phase]
|
202
195
|
hash[:scenarios].each do |key, scenario_hash|
|
203
196
|
@scenario_cache[key] = Scenario.new_from_hash(scenario_hash)
|
@@ -229,6 +222,7 @@ module ForemanMaintain
|
|
229
222
|
|
230
223
|
def phase=(phase)
|
231
224
|
raise "Unknown phase #{phase}" unless PHASES.include?(phase)
|
225
|
+
|
232
226
|
@phase = phase
|
233
227
|
end
|
234
228
|
end
|