foreman_maintain 1.0.11 → 1.1.2

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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/definitions/features/capsule.rb +1 -1
  3. data/definitions/features/foreman_database.rb +7 -1
  4. data/definitions/features/installer.rb +7 -1
  5. data/definitions/features/katello.rb +1 -1
  6. data/definitions/features/satellite.rb +1 -1
  7. data/definitions/procedures/backup/config_files.rb +25 -10
  8. data/definitions/procedures/backup/metadata.rb +11 -7
  9. data/definitions/procedures/backup/offline/foreman_db.rb +30 -9
  10. data/definitions/procedures/installer/run_for_6_11.rb +52 -0
  11. data/definitions/procedures/maintenance_mode/disable_maintenance_mode.rb +2 -1
  12. data/definitions/procedures/maintenance_mode/enable_maintenance_mode.rb +1 -30
  13. data/definitions/procedures/packages/update.rb +3 -1
  14. data/definitions/procedures/pulp/remove.rb +49 -13
  15. data/definitions/procedures/restore/extract_files.rb +4 -0
  16. data/definitions/procedures/selinux/set_file_security.rb +3 -0
  17. data/definitions/scenarios/backup.rb +10 -0
  18. data/definitions/scenarios/packages.rb +2 -2
  19. data/definitions/scenarios/puppet.rb +3 -1
  20. data/definitions/scenarios/self_upgrade.rb +10 -67
  21. data/definitions/scenarios/upgrade_to_satellite_6_11.rb +1 -1
  22. data/lib/foreman_maintain/cli/packages_command.rb +26 -7
  23. data/lib/foreman_maintain/cli/self_upgrade_command.rb +1 -7
  24. data/lib/foreman_maintain/concerns/base_database.rb +31 -3
  25. data/lib/foreman_maintain/concerns/downstream.rb +2 -3
  26. data/lib/foreman_maintain/concerns/firewall/maintenance_mode.rb +31 -0
  27. data/lib/foreman_maintain/concerns/os_facts.rb +26 -2
  28. data/lib/foreman_maintain/concerns/system_helpers.rb +16 -17
  29. data/lib/foreman_maintain/package_manager/apt.rb +71 -0
  30. data/lib/foreman_maintain/package_manager/yum.rb +19 -11
  31. data/lib/foreman_maintain/package_manager.rb +6 -4
  32. data/lib/foreman_maintain/repository_manager/el.rb +15 -4
  33. data/lib/foreman_maintain/repository_manager.rb +1 -1
  34. data/lib/foreman_maintain/utils/service/systemd.rb +8 -13
  35. data/lib/foreman_maintain/version.rb +1 -1
  36. data/lib/foreman_maintain.rb +1 -0
  37. metadata +5 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27d440b036591f10b20bfde591adfe573d8d48602c40a76791e9fe5fde2eb0a6
4
- data.tar.gz: ed71b8df8d073dc8c0607a8b2fdb95926a659033ce5f97b6e01d24a3f1d0916d
3
+ metadata.gz: a54e65aa9144d233ab256305556eebb5467cfd5c4fd9aa99b7971a13fdd81bac
4
+ data.tar.gz: ce6c5012139cc01bb4dee7f7cdb30a569ce3f05399d14d81d1c1cbf835588b31
5
5
  SHA512:
6
- metadata.gz: 0e5b7682a945427963ce4931e2980e49b29633e53f6f3d6172e482a6eb6fe11c84b5f600f00195e6bfd66ba083e359ee811ab75196ffc9af6e096d36f52d0b7d
7
- data.tar.gz: 3d4f6b27203254baeafb5f077569b4062c8ab96ee383595f3dd3dbc6acdb0849a68103a959e4306c3e05986c9cf9a3cc5b134726067bdb12e4c02553025f0978
6
+ metadata.gz: b94662b70f86ed91889688a3288dbe67d44ec46c9b1d3830f5a9687b0293500048ffd2df86162964e417a0ffa1514d78a43a0c4a1f7168848986bb92abe9828e
7
+ data.tar.gz: 0f2351eddc6236e7be70c44bc94e0ac4ae24b19b8f21dcf9d0a726a8897c4bea34bcb5bd5562827d1efb3400c421e2807288d56d1f5a03d5685ab2c402aa21b7
@@ -12,7 +12,7 @@ class Features::Capsule < ForemanMaintain::Feature
12
12
  end
