foreman_maintain 0.6.4 → 0.6.9

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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +46 -10
  3. data/bin/foreman-maintain-complete +3 -2
  4. data/definitions/checks/env_proxy.rb +13 -0
  5. data/definitions/checks/foreman/check_corrupted_roles.rb +14 -2
  6. data/definitions/checks/foreman_proxy/check_tftp_storage.rb +52 -0
  7. data/definitions/checks/foreman_proxy/verify_dhcp_config_syntax.rb +7 -9
  8. data/definitions/checks/repositories/check_non_rh_repository.rb +2 -2
  9. data/definitions/features/capsule.rb +2 -1
  10. data/definitions/features/foreman_proxy.rb +33 -6
  11. data/definitions/features/foreman_server.rb +1 -1
  12. data/definitions/procedures/backup/metadata.rb +2 -0
  13. data/definitions/procedures/backup/prepare_directory.rb +8 -1
  14. data/definitions/procedures/backup/snapshot/logical_volume_confirmation.rb +1 -1
  15. data/definitions/procedures/content/prepare.rb +5 -0
  16. data/definitions/procedures/content/switchover.rb +7 -1
  17. data/definitions/procedures/packages/locking_status.rb +1 -1
  18. data/definitions/procedures/restore/configs.rb +6 -0
  19. data/definitions/procedures/restore/regenerate_queues.rb +69 -0
  20. data/definitions/scenarios/backup.rb +1 -0
  21. data/definitions/scenarios/content.rb +8 -2
  22. data/definitions/scenarios/packages.rb +4 -1
  23. data/definitions/scenarios/restore.rb +17 -2
  24. data/extras/foreman_protector/foreman-protector.py +1 -1
  25. data/lib/foreman_maintain.rb +7 -1
  26. data/lib/foreman_maintain/cli/restore_command.rb +2 -1
  27. data/lib/foreman_maintain/concerns/base_database.rb +1 -1
  28. data/lib/foreman_maintain/concerns/downstream.rb +8 -12
  29. data/lib/foreman_maintain/utils/backup.rb +4 -0
  30. data/lib/foreman_maintain/version.rb +1 -1
  31. metadata +6 -5
  32. data/definitions/scenarios/upgrade_to_capsule_6_7.rb +0 -88
  33. data/definitions/scenarios/upgrade_to_capsule_6_7_z.rb +0 -88
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e51a96d2df37cf98881bc81a1b67f33dca283ea34b226f2f434273984e6baa59
4
- data.tar.gz: ad6c47b27ba7e5c2869354c0a60885e8da2158cc3b6feb04df614ccc78c395d5
3
+ metadata.gz: 7050dd905c1396f95686caabf7afaea60f963b8c68c2b0849eb4d06b7e5330f7
4
+ data.tar.gz: d683a46f74563cb3c22a4f0ab94ebf3354aa4685afd8b22a7ea68ec1fc6d70a7
5
5
  SHA512:
6
- metadata.gz: ddd22571061620757eaa7d814c34c7c4d06801361ebba1296b5089a345ed61ac91c41fbaa97f643bb8535bf5644d5e96065dccbd66681d6b3516963462f1d940
7
- data.tar.gz: 9f0023b28042b0f5145a7c2b60b91a8194216eeaa5936987cb91504c49a502a9dfd03c21d3d527cc7487a14a7abe2d8513dcc66a7f47454fa9f3bdc61debdb85
6
+ metadata.gz: 56ffb28e036596b3b7262ff27e5f7ab85ccd98ba3f261ef5049f0e4c404b743b96fe3086723a7a0d08005e27308b40888e209ca66125662d4dd72da8706a540c
7
+ data.tar.gz: f056a9c36223352dededfd338e462070f71780b679e2d661360733a85ef07045ac1fd7f803421f945d9f1cc0176d7351d8f0f951da558635b33a5dcc7e99a67c
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Foreman Maintenance [![Build Status](https://travis-ci.org/theforeman/foreman_maintain.svg?branch=master)](https://travis-ci.org/theforeman/foreman_maintain) <a href="https://codeclimate.com/github/theforeman/foreman_maintain"><img src="https://codeclimate.com/github/theforeman/foreman_maintain/badges/gpa.svg" /></a>
2
2
 
3
- `foreman_maintain` aims to provide various features that helps keep the
3
+ The `foreman_maintain` aims to provide various features that helps keep the
4
4
  Foreman/Satellite up and running. It supports multiple versions and subparts
5
5
  of the Foreman infrastructure, including server or smart proxy and is smart
6
6
  enough to provide the right tools for the specific version.
@@ -19,8 +19,10 @@ Subcommands:
19
19
  upgrade Upgrade related commands
20
20
  list-versions List versions this system is upgradable to
21
21
  check --target-version TARGET_VERSION Run pre-upgrade checks for upgrading to specified version
22
+ --disable-self-upgrade Disable automatic self upgrade (default: false)
22
23
  run --target-version TARGET_VERSION Run the full upgrade
23
24
  [--phase=phase TARGET_VERSION] Run just a specific phase of the upgrade
25
+ --disable-self-upgrade Disable automatic self upgrade (default: false)
24
26
 
25
27
  advanced Advanced tools for server maintenance
26
28
  procedure Run maintain procedures manually
@@ -59,8 +61,8 @@ Subcommands:
59
61
  Foreman-maintain implements upgrade tooling that helps the administrator to go
60
62
  through the upgrade process.
61
63
 
62
- Foreman-maintain scans the system to know, what version are available
63
- to upgrade to for the particular system. To see what versions are available
64
+ Foreman-maintain scans the system to know, what versions are available
65
+ for upgrade on the particular system. To see what versions are available
64
66
  for upgrade, run:
65
67
 
66
68
  ```
@@ -88,13 +90,13 @@ of the system:
88
90
 
89
91
  * **pre-migrations** - these steps perform changes on the system before
90
92
  the actual upgrade starts. An example is disabling access to the system from
91
- external sources, a.k.a. maintenance mode or disabling sync plans during the run.
93
+ external sources, a.k.a. maintenance mode or disabling Katello sync plans during the run.
92
94
 
93
95
  After this phase ends, the system is still running the old version, and it's possible
94
96
  to revert the changes by running the post-migrations steps.
95
97
 
96
98
  * **migrations** - this phase performs the actual migrations, starting with
97
- configuring new repositories, updated the packages and running the installer.
99
+ configuring new repositories, updating the packages and running the installer.
98
100
 
99
101
  At the end of this phase, the system should be fully migrated to the new version.
100
102
  However, the system is not fully operational yet, as the post-migrations steps
@@ -103,7 +105,7 @@ of the system:
103
105
  * **post-migrations** - these steps revert the changes made in pre-migrations phase,
104
106
  turning the system into fully-operational again.
105
107
 
106
- * **post-upgrade checks** - this steps should perform sanity check of the system
108
+ * **post-upgrade checks** - these steps should perform sanity check of the system
107
109
  to ensure the system is valid and ready to be used again.
108
110
 
109
111
 
@@ -114,6 +116,40 @@ the *pre-upgrade check* phase. In case the upgrade failed before **migrations**
114
116
  phase made some modifying changes, the tool tries to rollback to the previous
115
117
  state of the system.
116
118
 
119
+ #### Self-upgrade for rubygem-foreman_maintain package
120
+
121
+ **Note:** This feature is available from `rubygem-foreman_maintain` version 0.6.4 and newer.
122
+
123
+ When a user runs any `foreman-maintain upgrade` sub commands (e.g. `foreman-maintain upgrade check` or `foreman-maintain upgrade run`) then,
124
+
125
+ * If update available for `rubygem-foreman_maintain` package, the sub command tries to update this package. After successful package update, it returns the exit code 75 and requests user to re-run with the updated source code.
126
+
127
+ Here, exit code (value 75) is to indicate that it can not continue with further execution & needs re-run. e.g.,
128
+
129
+ ~~~
130
+ # foreman-maintain upgrade check --target-version TARGET_VERSION
131
+ Checking for new version of foreman-maintain...
132
+ rubygem-foreman_maintain.noarch repository
133
+
134
+ Updating foreman-maintain package.
135
+
136
+ The foreman-maintain package successfully updated.
137
+
138
+ Re-run foreman-maintain with required options!
139
+
140
+ # echo $?
141
+ 75
142
+ ~~~
143
+
144
+ * If update is not available for `rubygem-foreman_maintain` package, then sub command simply executes the further steps without halt.
145
+
146
+ * If user wants to skip self-update mechanism then `--disable-self-upgrade` flag can be used with upgrade sub commands. e.g.,
147
+
148
+ ~~~
149
+ # foreman-maintain upgrade check --target-version TARGET_VERSION --disable-self-upgrade
150
+ # foreman-maintain upgrade run --target-version TARGET_VERSION --disable-self-upgrade
151
+ ~~~
152
+
117
153
  #### Satellite notes
118
154
 
119
155
  To use custom organization/activation key for configuring repositories during
@@ -132,7 +168,7 @@ export FOREMAN_MAINTAIN_USE_BETA='1'
132
168
 
133
169
  ## Implementation
134
170
 
135
- `foreman_maintain` maps the CLI commands into definitions. This allows to keep the set
171
+ The `foreman_maintain` maps the CLI commands into definitions. This allows to keep the set
136
172
  of the commands the user needs to know immutable from version-specific changes. The mapping
137
173
  between the CLI commands and definitions is made by defining various metadata.
138
174
 
@@ -329,8 +365,8 @@ end
329
365
  ```
330
366
 
331
367
  Before executing the command the feature checks if it has valid hammer configuration to run the command.
332
- Foreman maintain always use the 'admin' account to run the commands. The password is taken either form
333
- the Hammer config or installer answer files or asked from the user interactively (in this order).
368
+ Foreman maintain always use the 'admin' account to run the commands. The password is taken from
369
+ the hammer config or installer answer files or asked from the user interactively (in this order).
334
370
  The valid credentials are stored and reused next time if still valid.
335
371
 
336
372
  Usually we want to do the user interaction at the beginning of our scenario.
@@ -449,7 +485,7 @@ Possible options for the `:completion` attribute are:
449
485
  * `maintenance-mode is-enabled` returns `0 or 1` output depending upon the maintenance-mode status.
450
486
  Here, 0=ON & 1=OFF.
451
487
 
452
- If User would like to check whether maintenance-mode is ON/OFF on system in their external script then
488
+ If users would like to check whether maintenance-mode is ON/OFF on system in their external script then
453
489
  they can use subcommand `foreman-maintain maintenance-mode is-enabled`.
454
490
 
455
491
  ## How to contribute?
@@ -13,7 +13,8 @@ require 'foreman_maintain/utils/bash'
13
13
  # rubocop:disable Lint/RescueWithoutErrorClass, Lint/HandleExceptions
14
14
  def cache_file(config_file)
15
15
  config = YAML.load(File.open(config_file))
16
- config[:completion_cache_file]
16
+ config.fetch(:completion_cache_file,
17
+ "#{ENV['HOME'] || '/root'}/.cache/foreman_maintain_completion.yml")
17
18
  rescue
18
19
  end
19
20
  # rubocop:enable Lint/RescueWithoutErrorClass, Lint/HandleExceptions
@@ -23,7 +24,7 @@ config_file = if File.exist?(CONFIG_FILE)
23
24
  else
24
25
  File.join(project_root, 'config/foreman_maintain.yml')
25
26
  end
26
- completion_cache_file = cache_file(config_file) || '~/.cache/foreman_maintain_completion.yml'
27
+ completion_cache_file = cache_file(config_file)
27
28
  completion_cache_file = File.expand_path(completion_cache_file)
28
29
 
29
30
  # build the cache if it does not exist
@@ -0,0 +1,13 @@
1
+ class Checks::EnvProxy < ForemanMaintain::Check
2
+ metadata do
3
+ label :env_proxy
4
+ tags :env_proxy
5
+ description 'Check to make sure no HTTP(S) proxy set in ENV'
6
+ end
7
+
8
+ def run
9
+ variables = %w[http_proxy https_proxy HTTP_PROXY HTTPS_PROXY]
10
+ has_proxy_set = true if variables.map { |variable| ENV[variable] }.compact.any?
11
+ assert(!has_proxy_set, 'Global HTTP(S) proxy in environment (env) is set. Please unset first!')
12
+ end
13
+ end
@@ -14,14 +14,22 @@ module Checks
14
14
  def run
15
15
  items = find_filter_permissions
16
16
  assert(items.empty?,
17
- 'There are user roles with inconsistent filters',
17
+ error_message(items),
18
18
  :next_steps => Procedures::Foreman::FixCorruptedRoles.new)
19
19
  end
20
20
 
21
+ def error_message(items)
22
+ roles = items.map { |item| item['role_name'] }.uniq
23
+ 'There are filters having permissions with multiple resource types. ' \
24
+ 'Roles with such filters are:' \
25
+ "\n#{roles.join("\n")}"
26
+ end
27
+
21
28
  def find_filter_permissions
22
29
  feature(:foreman_database).query(self.class.inconsistent_filter_perms)
23
30
  end
24
31
 
32
+ # rubocop:disable Metrics/MethodLength
25
33
  def self.inconsistent_filter_perms
26
34
  subquery = <<-SQL
27
35
  SELECT filters.id AS filter_id,
@@ -32,14 +40,17 @@ module Checks
32
40
  filterings.id AS filtering_id,
33
41
  permissions.id AS permission_id,
34
42
  permissions.name AS permission_name,
35
- permissions.resource_type
43
+ permissions.resource_type,
44
+ roles.name AS role_name
36
45
  FROM filters INNER JOIN filterings ON filters.id = filterings.filter_id
37
46
  INNER JOIN permissions ON permissions.id = filterings.permission_id
47
+ INNER JOIN roles ON filters.role_id = roles.id
38
48
  SQL
39
49
 
40
50
  <<-SQL
41
51
  SELECT DISTINCT first.filter_id,
42
52
  first.role_id,
53
+ first.role_name,
43
54
  first.filtering_id,
44
55
  first.permission_id,
45
56
  first.permission_name,
@@ -54,6 +65,7 @@ module Checks
54
65
  OR (first.resource_type != second.resource_type))
55
66
  SQL
56
67
  end
68
+ # rubocop:enable Metrics/MethodLength
57
69
  end
58
70
  end
59
71
  end
@@ -0,0 +1,52 @@
1
+ module Checks::ForemanProxy
2
+ class CheckTftpStorage < ForemanMaintain::Check
3
+ metadata do
4
+ label :check_tftp_storage
5
+ description 'Clean old Kernel and initramfs files from tftp-boot'
6
+ tags :default
7
+ confine do
8
+ feature(:satellite) && feature(:foreman_proxy) &&
9
+ feature(:foreman_proxy).features.include?('tftp') && non_zero_token_duration?
10
+ end
11
+ end
12
+
13
+ def run
14
+ if Dir.exist?(tftp_boot_directory)
15
+ files = old_files_from_tftp_boot
16
+ assert(files.empty?,
17
+ 'There are old initrd and vmlinuz files present in tftp',
18
+ :next_steps => Procedures::Files::Remove.new(:files => files))
19
+ else
20
+ skip "TFTP #{tftp_boot_directory} directory doesn't exist."
21
+ end
22
+ end
23
+
24
+ def old_files_from_tftp_boot
25
+ Dir.entries(tftp_boot_directory).map do |file|
26
+ unless File.directory?(file)
27
+ file_path = tftp_boot_directory + file
28
+ file_path if File.mtime(file_path) + (token_duration * 60) < Time.now
29
+ end
30
+ end.compact
31
+ end
32
+
33
+ def self.non_zero_token_duration?
34
+ lookup_token_duration != 0
35
+ end
36
+
37
+ def tftp_boot_directory
38
+ @tftp_boot_directory ||= "#{feature(:foreman_proxy).tftp_root_directory}/boot/"
39
+ end
40
+
41
+ def token_duration
42
+ @token_duration ||= self.class.lookup_token_duration
43
+ end
44
+
45
+ def self.lookup_token_duration
46
+ data = feature(:foreman_database). \
47
+ query("select s.value, s.default from settings s \
48
+ where category = 'Setting::Provisioning' and name = 'token_duration'")
49
+ YAML.load(data[0]['value'] || data[0]['default'])
50
+ end
51
+ end
52
+ end
@@ -4,20 +4,18 @@ module Checks::ForemanProxy
4
4
  description 'Check for verifying syntax for ISP DHCP configurations'
5
5
  tags :default
6
6
  confine do
7
- feature(:foreman_proxy)
7
+ feature(:foreman_proxy) &&
8
+ feature(:foreman_proxy).features.include?('dhcp') &&
9
+ feature(:foreman_proxy).dhcp_isc_provider?
8
10
  end
9
11
  end
10
12
 
11
13
  def run
12
- if feature(:foreman_proxy).features.include?('dhcp')
13
- if feature(:foreman_proxy).dhcpd_conf_exist?
14
- success = feature(:foreman_proxy).valid_dhcp_configs?
15
- assert(success, 'Please check and verify DHCP configurations.')
16
- else
17
- fail! "Couldn't find configuration file at #{feature(:foreman_proxy).dhcpd_config_file}"
18
- end
14
+ if feature(:foreman_proxy).dhcpd_conf_exist?
15
+ success = feature(:foreman_proxy).valid_dhcp_configs?
16
+ assert(success, 'Please check and verify DHCP configurations.')
19
17
  else
20
- skip 'DHCP feature is not enabled'
18
+ fail! "Couldn't find configuration file at #{feature(:foreman_proxy).dhcpd_config_file}"
21
19
  end
22
20
  end
23
21
  end
@@ -2,7 +2,7 @@ module Checks::Repositories
2
2
  class CheckNonRhRepository < ForemanMaintain::Check
3
3
  metadata do
4
4
  label :check_non_redhat_repository
5
- description "Check whether system don't have any non Red Hat repositories(Eg: EPEL) enabled"
5
+ description 'Check whether system has any non Red Hat repositories (e.g.: EPEL) enabled'
6
6
  tags :pre_upgrade
7
7
  confine do
8
8
  feature(:instance).downstream
@@ -11,7 +11,7 @@ module Checks::Repositories
11
11
 
12
12
  def run
13
13
  with_spinner('Checking repositories enabled on the system') do
14
- assert(!epel_enabled?, 'System is subscribed to non Red Hat repositories(Eg: EPEL)')
14
+ assert(!epel_enabled?, 'System is subscribed to non Red Hat repositories')
15
15
  end
16
16
  end
17
17
 
@@ -5,7 +5,8 @@ class Features::Capsule < ForemanMaintain::Feature
5
5
  label :capsule
6
6
 
7
7
  confine do
8
- package_manager.installed?(['satellite-capsule']) ||
8
+ !package_manager.installed?(['satellite']) &&
9
+ package_manager.installed?(['satellite-capsule']) ||
9
10
  package_manager.installed?(['capsule-installer'])
10
11
  end
11
12
  end
@@ -12,6 +12,9 @@ class Features::ForemanProxy < ForemanMaintain::Feature
12
12
  FOREMAN_PROXY_DHCP_YML_PATHS = ['/etc/foreman-proxy/settings.d/dhcp.yml',
13
13
  '/usr/local/etc/foreman-proxy/settings.d/dhcp.yml'].freeze
14
14
 
15
+ FOREMAN_PROXY_TFTP_YML_PATHS = ['/etc/foreman-proxy/settings.d/tftp.yml',
16
+ '/usr/local/etc/foreman-proxy/settings.d/tftp.yml'].freeze
17
+
15
18
  def valid_dhcp_configs?
16
19
  dhcp_req_pass? && !syntax_error_exists?
17
20
  end
@@ -66,7 +69,7 @@ class Features::ForemanProxy < ForemanMaintain::Feature
66
69
 
67
70
  configs.push('/var/lib/tftpboot') if backup_features.include?('tftp')
68
71
  configs += ['/var/named/', '/etc/named*'] if backup_features.include?('dns')
69
- if backup_features.include?('dhcp')
72
+ if backup_features.include?('dhcp') && dhcp_isc_provider?
70
73
  configs += ['/var/lib/dhcpd', File.dirname(dhcpd_config_file)]
71
74
  end
72
75
  configs.push('/usr/share/xml/scap') if backup_features.include?('openscap')
@@ -98,7 +101,9 @@ class Features::ForemanProxy < ForemanMaintain::Feature
98
101
  end
99
102
 
100
103
  def certs_tar
101
- feature(:installer).answers[content_module][certs_param_name[:param_section]] if content_module
104
+ if content_module
105
+ feature(:installer).answers.fetch(content_module, {})[certs_param_name[:param_key]]
106
+ end
102
107
  end
103
108
 
104
109
  def settings_file
@@ -113,6 +118,14 @@ class Features::ForemanProxy < ForemanMaintain::Feature
113
118
  @dhcpd_config_file ||= lookup_dhcpd_config_file
114
119
  end
115
120
 
121
+ def tftp_root_directory
122
+ @tftp_root_directory ||= lookup_tftp_root_directory
123
+ end
124
+
125
+ def dhcp_isc_provider?
126
+ configs_from_dhcp_yml[:use_provider] == 'dhcp_isc'
127
+ end
128
+
116
129
  private
117
130
 
118
131
  def backup_features(for_features)
@@ -209,11 +222,18 @@ class Features::ForemanProxy < ForemanMaintain::Feature
209
222
  dhcpd_config_file
210
223
  end
211
224
 
212
- def lookup_using_dhcp_yml
213
- dhcp_yml_path = lookup_into(FOREMAN_PROXY_DHCP_YML_PATHS)
214
- raise "Couldn't find dhcp.yml file under foreman-proxy" unless dhcp_yml_path
225
+ def dhcp_yml_path
226
+ dhcp_path = lookup_into(FOREMAN_PROXY_DHCP_YML_PATHS)
227
+ raise "Couldn't find dhcp.yml file under foreman-proxy" unless dhcp_path
215
228
 
216
- configs_from_dhcp_yml = yaml_load(dhcp_yml_path)
229
+ dhcp_path
230
+ end
231
+
232
+ def configs_from_dhcp_yml
233
+ @configs_from_dhcp_yml ||= yaml_load(dhcp_yml_path)
234
+ end
235
+
236
+ def lookup_using_dhcp_yml
217
237
  if configs_from_dhcp_yml.key?(:dhcp_config)
218
238
  return configs_from_dhcp_yml[:dhcp_config]
219
239
  elsif configs_from_dhcp_yml.key?(:use_provider)
@@ -226,6 +246,13 @@ class Features::ForemanProxy < ForemanMaintain::Feature
226
246
  end
227
247
  end
228
248
 
249
+ def lookup_tftp_root_directory
250
+ tftp_yml_path = lookup_into(FOREMAN_PROXY_TFTP_YML_PATHS)
251
+ raise "Couldn't find tftp.yml file under foreman-proxy" unless tftp_yml_path
252
+
253
+ yaml_load(tftp_yml_path)[:tftproot]
254
+ end
255
+
229
256
  def yaml_load(path)
230
257
  YAML.load_file(path) || {}
231
258
  end
@@ -28,7 +28,7 @@ module ForemanMaintain
28
28
  def config_files
29
29
  [
30
30
  '/etc/httpd',
31
- '/var/www/html/pub',
31
+ '/var/www/html/pub/katello-*',
32
32
  '/etc/squid',
33
33
  '/etc/foreman',
34
34
  '/etc/selinux/targeted/contexts/files/file_contexts.subs',
@@ -6,6 +6,7 @@ module Procedures::Backup
6
6
  preparation_steps { Checks::Foreman::DBUp.new if feature(:foreman_server) }
7
7
  param :backup_dir, 'Directory where to backup to', :required => true
8
8
  param :incremental_dir, 'Changes since specified backup only'
9
+ param :online_backup, 'Select for online backup', :flag => true, :default => false
9
10
  end
10
11
 
11
12
  def run
@@ -16,6 +17,7 @@ module Procedures::Backup
16
17
  metadata['proxy_features'] = proxy_feature_list(spinner) || []
17
18
  metadata['rpms'] = rpms(spinner)
18
19
  metadata['incremental'] = @incremental_dir || false
20
+ metadata['online'] = @online_backup
19
21
  save_metadata(metadata, spinner)
20
22
  end
21
23
  end
@@ -8,6 +8,7 @@ module Procedures::Backup
8
8
  param :incremental_dir, 'Changes since specified backup only'
9
9
  end
10
10
 
11
+ # rubocop:disable Metrics/MethodLength
11
12
  def run
12
13
  puts "Creating backup folder #{@backup_dir}"
13
14
 
@@ -22,8 +23,14 @@ module Procedures::Backup
22
23
 
23
24
  FileUtils.rm(Dir.glob(File.join(@backup_dir, '.*.snar'))) if @preserve_dir
24
25
  if @incremental_dir
25
- FileUtils.cp(Dir.glob(File.join(@incremental_dir, '.*.snar')), @backup_dir)
26
+ if (snar_files = Dir.glob(File.join(@incremental_dir, '.*.snar'))).empty?
27
+ raise "#{@incremental_dir}/*.snar files unavailable. "\
28
+ 'Provide a valid previous backup directory'
29
+ else
30
+ FileUtils.cp(snar_files, @backup_dir)
31
+ end
26
32
  end
27
33
  end
34
+ # rubocop:enable Metrics/MethodLength
28
35
  end
29
36
  end
@@ -12,7 +12,7 @@ module Procedures::Backup
12
12
  backup_lv = get_lv_info(@backup_dir)
13
13
 
14
14
  dbs = {}
15
- dbs[:pulp] = 'Pulp' if feature(:pulp2) && !@skip_pulp
15
+ dbs[:pulp2] = 'Pulp' if feature(:pulp2) && !@skip_pulp
16
16
  dbs[:mongo] = 'Mongo' if db_local?(:mongo)
17
17
  dbs[:candlepin_database] = 'Candlepin' if db_local?(:candlepin_database)
18
18
  dbs[:foreman_database] = 'Foreman' if db_local?(:foreman_database)
@@ -3,6 +3,11 @@ module Procedures::Content
3
3
  metadata do
4
4
  description 'Prepare content for Pulp 3'
5
5
  for_feature :pulpcore
6
+
7
+ confine do
8
+ # FIXME: remove this condition on next downstream upgrade scenario
9
+ !feature(:instance).downstream
10
+ end
6
11
  end
7
12
 
8
13
  def run
@@ -3,6 +3,11 @@ module Procedures::Content
3
3
  metadata do
4
4
  description 'Switch support for certain content from Pulp 2 to Pulp 3'
5
5
  for_feature :pulpcore
6
+
7
+ confine do
8
+ # FIXME: remove this condition on next downstream upgrade scenario
9
+ !feature(:instance).downstream
10
+ end
6
11
  end
7
12
 
8
13
  def run
@@ -15,7 +20,8 @@ module Procedures::Content
15
20
  puts 'Re-running the installer to switch specified content over to pulp3'
16
21
  args = ['--foreman-proxy-content-proxy-pulp-isos-to-pulpcore=true',
17
22
  '--katello-use-pulp-2-for-file=false',
18
- '--katello-use-pulp-2-for-docker=false']
23
+ '--katello-use-pulp-2-for-docker=false',
24
+ '--katello-use-pulp-2-for-yum=false']
19
25
  feature(:installer).run(args.join(' '))
20
26
  end
21
27
  end
@@ -18,7 +18,7 @@ module Procedures::Packages
18
18
  else
19
19
  puts ' Packages are not locked.'
20
20
  puts " WARNING: When locking is disabled there is a risk of unwanted update\n" \
21
- " of #{feature(:instance).product_name}' and its components and possible " \
21
+ " of #{feature(:instance).product_name} and its components and possible " \
22
22
  'data inconsistency'
23
23
  end
24
24
  end
@@ -19,10 +19,15 @@ module Procedures::Restore
19
19
  end
20
20
  end
21
21
 
22
+ # rubocop:disable Metrics/MethodLength
22
23
  def restore_configs(backup)
23
24
  exclude = ForemanMaintain.available_features.each_with_object([]) do |feat, cfgs|
25
+ if backup.online_backup?
26
+ feat.config_files_exclude_for_online.each { |f| cfgs << f.gsub(%r{^/}, '') }
27
+ end
24
28
  feat.config_files_to_exclude.each { |f| cfgs << f.gsub(%r{^/}, '') }
25
29
  end
30
+
26
31
  tar_options = {
27
32
  :overwrite => true,
28
33
  :listed_incremental => '/dev/null',
@@ -35,6 +40,7 @@ module Procedures::Restore
35
40
 
36
41
  feature(:tar).run(tar_options)
37
42
  end
43
+ # rubocop:enable Metrics/MethodLength
38
44
 
39
45
  def reload_configs
40
46
  feature(:mongo).reload_db_config if feature(:mongo)
@@ -0,0 +1,69 @@
1
+ module Procedures::Restore
2
+ class RegenerateQueues < ForemanMaintain::Procedure
3
+ metadata do
4
+ advanced_run false
5
+ description 'Regenerate required activemq and qpidd queues while restoring online backup'
6
+ confine do
7
+ feature(:pulp2)
8
+ end
9
+ end
10
+
11
+ def qpid_router_broker_port
12
+ @qpid_router_broker_port ||= feature(:installer).
13
+ answers['foreman_proxy_content']['qpid_router_broker_port']
14
+ end
15
+
16
+ def qpid_configs
17
+ @qpid_configs ||= {
18
+ 'ssl_cert' => "/etc/pki/katello/certs/#{hostname}-qpid-broker.crt",
19
+ 'ssl_key' => "/etc/pki/katello/private/#{hostname}-qpid-broker.key",
20
+ 'amqps_url' => "amqps://localhost:#{qpid_router_broker_port}"
21
+ }
22
+ end
23
+
24
+ def katello_events
25
+ %w[compliance.created
26
+ entitlement.created
27
+ entitlement.deleted
28
+ pool.created
29
+ pool.deleted]
30
+ end
31
+
32
+ def run
33
+ with_spinner('Resetting the queues') do |spinner|
34
+ regenerate_activemq_queues(spinner)
35
+ regenerate_qpidd_queues(spinner)
36
+ spinner.update('Queues created successfully')
37
+ end
38
+ end
39
+
40
+ def regenerate_activemq_queues(spinner)
41
+ # The activemq queues(/var/lib/candlepin/activemq-artemis) regenerate on tomcat restart.
42
+ # After stopping the tomcat here, service start is triggered from the restore scenario.
43
+ spinner.update('Stopping tomcat service')
44
+ feature(:candlepin).services.select(&:exist?).first.stop
45
+ spinner.update('Recreating activemq queues')
46
+ execute!('rm -rf /var/lib/candlepin/activemq-artemis/')
47
+ end
48
+
49
+ def run_qpid_command(opts)
50
+ execute!("qpid-config --ssl-certificate #{qpid_configs['ssl_cert']} \\
51
+ --ssl-key #{qpid_configs['ssl_key']} -b #{qpid_configs['amqps_url']} #{opts}")
52
+ end
53
+
54
+ def regenerate_qpidd_queues(spinner)
55
+ feature(:service).handle_services(spinner, 'stop', :only => ['qpidd'])
56
+ execute!('rm -rf /var/lib/qpidd/.qpidd/qls')
57
+ spinner.update('Starting qpidd service')
58
+ feature(:service).handle_services(spinner, 'start', :only => ['qpidd'])
59
+ spinner.update('Service qpidd started, waiting 60 seconds to start it completely')
60
+ sleep 60
61
+ spinner.update('Recreating qpidd queues')
62
+ run_qpid_command('add exchange topic event --durable')
63
+ run_qpid_command('add queue katello_event_queue --durable')
64
+ katello_events.each do |event|
65
+ run_qpid_command("bind event katello_event_queue #{event}")
66
+ end
67
+ end
68
+ end
69
+ end
@@ -210,6 +210,7 @@ module ForemanMaintain::Scenarios
210
210
  Procedures::Backup::Online::ForemanDB,
211
211
  Procedures::Backup::Online::PulpcoreDB
212
212
  )
213
+ add_step_with_context(Procedures::Backup::Metadata, :online_backup => true)
213
214
  end
214
215
 
215
216
  def strategy
@@ -8,7 +8,10 @@ module ForemanMaintain::Scenarios
8
8
  end
9
9
 
10
10
  def compose
11
- add_step(Procedures::Content::Prepare)
11
+ # FIXME: remove this condition on next downstream upgrade scenario
12
+ if Procedures::Content::Prepare.present?
13
+ add_step(Procedures::Content::Prepare)
14
+ end
12
15
  end
13
16
  end
14
17
 
@@ -20,7 +23,10 @@ module ForemanMaintain::Scenarios
20
23
  end
21
24
 
22
25
  def compose
23
- add_step(Procedures::Content::Switchover)
26
+ # FIXME: remove this condition on next downstream upgrade scenario
27
+ if Procedures::Content::Switchover.present?
28
+ add_step(Procedures::Content::Switchover)
29
+ end
24
30
  end
25
31
  end
26
32
  end
@@ -1,7 +1,10 @@
1
1
  module ForemanMaintain::Scenarios
2
2
  module Packages
3
3
  def self.skip_installer_run?(packages_list)
4
- packages_list = packages_list.split(',').map(&:strip) if packages_list.is_a?(String)
4
+ if packages_list.is_a?(String)
5
+ packages_list = packages_list.split(',').map(&:strip)
6
+ end
7
+ packages_list ||= []
5
8
 
6
9
  return false unless packages_list.any? { |p| p.include?('foreman_maintain') }
7
10
  return true if packages_list.length == 1
@@ -20,6 +20,7 @@ module ForemanMaintain::Scenarios
20
20
  Checks::Restore::ValidateHostname,
21
21
  Procedures::Selinux::SetFileSecurity,
22
22
  Procedures::Restore::Configs)
23
+ add_step_with_context(Procedures::Crond::Stop) if feature(:cron)
23
24
  unless backup.incremental?
24
25
  add_steps_with_context(Procedures::Restore::EnsureMongoEngineMatches,
25
26
  Procedures::Restore::InstallerReset)
@@ -36,9 +37,12 @@ module ForemanMaintain::Scenarios
36
37
  end
37
38
  restore_mongo_dump(backup)
38
39
  add_steps_with_context(Procedures::Pulp::Migrate,
39
- Procedures::Pulpcore::Migrate,
40
- Procedures::Service::Start,
40
+ Procedures::Pulpcore::Migrate)
41
+
42
+ add_steps_with_context(Procedures::Restore::RegenerateQueues) if backup.online_backup?
43
+ add_steps_with_context(Procedures::Service::Start,
41
44
  Procedures::Service::DaemonReload)
45
+ add_step_with_context(Procedures::Crond::Start) if feature(:cron)
42
46
  end
43
47
  # rubocop:enable Metrics/MethodLength,Metrics/AbcSize
44
48
 
@@ -96,4 +100,15 @@ module ForemanMaintain::Scenarios
96
100
  Procedures::Selinux::SetFileSecurity => :incremental_backup)
97
101
  end
98
102
  end
103
+
104
+ class RestoreRescue < ForemanMaintain::Scenario
105
+ metadata do
106
+ description 'Resuce Restore backup'
107
+ manual_detection
108
+ end
109
+
110
+ def compose
111
+ add_step_with_context(Procedures::Crond::Stop) if feature(:cron)
112
+ end
113
+ end
99
114
  end
@@ -26,7 +26,7 @@ def _load_whitelist():
26
26
  continue
27
27
  _package_whitelist.add(line.rstrip().lower())
28
28
  llfile.close()
29
- except urlgrabber.grabber.URLGrabError, e:
29
+ except urlgrabber.grabber.URLGrabError as e:
30
30
  raise PluginYumExit('Unable to read Foreman protector"s configuration: %s' % e)
31
31
 
32
32
  def _add_obsoletes(conduit):
@@ -53,6 +53,8 @@ module ForemanMaintain
53
53
  }.freeze
