foreman_maintain 0.6.8 → 0.6.13

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 +55 -10
  3. data/bin/foreman-maintain-complete +3 -2
  4. data/definitions/checks/env_proxy.rb +1 -1
  5. data/definitions/checks/foreman/check_checkpoint_segments.rb +51 -0
  6. data/definitions/checks/foreman/check_duplicate_permission.rb +33 -0
  7. data/definitions/checks/foreman_proxy/check_tftp_storage.rb +2 -3
  8. data/definitions/checks/foreman_proxy/verify_dhcp_config_syntax.rb +7 -9
  9. data/definitions/features/foreman_proxy.rb +7 -5
  10. data/definitions/features/installer.rb +4 -0
  11. data/definitions/procedures/backup/prepare_directory.rb +8 -1
  12. data/definitions/procedures/content/prepare.rb +5 -0
  13. data/definitions/procedures/content/switchover.rb +5 -0
  14. data/definitions/procedures/foreman/remove_duplicate_permissions.rb +70 -0
  15. data/definitions/procedures/installer/upgrade.rb +1 -1
  16. data/definitions/procedures/installer/upgrade_rake_task.rb +11 -0
  17. data/definitions/procedures/packages/locking_status.rb +1 -1
  18. data/definitions/scenarios/content.rb +8 -2
  19. data/definitions/scenarios/upgrade_to_satellite_6_8.rb +2 -0
  20. data/definitions/scenarios/upgrade_to_satellite_6_8_z.rb +1 -0
  21. data/extras/foreman_protector/foreman-protector.py +1 -1
  22. data/extras/foreman_protector/foreman-protector.whitelist +1 -0
  23. data/lib/foreman_maintain.rb +7 -1
  24. data/lib/foreman_maintain/cli.rb +2 -2
  25. data/lib/foreman_maintain/cli/packages_command.rb +1 -1
  26. data/lib/foreman_maintain/cli/upgrade_command.rb +3 -0
  27. data/lib/foreman_maintain/concerns/base_database.rb +1 -1
  28. data/lib/foreman_maintain/concerns/downstream.rb +4 -2
  29. data/lib/foreman_maintain/reporter/cli_reporter.rb +1 -1
  30. data/lib/foreman_maintain/runner.rb +1 -0
  31. data/lib/foreman_maintain/scenario.rb +5 -2
  32. data/lib/foreman_maintain/version.rb +1 -1
  33. metadata +7 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db720ab5cd56f2afbb74ccd75c4f8a479f2a4547c419b3b0f7b6d937e4df475a
4
- data.tar.gz: b97c27565dc68d5395c4b163486d3c2758de583faae7282934608d66d9230dd1
3
+ metadata.gz: 0a459203e886ab2569e44fe1248dcc5e678e9cb2752bee8d6ff1454687a3811b
4
+ data.tar.gz: 94d4ef1cd297ed24fde199194215e2ab5f1b799ec33b60335e1dc94835a9b48b
5
5
  SHA512:
6
- metadata.gz: 155e47d65bd4d8d0355e6a60133ddf4a14dd2c2604dfa5e793412e7bb07d9eb9df457f91d889396fd42ed6c9abd0a8347b6ae18afa51428567d8dfddee698489
7
- data.tar.gz: 52ca518f6fad0fa372d8a7a132858b4503580e016024996efdb06fda7eab4672fd23e9074c3127e15459606aab256ea6f7ff7538c57fe7f23ea2fb41b69f4c9e
6
+ metadata.gz: cc7422d890bf9637fa08f6efd8c8f5877371d14575746cd2d0e79771fe98aac99edd0aa8a591f86ff236f300723e1507e4dbae41c0d996d81049f31e187d2289
7
+ data.tar.gz: 24a5d18d3154143f4091777dd57f2f162736d1fdf83e1327062029f36601e78e48c6ca7feb1f812d7e1a5350de2634136dee07eb3eff22012810cf28982448e9
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,9 +485,18 @@ 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
 
491
+ ## Exit codes with special meanings -
492
+
493
+ Every command returns an exit code. Any other exit status than 0 indicates a failure of some kind. Foreman Maintain uses following exit codes with special meaning.
494
+
495
+ | Exit Code | Description |
496
+ | -----------| -----------------------------------|
497
+ | 75 | Temporary failure and needs re-run |
498
+ | 78 | Command executed with warning(s) |
499
+
455
500
  ## How to contribute?