13
13
 
14
14
  def current_version
15
- @current_version ||= rpm_version(package_name)
15
+ @current_version ||= package_version(package_name)
16
16
  end
17
17
 
18
18
  def package_name
@@ -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 = ' --disable-system-checks'
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
@@ -12,7 +12,7 @@ class Features::Katello < ForemanMaintain::Feature
12
12
  end
13
13
 
14
14
  def current_version
15
- @current_version ||= rpm_version('katello')
15
+ @current_version ||= package_version('katello')
16
16
  end
17
17
 
18
18
  def services
@@ -10,7 +10,7 @@ class Features::Satellite < ForemanMaintain::Feature
10
10
  end
11
11
 
12
12
  def current_version
13
- @current_version ||= rpm_version(package_name) || version_from_source
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
- if feature(:foreman_proxy)
64
- configs += feature(:foreman_proxy).config_files(@proxy_features)
65
- exclude_configs += feature(:foreman_proxy).config_files_to_exclude(@proxy_features)
66
- end
77
+ def foreman_proxy_configs
78
+ feature(:foreman_proxy).config_files(@proxy_features)
79
+ end
67
80
 
68
- configs.compact.select { |path| Dir.glob(path).any? }
69
- exclude_configs.compact.select { |path| Dir.glob(path).any? }
70
- [configs, exclude_configs]
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['rpms'] = rpms(spinner)
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
- execute!('cat /etc/redhat-release').chomp
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 #{pg_data_dir} is not supported for remote databases." \
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 #{pg_data_dir}") do
35
- feature(:foreman_database).backup_local(
36
- pg_backup_file,
37
- :listed_incremental => File.join(@backup_dir, '.postgres.snar'),
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 pg_data_dir
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?
@@ -0,0 +1,52 @@
1
+ module Procedures::Installer
2
+ class RunFor6_11 < ForemanMaintain::Procedure
3
+ metadata do
4
+ description 'Run installer with Candlepin SSL CA'\
5
+ ' when using external database with SSL'
6
+ param :assumeyes, 'Do not ask for confirmation'
7
+ manual_detection
8
+ end
9
+
10
+ def run
11
+ if extdb_and_ssl?
12
+ run_installer_with_extra_option
13
+ else
14
+ run_installer
15
+ end
16
+ end
17
+
18
+ def ext_db?
19
+ !feature(:foreman_database).local?
20
+ end
21
+
22
+ def installer_answers
23
+ @installer_answers ||= feature(:installer).answers
24
+ end
25
+
26
+ def server_db_with_ssl?
27
+ installer_answers.fetch('katello')['candlepin_db_ssl']
28
+ end
29
+
30
+ def extdb_and_ssl?
31
+ ext_db? && server_db_with_ssl?
32
+ end
33
+
34
+ def run_installer_with_extra_option
35
+ ssl_ca_path = installer_answers.fetch('foreman')['db_root_cert']
36
+ spinner_msg = "Running installer with --katello-candlepin-db-ssl-ca #{ssl_ca_path} argument!"
37
+ with_spinner(spinner_msg) do
38
+ installer_args = feature(:installer).installer_arguments
39
+ new_ssl_arg = " --katello-candlepin-db-ssl-ca #{ssl_ca_path}"
40
+ installer_args << new_ssl_arg
41
+ feature(:installer).run(installer_args)
42
+ end
43
+ end
44
+
45
+ def run_installer
46
+ with_spinner('Executing installer') do
47
+ assumeyes_val = @assumeyes.nil? ? assumeyes? : @assumeyes
48
+ feature(:installer).upgrade(:interactive => !assumeyes_val)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -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
- warn! 'Unable to find nftables or iptables'
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
- packages_action(:update, @packages, :assumeyes => assumeyes_val)
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
- pulp_data_dirs.select { |dir| File.directory?(dir) }.map { |dir| "rm -rf #{dir}" }
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(rm_cmds)
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(rm_cmds) unless assumeyes_val
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(rm_cmds) if rm_cmds.any?
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(rm_cmds)
167
- with_spinner('Deleting pulp2 data directories') do |spinner|
168
- rm_cmds.each do |cmd|
169
- execute!(cmd)
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
- spinner.update('Done deleting pulp2 data directories')
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
@@ -7,6 +7,9 @@ module Procedures::Selinux
7
7
  'Is the backup incremental?',
8
8
  :required => true
9
9
  manual_detection
10
+ confine do
11
+ File.directory?('/sys/fs/selinux')
12
+ end
10
13
  end
11
14
 
12
15
  def run
@@ -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)
@@ -15,7 +15,9 @@ module ForemanMaintain::Scenarios
15
15
  add_step(Procedures::Puppet::RemovePuppet)