54
54
 
55
55
  def setup(options = {})
56
+ set_home_environment
57
+
56
58
  # using a queue, we can log the messages which are generated before initializing logger
57
59
  self.config = Config.new(options)
58
60
  load_definitions
@@ -60,6 +62,10 @@ module ForemanMaintain
60
62
  update_path
61
63
  end
62
64
 
65
+ def set_home_environment
66
+ ENV['HOME'] ||= '/root'
67
+ end
68
+
63
69
  # Appending PATH with expected paths needed for commands we run
64
70
  def update_path
65
71
  paths = ['/sbin']
@@ -162,7 +168,7 @@ module ForemanMaintain
162
168
  ForemanMaintain.package_manager.update(main_package_name, :assumeyes => true)
163
169
  puts "\nThe #{package_name} package successfully updated."\
164
170
  "\nRe-run #{command} with required options!"
165
- exit 0
171
+ exit 75
166
172
  end
167
173
  puts "Nothing to update, can't find new version of #{package_name}."
168
174
  end
@@ -13,7 +13,8 @@ module ForemanMaintain
13
13
  :backup_dir => @backup_dir,
14
14
  :incremental_backup => @incremental || incremental_backup?
15
15
  )
16
- run_scenario(scenario)
16
+ rescue_scenario = Scenarios::RestoreRescue.new
17
+ run_scenario(scenario, rescue_scenario)
17
18
  exit runner.exit_code