456
501
 
457
502
  Generally, follow the [Foreman guidelines](https://theforeman.org/contribute.html). For code-related contributions, fork this project and send a pull request with all changes. Some things to keep in mind:
@@ -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
@@ -8,6 +8,6 @@ class Checks::EnvProxy < ForemanMaintain::Check
8
8
  def run
9
9
  variables = %w[http_proxy https_proxy HTTP_PROXY HTTPS_PROXY]
10
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!')
11
+ assert(!has_proxy_set, 'Global HTTP(S) proxy in environment (env) is set. Please unset first!')
12
12
  end
13
13
  end
@@ -0,0 +1,51 @@
1
+ module Checks
2
+ module Foreman
3
+ class CheckpointSegments < ForemanMaintain::Check
4
+ metadata do
5
+ label :check_postgresql_checkpoint_segments
6
+ description 'Check if checkpoint_segments configuration exists on the system'
7
+ confine do
8
+ feature(:foreman) && feature(:installer) &&
9
+ File.exist?(feature(:installer).custom_hiera_file)
10
+ end
11
+ end
12
+
13
+ def run
14
+ failure_message = check_custom_hiera
15
+ fail! failure_message if failure_message
16
+ end
17
+
18
+ # rubocop:disable Metrics/MethodLength
19
+ def check_custom_hiera
20
+ hiera_file = feature(:installer).custom_hiera_file
21
+ if (config = YAML.load_file(hiera_file)) &&
22
+ config.key?('postgresql::server::config_entries')
23
+ if config['postgresql::server::config_entries'].nil?
24
+ return <<-MESSAGE.strip_heredoc
25
+ ERROR: 'postgresql::server::config_entries' cannot be null.
26
+ Please remove it from following file and re-run the command.
27
+ - #{hiera_file}
28
+ MESSAGE
29
+ elsif config['postgresql::server::config_entries'].key?('checkpoint_segments')
30
+ message = <<-MESSAGE.strip_heredoc
31
+ ERROR: Tuning option 'checkpoint_segments' found.
32
+ This option is no longer valid for PostgreSQL 9.5 or newer.
33
+ Please remove it from following file and re-run the command.
34
+ - #{hiera_file}
35
+ MESSAGE
36
+ if feature(:katello)
37
+ message += <<-MESSAGE.strip_heredoc
38
+ The presence of checkpoint_segments in #{hiera_file} indicates manual tuning.
39
+ Manual tuning can override values provided by the --tuning parameter.
40
+ Review #{hiera_file} for values that are already provided by the built in tuning profiles.
41
+ Built in tuning profiles also provide a supported upgrade path.
42
+ MESSAGE
43
+ end
44
+ return message
45
+ end
46
+ end
47
+ end
48
+ # rubocop:enable Metrics/MethodLength
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,33 @@
1
+ module Checks
2
+ module Foreman
3
+ class CheckDuplicatePermissions < ForemanMaintain::Check
4
+ metadata do
5
+ label :duplicate_permissions
6
+ for_feature :foreman_database
7
+ description 'Check for duplicate permissions from database'
8
+ tags :pre_upgrade
9
+ end
10
+
11
+ def run
12
+ duplicate_permissions = find_duplicate_permissions
13
+ assert(
14
+ duplicate_permissions.empty?,
15
+ 'Duplicate permissions in your database',
16
+ :next_steps => [
17
+ Procedures::Foreman::RemoveDuplicatePermissions.new
18
+ ]
19
+ )
20
+ end
21
+
22
+ def find_duplicate_permissions
23
+ feature(:foreman_database).query(self.class.query_to_get_duplicate_permission)
24
+ end
25
+
26
+ def self.query_to_get_duplicate_permission
27
+ <<-SQL
28
+ SELECT id,name FROM permissions p WHERE (SELECT count(name) FROM permissions pr WHERE p.name =pr.name) > 1
29
+ SQL
30
+ end
31
+ end
32
+ end
33
+ end
@@ -22,10 +22,9 @@ module Checks::ForemanProxy
22
22
  end
23
23
 
24
24
  def old_files_from_tftp_boot
25
- Dir.entries(tftp_boot_directory).map do |file|
25
+ Dir.glob("#{tftp_boot_directory}*-{vmlinuz,initrd.img}").map do |file|
26
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
27
+ file if File.mtime(file) + (token_duration * 60) < Time.now
29
28
  end
30
29
  end.compact
31
30
  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
@@ -101,7 +101,9 @@ class Features::ForemanProxy < ForemanMaintain::Feature
101
101
  end
102
102
 
103
103
  def certs_tar
104
- 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
105
107
  end
106
108
 
107
109
  def settings_file
@@ -120,6 +122,10 @@ class Features::ForemanProxy < ForemanMaintain::Feature
120
122
  @tftp_root_directory ||= lookup_tftp_root_directory
121
123
  end
122
124
 
125
+ def dhcp_isc_provider?
126
+ configs_from_dhcp_yml[:use_provider] == 'dhcp_isc'
127
+ end
128
+
123
129
  private
124
130
 
125
131
  def backup_features(for_features)
@@ -227,10 +233,6 @@ class Features::ForemanProxy < ForemanMaintain::Feature
227
233
  @configs_from_dhcp_yml ||= yaml_load(dhcp_yml_path)
228
234
  end
229
235
 
230
- def dhcp_isc_provider?
231
- configs_from_dhcp_yml[:use_provider] == 'dhcp_isc'
232
- end
233
-
234
236
  def lookup_using_dhcp_yml
235
237
  if configs_from_dhcp_yml.key?(:dhcp_config)
236
238
  return configs_from_dhcp_yml[:dhcp_config]
@@ -53,6 +53,10 @@ class Features::Installer < ForemanMaintain::Feature
53
53
  end
54
54
  end
55
55
 
56
+ def custom_hiera_file
57
+ @custom_hiera_file ||= File.join(config_directory, 'custom-hiera.yaml')
58
+ end
59
+
56
60
  def can_upgrade?
57
61
  @installer_type == :scenarios || @installer_type == :legacy_katello
58
62
  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
@@ -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
@@ -0,0 +1,70 @@
1
+ module Procedures::Foreman
2
+ class RemoveDuplicatePermissions < ForemanMaintain::Procedure
3
+ metadata do
4
+ for_feature :foreman_database
5
+ description 'Remove duplicate permissions from database'
6
+ end
7
+
8
+ def run
9
+ duplicate_permissions = feature(:foreman_database).query(
10
+ Checks::Foreman::CheckDuplicatePermissions.query_to_get_duplicate_permission
11
+ ).group_by { |permission| permission['name'] }
12
+ unassigned_permissions = []
13
+ duplicate_permissions.each_value do |permissions|
14
+ permission_ids = permissions.map { |i| i['id'] }
15
+ filterings = check_permissions_assign_to_filter(permission_ids)
16
+ assigned_permissions = filterings.keys
17
+ unassigned_permissions << permission_ids - assigned_permissions
18
+ fix_permissions(assigned_permissions) if assigned_permissions.length > 1
19
+ end
20
+ delete_permission(unassigned_permissions.flatten) unless unassigned_permissions.empty?
21
+ end
22
+
23
+ private
24
+
25
+ def check_permissions_assign_to_filter(permission_ids)
26
+ sql = <<-SQL
27
+ SELECT id, filter_id, permission_id FROM filterings WHERE permission_id IN (#{permission_ids.join(',')})
28
+ SQL
29
+ feature(:foreman_database).query(sql).group_by { |filtering| filtering['permission_id'] }
30
+ end
31
+
32
+ def fix_permissions(assigned_permissions)
33
+ persist_permission = assigned_permissions.shift
34
+ filter_ids = filters_for_permission(persist_permission)
35
+ update_filtering(assigned_permissions, persist_permission, filter_ids)
36
+ delete_filtering(assigned_permissions)
37
+ delete_permission(assigned_permissions)
38
+ end
39
+
40
+ def filters_for_permission(permission)
41
+ feature(:foreman_database).query(
42
+ "SELECT filter_id FROM filterings WHERE permission_id = #{permission.to_i}"
43
+ ).map { |filter| filter['filter_id'] }
44
+ end
45
+
46
+ def update_filtering(old_ids, new_id, filter_ids)
47
+ sql = <<-SQL
48
+ WITH rows AS (
49
+ UPDATE filterings SET permission_id = '#{new_id}' WHERE permission_id IN (#{old_ids.join(',')}) AND filter_id NOT IN (#{filter_ids.join(',')})
50
+ RETURNING id
51
+ )
52
+ SELECT id
53
+ FROM rows
54
+ SQL
55
+ feature(:foreman_database).query(sql)
56
+ end
57
+
58
+ def delete_filtering(permission_ids)
59
+ feature(:foreman_database).psql(
60
+ "DELETE FROM filterings where permission_id IN (#{permission_ids.join(',')})"
61
+ )
62
+ end
63
+
64
+ def delete_permission(permission_ids)
65
+ feature(:foreman_database).psql(
66
+ "DELETE FROM permissions where id IN (#{permission_ids.join(',')})"
67
+ )
68
+ end
69
+ end
70
+ end
@@ -6,7 +6,7 @@ module Procedures::Installer
6
6
 
7
7
  def run
8
8
  assumeyes_val = @assumeyes.nil? ? assumeyes? : @assumeyes
9
- feature(:installer).run(@arguments, :interactive => !assumeyes_val)
9
+ feature(:installer).upgrade(:interactive => !assumeyes_val)
10
10
  end
11
11
  end
12
12
  end
@@ -0,0 +1,11 @@
1
+ module Procedures::Installer
2
+ class UpgradeRakeTask < ForemanMaintain::Procedure
3
+ metadata do
4
+ description 'Execute upgrade:run rake task'
5
+ end
6
+
7
+ def run
8
+ execute!('foreman-rake upgrade:run')
9
+ end
10
+ end
11
+ 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
@@ -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
@@ -27,6 +27,7 @@ module Scenarios::Satellite_6_8
27
27
  def compose
28
28
  add_steps(find_checks(:default))
29
29
  add_steps(find_checks(:pre_upgrade))
30
+ add_step(Checks::Foreman::CheckpointSegments)
30
31
  add_step(Checks::Repositories::Validate.new(:version => '6.8'))
31
32
  end
32
33
  end
@@ -58,6 +59,7 @@ module Scenarios::Satellite_6_8
58
59
  add_step(Procedures::Packages::UnlockVersions.new)
59
60
  add_step(Procedures::Packages::Update.new(:assumeyes => true))
60
61
  add_step_with_context(Procedures::Installer::Upgrade)
62
+ add_step(Procedures::Installer::UpgradeRakeTask)
61
63
  end
62
64
  end
63
65
 
@@ -58,6 +58,7 @@ module Scenarios::Satellite_6_8_z
58
58
  add_step(Procedures::Packages::UnlockVersions.new)
59
59
  add_step(Procedures::Packages::Update.new(:assumeyes => true))
60
60
  add_step_with_context(Procedures::Installer::Upgrade)
61
+ add_step(Procedures::Installer::UpgradeRakeTask)
61
62
  end
62
63
  end
63
64
 
@@ -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):
@@ -16,5 +16,6 @@ rdma-core
16
16
  boost-random
17
17
  boost-iostreams
18
18
  boost-thread
19
+ yum-utils
19
20
  # foreman-maintain
20
21
  rubygem-foreman_maintain
@@ -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
@@ -57,7 +57,7 @@ module ForemanMaintain
57
57
  raise error
58
58
  end
59
59
 
60
- puts error.message
60
+ $stderr.puts error.message
61
61
  logger.error(error)
62
62
 
63
63
  @exit_code = 1
@@ -65,7 +65,7 @@ module ForemanMaintain
65
65
 
66
66
  def process_usage_error(error)
67
67
  log_exit_code_info(1)
68
- puts error.message
68
+ $stderr.puts error.message
69
69
  exit!
70
70
  end
71
71
  end
@@ -38,7 +38,7 @@ module ForemanMaintain
38
38
 
39
39
  subcommand 'update', 'Update packages in an unlocked session' do
40
40
  interactive_option
41
- parameter '[PACKAGES ...]', 'packages to update', :attribute_name => :packages
41
+ parameter '[PACKAGES] ...', 'packages to update', :attribute_name => :packages
42
42
 
43
43
  def execute
44
44
  run_scenarios_and_exit(
@@ -53,7 +53,10 @@ module ForemanMaintain
53
53
  end
54
54
 
55
55
  subcommand 'list-versions', 'List versions this system is upgradable to' do
56
+ disable_self_upgrade_option
57
+
56
58
  def execute
59
+ ForemanMaintain.perform_self_upgrade unless disable_self_upgrade?
57
60
  print_versions(UpgradeRunner.available_targets)
58
61
  end
59
62
  end
@@ -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)
@@ -72,7 +72,9 @@ module ForemanMaintain
72
72
  end
73
73
 
74
74
  def ansible_repo(server_version, rh_version_major)
75
- if server_version >= version('6.6')
75
+ if server_version >= version('6.8')
76
+ "rhel-#{rh_version_major}-server-ansible-2.9-rpms"
77
+ elsif server_version >= version('6.6')
76
78
  "rhel-#{rh_version_major}-server-ansible-2.8-rpms"
77
79
  elsif server_version >= version('6.4')
78
80
  "rhel-#{rh_version_major}-server-ansible-2.6-rpms"
@@ -105,7 +107,7 @@ module ForemanMaintain
105
107
  "rhel-#{rh_version_major}-server-satellite-tools-#{full_version}-rpms"]
106
108
  end
107
109
 
108
- return repos_arrary.first(1) if feature(:capsule)
110
+ return repos_arrary.first(1) if feature(:satellite)
109
111
 
110
112
  repos_arrary
111
113
  end
@@ -276,7 +276,7 @@ module ForemanMaintain
276
276
 
277
277
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
278
278
  def scenario_failure_message(scenario)
279
- return if scenario.passed?
279
+ return if scenario.passed? && !scenario.warning?
280
280
  message = []
281
281
  message << <<-MESSAGE.strip_heredoc
282
282
  Scenario [#{scenario.description}] failed.
@@ -54,6 +54,7 @@ module ForemanMaintain
54
54
  @last_scenario = scenario
55
55
  @last_scenario_continuation_confirmed = false
56
56
  end
57
+ @exit_code = 78 if scenario.warning?
57
58
  @exit_code = 1 if scenario.failed?
58
59
  end
59
60
 
@@ -129,8 +129,11 @@ module ForemanMaintain
129
129
 
130
130
  def passed?
131
131
  (steps_with_abort(:whitelisted => false) +
132
- steps_with_error(:whitelisted => false) +
133
- steps_with_warning(:whitelisted => false)).empty?
132
+ steps_with_error(:whitelisted => false)).empty?
133
+ end
134
+
135
+ def warning?
136
+ !steps_with_warning(:whitelisted => false).empty?
134
137
  end
135
138
 
136
139
  def failed?
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '0.6.8'.freeze
2
+ VERSION = '0.6.13'.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.8
4
+ version: 0.6.13
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-07-08 00:00:00.000000000 Z
11
+ date: 2020-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -127,7 +127,9 @@ files:
127
127
  - definitions/checks/disk/available_space.rb
128
128
  - definitions/checks/disk/performance.rb
129
129
  - definitions/checks/env_proxy.rb
130
+ - definitions/checks/foreman/check_checkpoint_segments.rb
130
131
  - definitions/checks/foreman/check_corrupted_roles.rb
132
+ - definitions/checks/foreman/check_duplicate_permission.rb
131
133
  - definitions/checks/foreman/check_duplicate_roles.rb
132
134
  - definitions/checks/foreman/db_up.rb
133
135
  - definitions/checks/foreman/facts_names.rb
@@ -226,6 +228,7 @@ files:
226
228
  - definitions/procedures/foreman/apipie_cache.rb
227
229
  - definitions/procedures/foreman/fix_corrupted_roles.rb
228
230
  - definitions/procedures/foreman/remove_duplicate_obsolete_roles.rb
231
+ - definitions/procedures/foreman/remove_duplicate_permissions.rb
229
232
  - definitions/procedures/foreman_docker/remove_foreman_docker.rb
230
233
  - definitions/procedures/foreman_openscap/invalid_report_associations.rb
231
234
  - definitions/procedures/foreman_proxy/features.rb
@@ -236,6 +239,7 @@ files:
236
239
  - definitions/procedures/hammer_setup.rb
237
240
  - definitions/procedures/installer/run.rb
238
241
  - definitions/procedures/installer/upgrade.rb
242
+ - definitions/procedures/installer/upgrade_rake_task.rb
239
243
  - definitions/procedures/iptables/add_maintenance_mode_chain.rb
240
244
  - definitions/procedures/iptables/remove_maintenance_mode_chain.rb
241
245
  - definitions/procedures/knowledge_base_article.rb
@@ -401,7 +405,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
401
405
  - !ruby/object:Gem::Version
402
406
  version: '0'
403
407
  requirements: []
404
- rubygems_version: 3.0.8
408
+ rubygems_version: 3.0.3
405
409
  signing_key:
406
410
  specification_version: 4
407
411
  summary: Foreman maintenance tool belt