16
16
  add_step(Procedures::Puppet::RemovePuppetData) if context.get(:remove_data)
17
17
  add_step(Procedures::Service::Restart)
18
- add_step(Procedures::Foreman::ApipieCache)
18
+ if server?
19
+ add_step(Procedures::Foreman::ApipieCache)
20
+ end
19
21
  end
20
22
  end
21
23
  end
@@ -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
- main_rh_repos + [maintenance_repo_id(target_version)]
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
- add_step(Procedures::Repositories::BackupEnabledRepos.new)
104
- disable_repos
105
- add_step(Procedures::Repositories::Enable.new(repos: req_repos_to_update_pkgs,
106
- use_rhsm: use_rhsm?))
107
- add_step(Procedures::Packages::Update.new(packages: pkgs_to_update, assumeyes: true))
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
@@ -61,7 +61,7 @@ module Scenarios::Satellite_6_11
61
61
  add_step(Procedures::Repositories::Setup.new(:version => '6.11'))
62
62
  add_step(Procedures::Packages::UnlockVersions.new)
63
63
  add_step(Procedures::Packages::Update.new(:assumeyes => true))
64
- add_step_with_context(Procedures::Installer::Upgrade)
64
+ add_step_with_context(Procedures::Installer::RunFor6_11)
65
65
  add_step(Procedures::Installer::UpgradeRakeTask)
66
66
  end
67
67
  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
- run_scenarios_and_exit(Scenarios::Packages::Lock.new)
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
- run_scenarios_and_exit(Scenarios::Packages::Unlock.new)
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
- run_scenarios_and_exit(Scenarios::Packages::Status.new)
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
- locked = ForemanMaintain.package_manager.versions_locked?
64
- puts "Packages are#{locked ? '' : ' not'} locked"
65
- exit_code = locked ? 0 : 1
66
- exit exit_code
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, upgrade_rescue_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
@@ -4,13 +4,39 @@ module ForemanMaintain
4
4
  def data_dir
5
5
  if el7? && package_manager.installed?('rh-postgresql12-postgresql-server-syspaths')
6
6
  '/var/opt/rh/rh-postgresql12/lib/pgsql/data/'
7
+ elsif debian_or_ubuntu?
8
+ deb_postgresql_data_dir
7
9
  else
8
10
  '/var/lib/pgsql/data/'
9
11
  end
10
12
  end
11
13
 
14
+ def deb_postgresql_data_dir
15
+ deb_postgresql_versions.map do |ver|
16
+ "/var/lib/postgresql/#{ver}/main/"
17
+ end
18
+ end
19
+
20
+ def deb_postgresql_versions
21
+ installed_pkgs = package_manager.list_installed_packages('${binary:Package}\n')
22
+ @deb_postgresql_versions ||= installed_pkgs.grep(/^postgresql-\d+$/).map do |name|
23
+ name.split('-').last
24
+ end
25
+ @deb_postgresql_versions
26
+ end
27
+
12
28
  def postgresql_conf
13
- "#{data_dir}/postgresql.conf"
29
+ return "#{data_dir}/postgresql.conf" if el?
30
+
31
+ deb_postgresql_config_dirs.map do |conf_dir|
32
+ "#{conf_dir}postgresql.conf"
33
+ end
34
+ end
35
+
36
+ def deb_postgresql_config_dirs
37
+ deb_postgresql_versions.map do |ver|
38
+ "/etc/postgresql/#{ver}/main/"
39
+ end
14
40
  end