18
19
  end
19
20
 
@@ -82,7 +82,7 @@ module ForemanMaintain
82
82
  tar_options = {
83
83
  :archive => backup_file,
84
84
  :command => 'create',
85
- :transform => 's,^,var/lib/pgsql/data/,S',
85
+ :transform => "s,^,#{data_dir[1..-1]},S",
86
86
  :files => '*'
87
87
  }.merge(extra_tar_options)
88
88
  feature(:tar).run(tar_options)
@@ -97,23 +97,19 @@ module ForemanMaintain
97
97
  end
98
98
 
99
99
  def common_repos(rh_version_major, full_version)
100
- repos_arrary = common_repos_array(rh_version_major, full_version)
100
+ repos_arrary = if ENV['FOREMAN_MAINTAIN_USE_BETA'] == '1'
101
+ ["rhel-#{rh_version_major}-server-satellite-maintenance-6-beta-rpms",
102
+ "rhel-#{rh_version_major}-server-satellite-tools-6-beta-rpms"]
103
+ else
104
+ ["rhel-#{rh_version_major}-server-satellite-maintenance-6-rpms",
105
+ "rhel-#{rh_version_major}-server-satellite-tools-#{full_version}-rpms"]
106
+ end
107
+
101
108
  return repos_arrary.first(1) if feature(:capsule)
