foreman_maintain 1.0.12 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/definitions/features/capsule.rb +1 -1
- data/definitions/features/foreman_database.rb +7 -1
- data/definitions/features/installer.rb +7 -1
- data/definitions/features/katello.rb +1 -1
- data/definitions/features/satellite.rb +1 -1
- data/definitions/procedures/backup/config_files.rb +25 -10
- data/definitions/procedures/backup/metadata.rb +11 -7
- data/definitions/procedures/backup/offline/foreman_db.rb +30 -9
- data/definitions/procedures/maintenance_mode/disable_maintenance_mode.rb +2 -1
- data/definitions/procedures/maintenance_mode/enable_maintenance_mode.rb +1 -30
- data/definitions/procedures/packages/update.rb +3 -1
- data/definitions/procedures/pulp/remove.rb +49 -13
- data/definitions/procedures/restore/extract_files.rb +4 -0
- data/definitions/procedures/selinux/set_file_security.rb +3 -0
- data/definitions/scenarios/backup.rb +10 -0
- data/definitions/scenarios/packages.rb +2 -2
- data/definitions/scenarios/self_upgrade.rb +10 -67
- data/lib/foreman_maintain/cli/packages_command.rb +26 -7
- data/lib/foreman_maintain/cli/self_upgrade_command.rb +1 -7
- data/lib/foreman_maintain/concerns/base_database.rb +31 -3
- data/lib/foreman_maintain/concerns/downstream.rb +2 -3
- data/lib/foreman_maintain/concerns/firewall/maintenance_mode.rb +31 -0
- data/lib/foreman_maintain/concerns/os_facts.rb +26 -2
- data/lib/foreman_maintain/concerns/system_helpers.rb +19 -17
- data/lib/foreman_maintain/package_manager/apt.rb +71 -0
- data/lib/foreman_maintain/package_manager/yum.rb +19 -11
- data/lib/foreman_maintain/package_manager.rb +6 -4
- data/lib/foreman_maintain/repository_manager/el.rb +15 -4
- data/lib/foreman_maintain/repository_manager.rb +1 -1
- data/lib/foreman_maintain/utils/service/systemd.rb +8 -13
- data/lib/foreman_maintain/version.rb +1 -1
- data/lib/foreman_maintain.rb +1 -0
- metadata +4 -7
- data/bin/passenger-recycler +0 -89
- data/config/passenger-recycler.yaml +0 -38
- data/definitions/procedures/passenger_recycler.rb +0 -14
- data/extras/passenger-recycler.cron +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5223427d91fd37a6dda0c341fada111c6555378cca050db661e81e4807bac53
|
4
|
+
data.tar.gz: 0ccf33ffe89749016e9b943b9421427f456e524fcd8a1d2f44a0aa3a02c7af8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe155208da6aa978763d158e89f6552897a4d26e7aae09af6182c5d055988348176693050a5197f07203366083902bda7a76cb2d569298e52f7aa70723dc9ee0
|
7
|
+
data.tar.gz: c323b7a0c47767f86cfbc58b1d3257d0ce005f80ae9d73cdb908e98796db28e9d1044348bd78b35baef8bef714fbc8a59cc6925222db60bb80fe3b505594bb20
|
@@ -16,7 +16,13 @@ class Features::ForemanDatabase < ForemanMaintain::Feature
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def config_files
|
19
|
-
[postgresql_conf]
|
19
|
+
el? ? [postgresql_conf] : []
|
20
|
+
end
|
21
|
+
|
22
|
+
def config_dirs
|
23
|
+
# On Debian config files reside in /etc/postgresql/#{version}/main/
|
24
|
+
# There could be more than on config dir because of multiple versions
|
25
|
+
deb_postgresql_config_dirs
|
20
26
|
end
|
21
27
|
|
22
28
|
def services
|
@@ -102,7 +102,13 @@ class Features::Installer < ForemanMaintain::Feature
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def installer_arguments
|
105
|
-
installer_args = '
|
105
|
+
installer_args = ''
|
106
|
+
|
107
|
+
if feature(:foreman_proxy) &&
|
108
|
+
feature(:foreman_proxy).with_content?
|
109
|
+
installer_args += ' --disable-system-checks'
|
110
|
+
end
|
111
|
+
|
106
112
|
unless check_min_version('foreman', '2.1') || check_min_version('foreman-proxy', '2.1')
|
107
113
|
installer_args += ' --upgrade' if can_upgrade?
|
108
114
|
end
|
@@ -10,7 +10,7 @@ class Features::Satellite < ForemanMaintain::Feature
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def current_version
|
13
|
-
@current_version ||=
|
13
|
+
@current_version ||= package_version(package_name) || version_from_source
|
14
14
|
end
|
15
15
|
|
16
16
|
def package_name
|
@@ -45,10 +45,22 @@ module Procedures::Backup
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
|
-
# rubocop:enable Metrics/MethodLength
|
49
48
|
|
50
|
-
# rubocop:disable Metrics/AbcSize
|
51
49
|
def config_files
|
50
|
+
configs, exclude_configs = available_features_config
|
51
|
+
|
52
|
+
if feature(:foreman_proxy)
|
53
|
+
configs += foreman_proxy_configs
|
54
|
+
exclude_configs += foreman_proxy_exclude_configs
|
55
|
+
end
|
56
|
+
|
57
|
+
configs += config_dirs
|
58
|
+
configs.compact.select { |path| Dir.glob(path).any? }
|
59
|
+
exclude_configs.compact.select { |path| Dir.glob(path).any? }
|
60
|
+
[configs, exclude_configs]
|
61
|
+
end
|
62
|
+
|
63
|
+
def available_features_config
|
52
64
|
configs = []
|
53
65
|
exclude_configs = []
|
54
66
|
ForemanMaintain.available_features.each do |feature|
|
@@ -59,17 +71,20 @@ module Procedures::Backup
|
|
59
71
|
exclude_configs += feature.config_files_to_exclude
|
60
72
|
exclude_configs += feature.config_files_exclude_for_online if @online_backup
|
61
73
|
end
|
74
|
+
[configs, exclude_configs]
|
75
|
+
end
|
62
76
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
77
|
+
def foreman_proxy_configs
|
78
|
+
feature(:foreman_proxy).config_files(@proxy_features)
|
79
|
+
end
|
67
80
|
|
68
|
-
|
69
|
-
|
70
|
-
|
81
|
+
def foreman_proxy_exclude_configs
|
82
|
+
feature(:foreman_proxy).config_files_to_exclude(@proxy_features)
|
83
|
+
end
|
84
|
+
|
85
|
+
def config_dirs
|
86
|
+
debian_or_ubuntu? ? feature(:foreman_database).config_dirs : []
|
71
87
|
end
|
72
|
-
# rubocop:enable Metrics/AbcSize
|
73
88
|
|
74
89
|
private
|
75
90
|
|
@@ -17,7 +17,7 @@ module Procedures::Backup
|
|
17
17
|
metadata['os_version'] = release_info(spinner)
|
18
18
|
metadata['plugin_list'] = plugin_list(spinner) || []
|
19
19
|
metadata['proxy_features'] = proxy_feature_list(spinner) || []
|
20
|
-
metadata
|
20
|
+
installed_pkgs(metadata)
|
21
21
|
metadata['incremental'] = @incremental_dir || false
|
22
22
|
metadata['online'] = @online_backup
|
23
23
|
metadata['hostname'] = hostname
|
@@ -28,6 +28,15 @@ module Procedures::Backup
|
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
|
+
def installed_pkgs(metadata)
|
32
|
+
installed_pkgs = package_manager.list_installed_packages
|
33
|
+
if el?
|
34
|
+
metadata[:rpms] = installed_pkgs
|
35
|
+
else
|
36
|
+
metadata[:debs] = installed_pkgs
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
31
40
|
def save_metadata(metadata, spinner)
|
32
41
|
spinner.update('Saving metadata to metadata.yml')
|
33
42
|
File.open(File.join(@backup_dir, 'metadata.yml'), 'w') do |metadata_file|
|
@@ -37,12 +46,7 @@ module Procedures::Backup
|
|
37
46
|
|
38
47
|
def release_info(spinner)
|
39
48
|
spinner.update('Collecting system release info')
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
def rpms(spinner)
|
44
|
-
spinner.update('Collecting installed RPMs')
|
45
|
-
execute!('rpm -qa').split("\n")
|
49
|
+
"#{os_name} #{os_version}"
|
46
50
|
end
|
47
51
|
|
48
52
|
def plugin_list(spinner)
|
@@ -20,7 +20,7 @@ module Procedures::Backup
|
|
20
20
|
local_backup
|
21
21
|
end
|
22
22
|
else
|
23
|
-
puts "Backup of #{
|
23
|
+
puts "Backup of #{pg_data_dirs.join(',')} is not supported for remote databases." \
|
24
24
|
' Doing postgres dump instead...'
|
25
25
|
with_spinner('Getting Foreman DB dump') do
|
26
26
|
feature(:foreman_database).dump_db(File.join(@backup_dir, 'foreman.dump'))
|
@@ -31,22 +31,43 @@ module Procedures::Backup
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def local_backup
|
34
|
-
with_spinner("Collecting data from #{
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
:volume_size => @tar_volume_size,
|
39
|
-
:data_dir => pg_data_dir
|
40
|
-
)
|
34
|
+
with_spinner("Collecting data from #{pg_data_dirs.join(',')}") do
|
35
|
+
pg_data_dirs.each_with_index do |pg_dir, index|
|
36
|
+
do_backup(pg_dir, index == 0 ? 'create' : 'append')
|
37
|
+
end
|
41
38
|
end
|
42
39
|
end
|
43
40
|
|
41
|
+
def do_backup(pg_dir, cmd)
|
42
|
+
feature(:foreman_database).backup_local(
|
43
|
+
pg_backup_file,
|
44
|
+
:listed_incremental => File.join(@backup_dir, '.postgres.snar'),
|
45
|
+
:volume_size => @tar_volume_size,
|
46
|
+
:data_dir => pg_dir,
|
47
|
+
:command => cmd
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
44
51
|
def pg_backup_file
|
45
52
|
File.join(@backup_dir, 'pgsql_data.tar')
|
46
53
|
end
|
47
54
|
|
48
|
-
def
|
55
|
+
def pg_data_dirs
|
56
|
+
el? ? [pg_data_dir_el] : pg_data_dirs_deb
|
57
|
+
end
|
58
|
+
|
59
|
+
def pg_data_dirs_deb
|
60
|
+
# The Debian based OSes support multiple installations of Postgresql
|
61
|
+
# There could be situations where Foreman db is either of these versions
|
62
|
+
# To be sure we backup the system correctly without missing anything
|
63
|
+
# we backup all of the Postgresql dirs
|
64
|
+
# Yet to implement the snapshot backup!
|
65
|
+
feature(:foreman_database).data_dir
|
66
|
+
end
|
67
|
+
|
68
|
+
def pg_data_dir_el
|
49
69
|
return feature(:foreman_database).data_dir if @mount_dir.nil?
|
70
|
+
|
50
71
|
mount_point = File.join(@mount_dir, 'pgsql')
|
51
72
|
dir = feature(:foreman_database).find_base_directory(mount_point)
|
52
73
|
fail!("Snapshot of Foreman DB was not found mounted in #{mount_point}") if dir.nil?
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Procedures::MaintenanceMode
|
2
2
|
class DisableMaintenanceMode < ForemanMaintain::Procedure
|
3
|
+
include ForemanMaintain::Concerns::Firewall::MaintenanceMode
|
3
4
|
metadata do
|
4
5
|
label :disable_maintenance_mode
|
5
6
|
description 'Remove maintenance mode table/chain from nftables/iptables'
|
@@ -11,7 +12,7 @@ module Procedures::MaintenanceMode
|
|
11
12
|
if feature(:instance).firewall
|
12
13
|
feature(:instance).firewall.disable_maintenance_mode
|
13
14
|
else
|
14
|
-
|
15
|
+
notify_and_ask_to_install_firewall_utility
|
15
16
|
end
|
16
17
|
end
|
17
18
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module Procedures::MaintenanceMode
|
2
2
|
class EnableMaintenanceMode < ForemanMaintain::Procedure
|
3
|
+
include ForemanMaintain::Concerns::Firewall::MaintenanceMode
|
3
4
|
metadata do
|
4
5
|
label :enable_maintenance_mode
|
5
6
|
description 'Add maintenance_mode tables/chain to nftables/iptables'
|
@@ -14,35 +15,5 @@ module Procedures::MaintenanceMode
|
|
14
15
|
notify_and_ask_to_install_firewall_utility
|
15
16
|
end
|
16
17
|
end
|
17
|
-
|
18
|
-
def notify_and_ask_to_install_firewall_utility
|
19
|
-
puts 'Unable to find nftables or iptables!'
|
20
|
-
question, pkg = question_and_pkg_name
|
21
|
-
answer = ask_decision(question, actions_msg: 'y(yes), q(quit)')
|
22
|
-
if answer == :yes
|
23
|
-
packages_action(:install, pkg)
|
24
|
-
feature(:instance).firewall.enable_maintenance_mode
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def can_install_nft?
|
29
|
-
nft_kernel_version = Gem::Version.new('3.13')
|
30
|
-
installed_kernel_version = Gem::Version.new(execute!('uname -r').split('-').first)
|
31
|
-
installed_kernel_version >= nft_kernel_version
|
32
|
-
end
|
33
|
-
|
34
|
-
def question_and_pkg_name
|
35
|
-
question = 'Do you want to install missing netfilter utility '
|
36
|
-
pkg_to_install = []
|
37
|
-
if can_install_nft?
|
38
|
-
question << 'nftables?'
|
39
|
-
pkg_to_install << 'nftables'
|
40
|
-
else
|
41
|
-
question << 'iptables?'
|
42
|
-
pkg_to_install << 'iptables'
|
43
|
-
end
|
44
|
-
question << "\nand start maintenance mode?"
|
45
|
-
[question, pkg_to_install]
|
46
|
-
end
|
47
18
|
end
|
48
19
|
end
|
@@ -6,12 +6,14 @@ module Procedures::Packages
|
|
6
6
|
param :force, 'Do not skip if package is installed', :flag => true, :default => false
|
7
7
|
param :warn_on_errors, 'Do not interrupt scenario on failure',
|
8
8
|
:flag => true, :default => false
|
9
|
+
param :yum_options, 'Extra yum options if any', :array => true, :default => []
|
9
10
|
end
|
10
11
|
|
11
12
|
def run
|
12
13
|
assumeyes_val = @assumeyes.nil? ? assumeyes? : @assumeyes
|
13
14
|
package_manager.clean_cache(:assumeyes => assumeyes_val)
|
14
|
-
|
15
|
+
opts = { :assumeyes => assumeyes_val, :yum_options => @yum_options }
|
16
|
+
packages_action(:update, @packages, opts)
|
15
17
|
rescue ForemanMaintain::Error::ExecutionError => e
|
16
18
|
if @warn_on_errors
|
17
19
|
set_status(:warning, e.message)
|
@@ -24,7 +24,15 @@ module Procedures::Pulp
|
|
24
24
|
'/var/lib/pulp/uploads',
|
25
25
|
'/var/lib/mongodb/',
|
26
26
|
'/var/cache/pulp'
|
27
|
-
]
|
27
|
+
].select { |dir| File.directory?(dir) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def pulp_data_dirs_mountpoints
|
31
|
+
pulp_data_dirs.select { |d| Pathname(d).mountpoint? }
|
32
|
+
end
|
33
|
+
|
34
|
+
def deletable_pulp_dirs
|
35
|
+
@deletable_pulp_dirs ||= pulp_data_dirs - pulp_data_dirs_mountpoints
|
28
36
|
end
|
29
37
|
|
30
38
|
# rubocop:disable Metrics/MethodLength
|
@@ -53,11 +61,12 @@ module Procedures::Pulp
|
|
53
61
|
@installed_pulp_packages
|
54
62
|
end
|
55
63
|
|
56
|
-
def data_dir_removal_cmds
|
57
|
-
|
64
|
+
def data_dir_removal_cmds(pulp_dirs)
|
65
|
+
pulp_dirs.map { |dir| "rm -rf #{dir}" }
|
58
66
|
end
|
59
67
|
|
60
|
-
def ask_to_proceed
|
68
|
+
def ask_to_proceed
|
69
|
+
rm_cmds = data_dir_removal_cmds(pulp_data_dirs)
|
61
70
|
question = "\nWARNING: All pulp2 packages will be removed with the following commands:\n"
|
62
71
|
question += "\n# rpm -e #{pulp_packages.join(' ')}" if pulp_packages.any?
|
63
72
|
question += "\n# yum remove rh-mongodb34-*"
|
@@ -70,11 +79,9 @@ module Procedures::Pulp
|
|
70
79
|
end
|
71
80
|
|
72
81
|
def run
|
73
|
-
rm_cmds = data_dir_removal_cmds
|
74
|
-
|
75
82
|
assumeyes_val = @assumeyes.nil? ? assumeyes? : @assumeyes
|
76
83
|
|
77
|
-
ask_to_proceed
|
84
|
+
ask_to_proceed unless assumeyes_val
|
78
85
|
|
79
86
|
remove_pulp if pulp_packages.any?
|
80
87
|
|
@@ -86,7 +93,7 @@ module Procedures::Pulp
|
|
86
93
|
|
87
94
|
drop_migrations
|
88
95
|
|
89
|
-
delete_pulp_data
|
96
|
+
delete_pulp_data
|
90
97
|
|
91
98
|
restart_pulpcore_services
|
92
99
|
end
|
@@ -163,12 +170,41 @@ module Procedures::Pulp
|
|
163
170
|
end
|
164
171
|
# rubocop:enable Metrics/BlockLength
|
165
172
|
|
166
|
-
def delete_pulp_data
|
167
|
-
|
168
|
-
|
169
|
-
|
173
|
+
def delete_pulp_data
|
174
|
+
non_mountpoints = data_dir_removal_cmds(deletable_pulp_dirs)
|
175
|
+
mountpoints = pulp_data_dirs_mountpoints
|
176
|
+
with_spinner('') do |spinner|
|
177
|
+
if non_mountpoints.any?
|
178
|
+
spinner.update('Deleting pulp2 data directories.')
|
179
|
+
non_mountpoints.each do |cmd|
|
180
|
+
execute!(cmd)
|
181
|
+
end
|
182
|
+
msg_for_del_non_mountpoints(mountpoints, spinner)
|
183
|
+
end
|
184
|
+
if mountpoints.any?
|
185
|
+
msg_for_del_mountpoints(mountpoints, spinner)
|
170
186
|
end
|
171
|
-
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def msg_for_del_non_mountpoints(mountpoints, spinner)
|
191
|
+
if mountpoints.empty?
|
192
|
+
spinner.update('Done deleting all pulp2 data directories.')
|
193
|
+
else
|
194
|
+
spinner.update("Deleted: #{deletable_pulp_dirs.join("\n")}")
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def msg_for_del_mountpoints(mountpoints, spinner)
|
199
|
+
_, cmd_name = ForemanMaintain.pkg_and_cmd_name
|
200
|
+
if mountpoints.count > 1
|
201
|
+
spinner.update("The directories #{mountpoints.join(',')} are individual mountpoints.")
|
202
|
+
puts "\nThe #{cmd_name} won't delete these directories.\n"\
|
203
|
+
'You need to remove content and these directories on your own.'
|
204
|
+
else
|
205
|
+
spinner.update("The directory #{mountpoints.join(',')} is individual mountpoint.")
|
206
|
+
puts "\nThe #{cmd_name} won't delete the directory.\n"\
|
207
|
+
'You need to remove content and the directory on your own.'
|
172
208
|
end
|
173
209
|
end
|
174
210
|
|
@@ -71,6 +71,10 @@ module Procedures::Restore
|
|
71
71
|
:transform => any_database.restore_transform
|
72
72
|
)
|
73
73
|
feature(:tar).run(pgsql_data_tar)
|
74
|
+
del_data_dir_param if el?
|
75
|
+
end
|
76
|
+
|
77
|
+
def del_data_dir_param
|
74
78
|
# workaround for https://tickets.puppetlabs.com/browse/MODULES-11160
|
75
79
|
execute("sed -i '/data_directory/d' #{any_database.postgresql_conf}")
|
76
80
|
end
|
@@ -19,6 +19,7 @@ module ForemanMaintain::Scenarios
|
|
19
19
|
param :tar_volume_size, 'Size of tar volume (indicates splitting)'
|
20
20
|
end
|
21
21
|
|
22
|
+
# rubocop:disable Metrics/MethodLength
|
22
23
|
def compose
|
23
24
|
check_valid_startegy
|
24
25
|
safety_confirmation
|
@@ -33,10 +34,19 @@ module ForemanMaintain::Scenarios
|
|
33
34
|
when :offline
|
34
35
|
add_offline_backup_steps
|
35
36
|
when :snapshot
|
37
|
+
deb_snapshot_msg
|
36
38
|
add_snapshot_backup_steps
|
37
39
|
end
|
38
40
|
add_step_with_context(Procedures::Backup::CompressData)
|
39
41
|
end
|
42
|
+
# rubocop:enable Metrics/MethodLength
|
43
|
+
|
44
|
+
def deb_snapshot_msg
|
45
|
+
if debian_or_ubuntu?
|
46
|
+
puts 'The snapshot backup is not yet available for Debian based OSes!'
|
47
|
+
exit 0
|
48
|
+
end
|
49
|
+
end
|
40
50
|
|
41
51
|
# rubocop:disable Metrics/MethodLength
|
42
52
|
def set_context_mapping
|
@@ -107,9 +107,9 @@ module ForemanMaintain::Scenarios
|
|
107
107
|
else
|
108
108
|
add_steps_with_context(
|
109
109
|
Procedures::Packages::UpdateAllConfirmation,
|
110
|
-
Procedures::Packages::InstallerConfirmation
|
111
|
-
Procedures::Packages::UnlockVersions
|
110
|
+
Procedures::Packages::InstallerConfirmation
|
112
111
|
)
|
112
|
+
add_step_with_context(Procedures::Packages::UnlockVersions)
|
113
113
|
add_step_with_context(Procedures::Packages::Update,
|
114
114
|
:force => true, :warn_on_errors => true)
|
115
115
|
add_step_with_context(Procedures::Installer::Upgrade)
|
@@ -1,18 +1,6 @@
|
|
1
1
|
module ForemanMaintain::Scenarios
|
2
2
|
class SelfUpgradeBase < ForemanMaintain::Scenario
|
3
3
|
include ForemanMaintain::Concerns::Downstream
|
4
|
-
def enabled_system_repos_id
|
5
|
-
repository_manager.enabled_repos.keys
|
6
|
-
end
|
7
|
-
|
8
|
-
def enable_repos(repo_ids = stored_enabled_repos_ids)
|
9
|
-
add_step(Procedures::Repositories::Enable.new(repos: repo_ids))
|
10
|
-
end
|
11
|
-
|
12
|
-
def disable_repos(repo_ids = stored_enabled_repos_ids)
|
13
|
-
add_step(Procedures::Repositories::Disable.new(repos: repo_ids))
|
14
|
-
end
|
15
|
-
|
16
4
|
def target_version
|
17
5
|
current_full_version = feature(:instance).downstream.current_version
|
18
6
|
@target_version ||= current_full_version.bump
|
@@ -44,36 +32,6 @@ module ForemanMaintain::Scenarios
|
|
44
32
|
end
|
45
33
|
end
|
46
34
|
|
47
|
-
def maintenance_repo_version
|
48
|
-
return '6' if current_version == '6.10'
|
49
|
-
|
50
|
-
current_version
|
51
|
-
end
|
52
|
-
|
53
|
-
def stored_enabled_repos_ids
|
54
|
-
@stored_enabled_repos_ids ||= begin
|
55
|
-
path = File.expand_path('enabled_repos.yml', ForemanMaintain.config.backup_dir)
|
56
|
-
@stored_enabled_repos_ids = File.file?(path) ? YAML.load(File.read(path)) : []
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def all_maintenance_repos
|
61
|
-
repo_regex = if el7?
|
62
|
-
/rhel-\d-server-satellite-maintenance-\d.\d-rpms/
|
63
|
-
else
|
64
|
-
/satellite-maintenance-\d.\d-for-rhel-\d-x86_64-rpms/
|
65
|
-
end
|
66
|
-
stored_enabled_repos_ids.select { |id| !id.match(repo_regex).nil? }
|
67
|
-
end
|
68
|
-
|
69
|
-
def repos_ids_to_reenable
|
70
|
-
repos_ids_to_reenable = stored_enabled_repos_ids - all_maintenance_repos
|
71
|
-
if use_rhsm?
|
72
|
-
repos_ids_to_reenable << maintenance_repo(maintenance_repo_version)
|
73
|
-
end
|
74
|
-
repos_ids_to_reenable
|
75
|
-
end
|
76
|
-
|
77
35
|
def use_rhsm?
|
78
36
|
return false if maintenance_repo_label
|
79
37
|
|
@@ -85,7 +43,11 @@ module ForemanMaintain::Scenarios
|
|
85
43
|
end
|
86
44
|
|
87
45
|
def req_repos_to_update_pkgs
|
88
|
-
|
46
|
+
if use_rhsm?
|
47
|
+
main_rh_repos + [maintenance_repo_id(target_version)]
|
48
|
+
else
|
49
|
+
[maintenance_repo_id(target_version)]
|
50
|
+
end
|
89
51
|
end
|
90
52
|
end
|
91
53
|
|
@@ -100,30 +62,11 @@ module ForemanMaintain::Scenarios
|
|
100
62
|
def compose
|
101
63
|
if check_min_version('foreman', '2.5') || check_min_version('foreman-proxy', '2.5')
|
102
64
|
pkgs_to_update = %w[satellite-maintain rubygem-foreman_maintain]
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
disable_repos('*')
|
109
|
-
enable_repos(repos_ids_to_reenable)
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
class SelfUpgradeRescue < SelfUpgradeBase
|
115
|
-
metadata do
|
116
|
-
label :rescue_self_upgrade
|
117
|
-
description 'Disables all version specific maintenance repositories and,'\
|
118
|
-
"\nenables the repositories which were configured prior to self upgrade"
|
119
|
-
manual_detection
|
120
|
-
run_strategy :fail_slow
|
121
|
-
end
|
122
|
-
|
123
|
-
def compose
|
124
|
-
if check_min_version('foreman', '2.5') || check_min_version('foreman-proxy', '2.5')
|
125
|
-
disable_repos('*')
|
126
|
-
enable_repos(repos_ids_to_reenable)
|
65
|
+
yum_options = req_repos_to_update_pkgs.map do |id|
|
66
|
+
"--enablerepo=#{id}"
|
67
|
+
end
|
68
|
+
add_step(Procedures::Packages::Update.new(packages: pkgs_to_update, assumeyes: true,
|
69
|
+
yum_options: yum_options))
|
127
70
|
end
|
128
71
|
end
|
129
72
|
end
|
@@ -2,23 +2,32 @@ module ForemanMaintain
|
|
2
2
|
module Cli
|
3
3
|
class PackagesCommand < Base
|
4
4
|
subcommand 'lock', 'Prevent packages from automatic update' do
|
5
|
+
# This command is not implemented for Debian based operating systems
|
5
6
|
interactive_option(['assumeyes'])
|
6
7
|
def execute
|
7
|
-
|
8
|
+
run_scenario_or_rescue do
|
9
|
+
run_scenarios_and_exit(Scenarios::Packages::Lock.new)
|
10
|
+
end
|
8
11
|
end
|
9
12
|
end
|
10
13
|
|
11
14
|
subcommand 'unlock', 'Enable packages for automatic update' do
|
15
|
+
# This command is not implemented for Debian based operating systems
|
12
16
|
interactive_option(['assumeyes'])
|
13
17
|
def execute
|
14
|
-
|
18
|
+
run_scenario_or_rescue do
|
19
|
+
run_scenarios_and_exit(Scenarios::Packages::Unlock.new)
|
20
|
+
end
|
15
21
|
end
|
16
22
|
end
|
17
23
|
|
18
24
|
subcommand 'status', 'Check if packages are protected against update' do
|
25
|
+
# This command is not implemented for Debian based operating systems
|
19
26
|
interactive_option(['assumeyes'])
|
20
27
|
def execute
|
21
|
-
|
28
|
+
run_scenario_or_rescue do
|
29
|
+
run_scenarios_and_exit(Scenarios::Packages::Status.new)
|
30
|
+
end
|
22
31
|
end
|
23
32
|
end
|
24
33
|
|
@@ -58,14 +67,24 @@ module ForemanMaintain
|
|
58
67
|
end
|
59
68
|
|
60
69
|
subcommand 'is-locked', 'Check if update of packages is allowed' do
|
70
|
+
# This command is not implemented for Debian based operating systems
|
61
71
|
interactive_option(['assumeyes'])
|
62
72
|
def execute
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
73
|
+
run_scenario_or_rescue do
|
74
|
+
locked = ForemanMaintain.package_manager.versions_locked?
|
75
|
+
puts "Packages are#{locked ? '' : ' not'} locked"
|
76
|
+
exit_code = locked ? 0 : 1
|
77
|
+
exit exit_code
|
78
|
+
end
|
67
79
|
end
|
68
80
|
end
|
81
|
+
|
82
|
+
def run_scenario_or_rescue
|
83
|
+
yield
|
84
|
+
rescue NotImplementedError
|
85
|
+
puts 'Command is not implemented for Debian based operating systems!'
|
86
|
+
exit 0
|
87
|
+
end
|
69
88
|
end
|
70
89
|
end
|
71
90
|
end
|
@@ -5,7 +5,7 @@ module ForemanMaintain
|
|
5
5
|
'Repository label from which packages should be updated.'\
|
6
6
|
'This can be used when standard CDN repositories are unavailable.'
|
7
7
|
def execute
|
8
|
-
run_scenario(upgrade_scenario
|
8
|
+
run_scenario(upgrade_scenario)
|
9
9
|
end
|
10
10
|
|
11
11
|
def upgrade_scenario
|
@@ -13,12 +13,6 @@ module ForemanMaintain
|
|
13
13
|
maintenance_repo_label: maintenance_repo_label
|
14
14
|
)
|
15
15
|
end
|
16
|
-
|
17
|
-
def upgrade_rescue_scenario
|
18
|
-
Scenarios::SelfUpgradeRescue.new(
|
19
|
-
maintenance_repo_label: maintenance_repo_label
|
20
|
-
)
|
21
|
-
end
|
22
16
|
end
|
23
17
|
end
|
24
18
|
end
|