15
41
 
16
42
  def restore_transform
@@ -89,11 +115,13 @@ module ForemanMaintain
89
115
 
90
116
  def backup_local(backup_file, extra_tar_options = {})
91
117
  dir = extra_tar_options.fetch(:data_dir, data_dir)
118
+ command = extra_tar_options.fetch(:command, 'create')
119
+
92
120
  FileUtils.cd(dir) do
93
121
  tar_options = {
94
122
  :archive => backup_file,
95
- :command => 'create',
96
- :transform => "s,^,#{data_dir[1..-1]},S",
123
+ :command => command,
124
+ :transform => "s,^,#{dir[1..-1]},S",
97
125
  :files => '*'
98
126
  }.merge(extra_tar_options)
99
127
  feature(:tar).run(tar_options)
@@ -66,7 +66,8 @@ module ForemanMaintain
66
66
  server_version_full = "#{server_version.major}.#{server_version.minor}"
67
67
  rh_repos.concat(product_specific_repos(server_version_full))
68
68
  if server_version > version('6.3')
69
- rh_repos << ansible_repo(server_version)
69
+ ansible_repo = ansible_repo(server_version)
70
+ rh_repos << ansible_repo if ansible_repo
70
71
  end
71
72
 
72
73
  rh_repos
@@ -83,8 +84,6 @@ module ForemanMaintain
83
84
 
84
85
  if el7?
85
86
  "rhel-#{el_major_version}-server-ansible-#{ansible_version}-rpms"
86
- else
87
- "ansible-#{ansible_version}-for-rhel-#{el_major_version}-x86_64-rpms"
88
87
  end
89
88
  end
90
89
 
@@ -0,0 +1,31 @@
1
+ module ForemanMaintain
2
+ module Concerns
3
+ module Firewall
4
+ module MaintenanceMode
5
+ def notify_and_ask_to_install_firewall_utility
6
+ puts 'Unable to find nftables or iptables!'
7
+ question, pkg = question_and_pkg_name
8
+ answer = ask_decision(question, actions_msg: 'y(yes), q(quit)')
9
+ if answer == :yes
10
+ packages_action(:install, pkg)
11
+ feature(:instance).firewall.enable_maintenance_mode
12
+ end
13
+ end
14
+
15
+ def can_install_nft?
16
+ # The nftables is default from EL8 and Debian 10(Buster)
17
+ (el? && el_major_version >= 8) ||
18
+ (debian? && deb_major_version >= 10) ||
19
+ (ubuntu? && ubuntu_major_version.to_i >= 22)
20
+ end
21
+
22
+ def question_and_pkg_name
23
+ pkg_to_install = can_install_nft? ? 'nftables' : 'iptables'
24
+ question = "Do you want to install missing netfilter utility #{pkg_to_install}?"\
25
+ "\nand start maintenance mode?"
26
+ [question, [pkg_to_install]]
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -46,12 +46,20 @@ module ForemanMaintain
46
46
  facts.fetch('ID_LIKE', '').split
47
47
  end
48
48
 
49
+ def os_name
50
+ facts.fetch('NAME')
51
+ end
52
+
49
53
  def el?
50
54
  File.exist?('/etc/redhat-release')
51
55
  end
52
56
 
53
57
  def debian?
54
- File.exist?('/etc/debian_version')
58
+ os_id == 'debian'
59
+ end
60
+
61
+ def ubuntu?
62
+ os_id == 'ubuntu'
55
63
  end
56
64
 
57
65
  def el7?
@@ -63,7 +71,23 @@ module ForemanMaintain
63
71
  end
64
72
 
65
73
  def el_major_version
66
- return os_version_id.to_i if el?
74
+ os_version_id.to_i if el?
75
+ end
76
+
77
+ def deb_major_version
78
+ os_version_id.to_i if debian?
79
+ end
80
+
81
+ def ubuntu_major_version
82
+ os_version_id if ubuntu?
83
+ end
84
+
85
+ def debian_or_ubuntu?
86
+ debian? || ubuntu?
87
+ end
88
+
89
+ def os_version
90
+ facts.fetch('VERSION')
67
91
  end