102
109
 
103
110
  repos_arrary
104
111
  end
105
112
 
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'
113
-
114
- nil
115
- end
116
-
117
113
  def main_rh_repos(rh_version_major)
118
114
  ["rhel-#{rh_version_major}-server-rpms",
119
115
  "rhel-server-rhscl-#{rh_version_major}-rpms"]
@@ -204,6 +204,10 @@ module ForemanMaintain
204
204
  def incremental?
205
205
  !!metadata.fetch('incremental', false)
206
206
  end
207
+
208
+ def online_backup?
209
+ !!metadata.fetch('online', false)
210
+ end
207
211
  end
208
212
  end
209
213
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '0.6.4'.freeze
2
+ VERSION = '0.6.9'.freeze
3
3
  end
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: 0.6.4
4
+ version: 0.6.9
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: 2020-05-27 00:00:00.000000000 Z
11
+ date: 2020-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -126,6 +126,7 @@ files:
126
126
  - definitions/checks/check_tmout.rb
127
127
  - definitions/checks/disk/available_space.rb
128
128
  - definitions/checks/disk/performance.rb
129
+ - definitions/checks/env_proxy.rb
129
130
  - definitions/checks/foreman/check_corrupted_roles.rb
130
131
  - definitions/checks/foreman/check_duplicate_roles.rb