68
92
  end
69
93
  end
@@ -100,12 +100,13 @@ module ForemanMaintain
100
100
  end
101
101
 
102
102
  def packages_action(action, packages, options = {})
103
- options.validate_options!(:assumeyes)
103
+ options.validate_options!(:assumeyes, :yum_options)
104
104
  case action
105
105
  when :install
106
106
  package_manager.install(packages, :assumeyes => options[:assumeyes])
107
107
  when :update
108
- package_manager.update(packages, :assumeyes => options[:assumeyes])
108
+ package_manager.update(packages, :assumeyes => options[:assumeyes],
109
+ :yum_options => options[:yum_options])
109
110
  when :remove
110
111
  package_manager.remove(packages, :assumeyes => options[:assumeyes])
111
112
  else
@@ -114,8 +115,13 @@ module ForemanMaintain
114
115
  end
115
116
 
116
117
  def package_version(name)
117
- # space for extension to support non-rpm distributions
118
- rpm_version(name)
118
+ ver = if el?
119
+ '%{VERSION}'
120
+ elsif debian_or_ubuntu?
121
+ '${VERSION}'
122
+ end
123
+ pkg = package_manager.find_installed_package(name, ver)
124
+ version(pkg) unless pkg.nil?
119
125
  end
120
126
 
121
127
  def parse_csv(data)
@@ -132,13 +138,6 @@ module ForemanMaintain
132
138
  nil
133
139
  end
134
140
 
135
- def rpm_version(name)
136
- rpm_version = execute(%(rpm -q '#{name}' --queryformat="%{VERSION}"))
137
- if $CHILD_STATUS.success?
138
- version(rpm_version)
139
- end
140
- end
141
-
142
141
  def shellescape(string)
143
142
  Shellwords.escape(string)
144
143
  end
@@ -190,7 +189,7 @@ module ForemanMaintain
190
189
  end
191
190
 
192
191
  def ruby_prefix(scl = true)
193
- if debian?
192
+ if debian_or_ubuntu?
194
193
  'ruby-'
195
194
  elsif el7? && scl
196
195
  'tfm-rubygem-'
@@ -200,12 +199,12 @@ module ForemanMaintain
200
199
  end
201
200
 
202
201
  def foreman_plugin_name(plugin)
203
- plugin = plugin.tr('_', '-') if debian?
202
+ plugin = plugin.tr('_', '-') if debian_or_ubuntu?
204
203
  ruby_prefix + plugin
205
204
  end
206
205
 
207
206
  def proxy_plugin_name(plugin)
208
- if debian?
207
+ if debian_or_ubuntu?
209
208
  plugin = plugin.tr('_', '-')
210
209
  proxy_plugin_prefix = 'smart-proxy-'
211
210
  else
@@ -216,12 +215,12 @@ module ForemanMaintain
216
215
  end
217
216
 
218
217
  def hammer_plugin_name(plugin)
219
- plugin = plugin.tr('_', '-') if debian?
220
- [hammer_package, plugin].join(debian? ? '-' : '_')
218
+ plugin = plugin.tr('_', '-') if debian_or_ubuntu?
219
+ [hammer_package, plugin].join(debian_or_ubuntu? ? '-' : '_')
221
220
  end
222
221
 
223
222
  def hammer_package
224
- hammer_prefix = if debian?
223
+ hammer_prefix = if debian_or_ubuntu?
225
224
  'hammer-cli'
226
225
  else
227
226
  'hammer_cli'
@@ -0,0 +1,71 @@
1
+ module ForemanMaintain::PackageManager
2
+ class Apt < Base
3
+ def installed?(packages)
4
+ packages_list = [packages].flatten(1).map { |pkg| "'#{pkg}'" }.join(' ')
5
+ status, output = sys.execute_with_status(%(dpkg --status #{packages_list}))
6
+ return false if status != 0
7
+
8
+ status_of_pkg = output.split("\n").grep(/^Status:/).first
9
+ status_of_pkg.include?('installed')
10
+ end
11
+
12
+ def install(packages, assumeyes: false)
13
+ apt_action('install', packages, :assumeyes => assumeyes)
14
+ end
15
+
16
+ def remove(packages, assumeyes: false)
17
+ apt_action('remove', packages, :assumeyes => assumeyes)
18
+ end
19
+
20
+ def update(packages = [], assumeyes: false)
21
+ action = packages.any? ? '--only-upgrade install' : 'upgrade'
22
+ apt_action(action, packages, :assumeyes => assumeyes)
23
+ end
24
+
25
+ def clean_cache(assumeyes: false)
26
+ apt_action('clean', :assumeyes => assumeyes)
27
+ end
28
+
29
+ def find_installed_package(name, queryfm = '')
30
+ return unless installed?(name)
31
+
32
+ dpkg_cmd = "dpkg-query --show #{name}"
33
+ unless queryfm.empty?
34
+ dpkg_cmd = "dpkg-query --showformat='#{queryfm}' --show #{name}"
35
+ end
36
+ _, result = sys.execute_with_status(dpkg_cmd)
37
+ result
38
+ end
39
+
40
+ def check_update(packages: nil, with_status: false)
41
+ apt_action('upgrade --dry-run', packages, :with_status => with_status)
42
+ end
43
+
44
+ def list_installed_packages(queryfm = '${binary:Package}-${VERSION}\n')
45
+ # The queryfm should only include valid tag(s) as per `dpkg-query` man page.
46
+ # If any special formatting is required with querytag then it should be provided with tag i.e,
47
+ # querytag = "--%{VERSION}"
48
+ # The queryfm string must end with '\n'
49
+ sys.execute!("dpkg-query --showformat='#{queryfm}' -W").split("\n")
50
+ end
51
+
52
+ def version_locking_supported?
53
+ false
54
+ end
55
+
56
+ def apt_action(action, packages, with_status: false, assumeyes: false, valid_exit_statuses: [0])
57
+ apt_options = []
58
+ packages = [packages].flatten(1)
59
+ apt_options << '-y' if assumeyes
60
+ apt_options_s = apt_options.empty? ? '' : ' ' + apt_options.join(' ')
61
+ packages_s = packages.empty? ? '' : ' ' + packages.join(' ')
62
+ if with_status
63
+ sys.execute_with_status("apt-get#{apt_options_s} #{action}#{packages_s}",
64
+ :interactive => !assumeyes)
65
+ else
66
+ sys.execute!("apt-get#{apt_options_s} #{action}#{packages_s}",
67
+ :interactive => !assumeyes, :valid_exit_statuses => valid_exit_statuses)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -36,8 +36,12 @@ module ForemanMaintain::PackageManager
36
36
  sys.execute?(%(rpm -q #{packages_list}))
37
37
  end
38
38
 
39
- def find_installed_package(name)
40
- status, result = sys.execute_with_status(%(rpm -q '#{name}'))
39
+ def find_installed_package(name, queryformat = '')
40
+ rpm_cmd = "rpm -q '#{name}'"
41
+ unless queryformat.empty?
42
+ rpm_cmd += " --qf '#{queryformat}'"
43
+ end
44
+ status, result = sys.execute_with_status(rpm_cmd)
41
45
  if status == 0
42
46
  result
43
47
  end
@@ -55,8 +59,8 @@ module ForemanMaintain::PackageManager
55
59
  yum_action('remove', packages, :assumeyes => assumeyes)
56
60
  end
57
61
 
58
- def update(packages = [], assumeyes: false)
59
- yum_action('update', packages, :assumeyes => assumeyes)
62
+ def update(packages = [], assumeyes: false, yum_options: [])
63
+ yum_action('update', packages, :assumeyes => assumeyes, :yum_options => yum_options)
60
64
  end
61
65
 
62
66
  def clean_cache(assumeyes: false)
@@ -78,12 +82,12 @@ module ForemanMaintain::PackageManager
78
82
  sys.execute(find_cmd).split("\n")
79
83
  end
80
84
 
81
- def list_installed_packages(queryfm = '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n')
82
- # The queryfm should only include valid tag(s) as per `rpm --querytag` list.
85
+ def list_installed_packages(queryformat = '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n')
86
+ # The queryformat should only include valid tag(s) as per `rpm --querytags` list.
83
87
  # If any special formatting is required with querytag then it should be provided with tag i.e,
84
- # querytag = "--%{VENDOR}"
85
- # The queryfm string must end with '\n'
86
- sys.execute!("rpm -qa --qf '#{queryfm}'").split("\n")
88
+ # "--%{VENDOR}"
89
+ # The queryformat string must end with '\n'
90
+ sys.execute!("rpm -qa --qf '#{queryformat}'").split("\n")
87
91
  end
88
92
 
89
93
  private
@@ -116,8 +120,12 @@ module ForemanMaintain::PackageManager
116
120
  File.open(protector_config_file, 'w') { |file| file.puts config }
117
121
  end
118
122
 
119
- def yum_action(action, packages, with_status: false, assumeyes: false, valid_exit_statuses: [0])
120
- yum_options = []
123
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
124
+ def yum_action(action, packages, options)
125
+ with_status = options.fetch(:with_status, false)
126
+ assumeyes = options.fetch(:assumeyes, false)
127
+ valid_exit_statuses = options.fetch(:valid_exit_statuses, [0])
128
+ yum_options = options.fetch(:yum_options, [])
121
129
  packages = [packages].flatten(1)
122
130
  yum_options << '-y' if assumeyes
123
131
  yum_options << '--disableplugin=foreman-protector'
@@ -1,14 +1,16 @@
1
1
  require 'foreman_maintain/package_manager/base'
2
2
  require 'foreman_maintain/package_manager/yum'
3
3
  require 'foreman_maintain/package_manager/dnf'
4
+ require 'foreman_maintain/package_manager/apt'
4
5
 
5
6
  module ForemanMaintain
6
7
  def self.package_manager
7
- @package_manager ||= case (%w[dnf yum apt].find { |manager| !`command -v #{manager}`.empty? })
8
- when 'dnf'
9
- ForemanMaintain::PackageManager::Dnf.new
10
- when 'yum'
8
+ @package_manager ||= if el7?
11
9
  ForemanMaintain::PackageManager::Yum.new
10
+ elsif el?
11
+ ForemanMaintain::PackageManager::Dnf.new
12
+ elsif debian_or_ubuntu?
13
+ ForemanMaintain::PackageManager::Apt.new
12
14
  else
13
15
  raise 'No supported package manager was found'
14
16
  end
@@ -76,10 +76,21 @@ module ForemanMaintain::RepositoryManager
76
76
  end
77
77
 
78
78
  def hash_of_repoids_urls(repos, regex)
79
- Hash[*repos.split("\n").grep(regex).map do |entry|
80
- entry.split(':', 2).last.strip
81
- end
82
- ]
79
+ ids_urls = Hash[*repos.split("\n").grep(regex).map do |entry|
80
+ entry.split(':', 2).last.strip
81
+ end]
82
+
83
+ # The EL7 yum repolist output includes extra info in the output,
84
+ # as example
85
+ # rhel-7-server-rpms/7Server/x86_64
86
+ # rhel-server-rhscl-7-rpms/7Server/x86_64
87
+ # This trims anything after first '/' to get correct repo label
88
+ trimmed_hash = {}
89
+ ids_urls.each do |id, url|
90
+ trimmed_id = id.split('/').first
91
+ trimmed_hash[trimmed_id] = url
92
+ end
93
+ trimmed_hash
83
94
  end
84
95
  end
85
96
  end
@@ -4,7 +4,7 @@ module ForemanMaintain
4
4
  def self.repository_manager
5
5
  @repository_manager ||= if el?
6
6
  ForemanMaintain::RepositoryManager::El.new
7
- elsif debian?
7
+ elsif debian_or_ubuntu?
8
8
  raise 'Not implemented!'
9
9
  else
10
10
  raise 'No supported repository manager was found'
@@ -8,21 +8,16 @@ module ForemanMaintain::Utils
8
8
  @instance_parent_unit = options.fetch(:instance_parent_unit, nil)
9
9
  end
10
10
 
11
- def command(action, options = {})
12
- do_wait = options.fetch(:wait, true) # wait for service to start
11
+ def command(action)
13
12
  all = @options.fetch(:all, false)
14
13
  skip_enablement = @options.fetch(:skip_enablement, false)
15
14
  if skip_enablement && %w[enable disable].include?(action)
16
15
  return skip_enablement_message(action, @name)
17
16
  end
18
17
 
19
- if do_wait && File.exist?('/usr/sbin/service-wait')
20
- "service-wait #{@name} #{action}"
21
- else
22
- cmd = "systemctl #{action} #{@name}"
23
- cmd += ' --all' if all
24
- cmd
25
- end
18
+ cmd = "systemctl #{action} #{@name}"
19
+ cmd += ' --all' if all
20
+ cmd
26
21
  end
27
22
 
28
23
  def status
@@ -38,11 +33,11 @@ module ForemanMaintain::Utils
38
33
  end
39
34
 
40
35
  def enable
41
- execute('enable', :wait => false)
36
+ execute('enable')
42
37
  end
43
38
 
44
39
  def disable
45
- execute('disable', :wait => false)
40
+ execute('disable')
46
41
  end
47
42
 
48
43
  def running?
@@ -66,8 +61,8 @@ module ForemanMaintain::Utils
66
61
 
67
62
  private
68
63
 
69
- def execute(action, options = {})
70
- @sys.execute_with_status(command(action, options))
64
+ def execute(action)
65
+ @sys.execute_with_status(command(action))
71
66
  end
72
67
 
73
68
  def service_enabled_status
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '1.0.11'.freeze
2
+ VERSION = '1.1.2'.freeze
3
3
  end
@@ -26,6 +26,7 @@ module ForemanMaintain
26
26
  require 'foreman_maintain/concerns/pulp_common'
27
27
  require 'foreman_maintain/concerns/firewall/iptables_maintenance_mode'
28
28
  require 'foreman_maintain/concerns/firewall/nftables_maintenance_mode'
29
+ require 'foreman_maintain/concerns/firewall/maintenance_mode'
29
30
  require 'foreman_maintain/top_level_modules'
30
31
  require 'foreman_maintain/yaml_storage'
31
32
  require 'foreman_maintain/config'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_maintain
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-01 00:00:00.000000000 Z
11
+ date: 2022-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -266,6 +266,7 @@ files:
266
266
  - definitions/procedures/foreman_tasks/ui_investigate.rb
267
267
  - definitions/procedures/hammer_setup.rb
268
268
  - definitions/procedures/installer/run.rb
269
+ - definitions/procedures/installer/run_for_6_11.rb
269
270
  - definitions/procedures/installer/upgrade.rb
270
271
  - definitions/procedures/installer/upgrade_rake_task.rb
271
272
  - definitions/procedures/knowledge_base_article.rb
@@ -392,6 +393,7 @@ files:
392
393
  - lib/foreman_maintain/concerns/downstream.rb
393
394
  - lib/foreman_maintain/concerns/finders.rb
394
395
  - lib/foreman_maintain/concerns/firewall/iptables_maintenance_mode.rb
396
+ - lib/foreman_maintain/concerns/firewall/maintenance_mode.rb
395
397
  - lib/foreman_maintain/concerns/firewall/nftables_maintenance_mode.rb
396
398
  - lib/foreman_maintain/concerns/hammer.rb
397
399
  - lib/foreman_maintain/concerns/logger.rb
@@ -413,6 +415,7 @@ files:
413
415
  - lib/foreman_maintain/executable.rb
414
416
  - lib/foreman_maintain/feature.rb
415
417
  - lib/foreman_maintain/package_manager.rb
418
+ - lib/foreman_maintain/package_manager/apt.rb
416
419
  - lib/foreman_maintain/package_manager/base.rb
417
420
  - lib/foreman_maintain/package_manager/dnf.rb
418
421
  - lib/foreman_maintain/package_manager/yum.rb