131
132
  - definitions/checks/foreman/db_up.rb
@@ -133,6 +134,7 @@ files:
133
134
  - definitions/checks/foreman/puppet_class_duplicates.rb
134
135
  - definitions/checks/foreman/validate_external_db_version.rb
135
136
  - definitions/checks/foreman_openscap/invalid_report_associations.rb
137
+ - definitions/checks/foreman_proxy/check_tftp_storage.rb
136
138
  - definitions/checks/foreman_proxy/verify_dhcp_config_syntax.rb
137
139
  - definitions/checks/foreman_tasks/invalid/check_old.rb
138
140
  - definitions/checks/foreman_tasks/invalid/check_pending_state.rb
@@ -265,6 +267,7 @@ files:
265
267
  - definitions/procedures/restore/pg_global_objects.rb
266
268
  - definitions/procedures/restore/postgres_owner.rb
267
269
  - definitions/procedures/restore/pulpcore_dump.rb
270
+ - definitions/procedures/restore/regenerate_queues.rb
268
271
  - definitions/procedures/selinux/set_file_security.rb
269
272
  - definitions/procedures/service/base.rb
270
273
  - definitions/procedures/service/daemon_reload.rb
@@ -283,8 +286,6 @@ files:
283
286
  - definitions/scenarios/packages.rb
284
287
  - definitions/scenarios/restore.rb
285
288
  - definitions/scenarios/services.rb
286
- - definitions/scenarios/upgrade_to_capsule_6_7.rb
287
- - definitions/scenarios/upgrade_to_capsule_6_7_z.rb
288
289
  - definitions/scenarios/upgrade_to_capsule_6_8.rb
289
290
  - definitions/scenarios/upgrade_to_capsule_6_8_z.rb
290
291
  - definitions/scenarios/upgrade_to_satellite_6_2.rb
@@ -400,7 +401,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
400
401
  - !ruby/object:Gem::Version
401
402
  version: '0'
402
403
  requirements: []
403
- rubygems_version: 3.0.8
404
+ rubygems_version: 3.0.3
404
405
  signing_key:
405
406
  specification_version: 4
406
407
  summary: Foreman maintenance tool belt
@@ -1,88 +0,0 @@
1
- module Scenarios::Capsule_6_7
2
- class Abstract < ForemanMaintain::Scenario
3
- def self.upgrade_metadata(&block)
4
- metadata do
5
- tags :upgrade_scenario
6
- confine do
7
- feature(:capsule) &&
8
- (feature(:capsule).current_minor_version == '6.6' || \
9
- ForemanMaintain.upgrade_in_progress == '6.7')
10
- end
11
- instance_eval(&block)
12
- end
13
- end
14
-
15
- def target_version
16
- '6.7'
17
- end
18
- end
19
-
20
- class PreUpgradeCheck < Abstract
21
- upgrade_metadata do
22
- description 'Checks before upgrading to Capsule 6.7'
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.7'))
31
- end
32
- end
33
-
34
- class PreMigrations < Abstract
35
- upgrade_metadata do
36
- description 'Procedures before migrating to Capsule 6.7'
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 Capsule 6.7'
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.7'))
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 Capsule 6.7'
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 Capsule 6.7'
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
@@ -1,88 +0,0 @@
1
- module Scenarios::Capsule_6_7_z
2
- class Abstract < ForemanMaintain::Scenario
3
- def self.upgrade_metadata(&block)
4
- metadata do
5
- tags :upgrade_scenario
6
- confine do
7
- feature(:capsule) &&
8
- (feature(:capsule).current_minor_version == '6.7' || \
9
- ForemanMaintain.upgrade_in_progress == '6.7.z')
10
- end
11
- instance_eval(&block)
12
- end
13
- end
14
-
15
- def target_version
16
- '6.7.z'
17
- end
18
- end
19
-
20
- class PreUpgradeCheck < Abstract
21
- upgrade_metadata do
22
- description 'Checks before upgrading to Capsule 6.7.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.7'))
31
- end
32
- end
33
-
34
- class PreMigrations < Abstract
35
- upgrade_metadata do
36
- description 'Procedures before migrating to Capsule 6.7.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 Capsule 6.7.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.7'))
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 Capsule 6.7.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 Capsule 6.7.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