foreman_maintain 0.6.16 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/definitions/checks/package_manager/yum/validate_yum_config.rb +51 -0
  4. data/definitions/features/candlepin.rb +0 -4
  5. data/definitions/features/dynflow_sidekiq.rb +4 -7
  6. data/definitions/features/pulpcore.rb +23 -6
  7. data/definitions/procedures/backup/accessibility_confirmation.rb +1 -1
  8. data/definitions/procedures/backup/online/safety_confirmation.rb +1 -1
  9. data/definitions/procedures/backup/snapshot/logical_volume_confirmation.rb +1 -1
  10. data/definitions/procedures/content/migration_stats.rb +12 -0
  11. data/definitions/procedures/content/prepare.rb +0 -5
  12. data/definitions/procedures/content/prepare_abort.rb +12 -0
  13. data/definitions/procedures/content/switchover.rb +1 -1
  14. data/definitions/procedures/packages/installer_confirmation.rb +1 -1
  15. data/definitions/procedures/packages/update_all_confirmation.rb +1 -1
  16. data/definitions/procedures/prep_6_10_upgrade.rb +31 -0
  17. data/definitions/procedures/restore/confirmation.rb +1 -1
  18. data/definitions/procedures/restore/installer_reset.rb +10 -1
  19. data/definitions/procedures/service/list.rb +2 -12
  20. data/definitions/scenarios/content.rb +50 -3
  21. data/definitions/scenarios/prep_6_10_upgrade.rb +13 -0
  22. data/definitions/scenarios/upgrade_to_capsule_6_9.rb +88 -0
  23. data/definitions/scenarios/upgrade_to_capsule_6_9_z.rb +88 -0
  24. data/definitions/scenarios/upgrade_to_satellite_6_9.rb +90 -0
  25. data/definitions/scenarios/upgrade_to_satellite_6_9_z.rb +89 -0
  26. data/lib/foreman_maintain.rb +1 -3
  27. data/lib/foreman_maintain/cli.rb +9 -0
  28. data/lib/foreman_maintain/cli/content_command.rb +17 -2
  29. data/lib/foreman_maintain/cli/upgrade_command.rb +0 -3
  30. data/lib/foreman_maintain/concerns/downstream.rb +4 -0
  31. data/lib/foreman_maintain/reporter.rb +18 -13
  32. data/lib/foreman_maintain/reporter/cli_reporter.rb +18 -9
  33. data/lib/foreman_maintain/runner.rb +6 -4
  34. data/lib/foreman_maintain/scenario.rb +4 -0
  35. data/lib/foreman_maintain/utils/disk/io_device.rb +0 -4
  36. data/lib/foreman_maintain/utils/service/systemd.rb +12 -3
  37. data/lib/foreman_maintain/version.rb +1 -1
  38. metadata +11 -5
  39. data/definitions/checks/disk/available_space_candlepin.rb +0 -27
  40. data/definitions/checks/yum_exclude.rb +0 -21
  41. data/lib/foreman_maintain/concerns/primary_checks.rb +0 -23
@@ -54,6 +54,10 @@ module ForemanMaintain
54
54
  raise NotImplementedError
55
55
  end
56
56
 
57
+ def fm_pkg_and_cmd_name
58
+ %w[satellite-maintain satellite-maintain]
59
+ end
60
+
57
61
  private
58
62
 
59
63
  def rh_repos(server_version)
@@ -22,12 +22,13 @@ module ForemanMaintain
22
22
 
23
23
  def after_scenario_finishes(_scenario); end
24
24
 
25
- def on_next_steps(steps)
25
+ def on_next_steps(steps, run_strategy = :fail_fast)
26
26
  return if steps.empty?
27
+
27
28
  if steps.size > 1
28
- multiple_steps_decision(steps)
29
+ multiple_steps_decision(steps, run_strategy)
29
30
  else
30
- single_step_decision(steps.first)
31
+ single_step_decision(steps.first, run_strategy)
31
32
  end
32
33
  end
33
34
 
@@ -46,17 +47,19 @@ module ForemanMaintain
46
47
  end
47
48
 
48
49
  # simple yes/no question, returns :yes, :no or :quit
49
- def ask_decision(message, options = {})
50
- options.validate_options!(:assumeyes)
51
- assumeyes = options.fetch(:assumeyes, assumeyes?)
50
+ # rubocop:disable Metrics/LineLength
51
+ def ask_decision(message, actions_msg: 'y(yes), n(no), q(quit)', assumeyes: assumeyes?, run_strategy: :fail_fast)
52
+ actions_msg = 'y(yes), n(no)' if run_strategy == :fail_slow
52
53
  if assumeyes
53
54
  print("#{message} (assuming yes)")
54
55
  return :yes
55
56
  end
57
+
56
58
  until_valid_decision do
57
- filter_decision(ask("#{message}, [y(yes), n(no), q(quit)]"))
59
+ filter_decision(ask("#{message}, [#{actions_msg}]"))
58
60
  end
59
61
  end
62
+ # rubocop:enable Metrics/LineLength
60
63
 
61
64
  def assumeyes=(assume)
62
65
  @assumeyes = !!assume
@@ -64,8 +67,8 @@ module ForemanMaintain
64
67
 
65
68
  private
66
69
 
67
- def single_step_decision(step)
68
- answer = ask_decision("Continue with step [#{step.description}]?")
70
+ def single_step_decision(step, run_strategy)
71
+ answer = ask_decision("Continue with step [#{step.description}]?", run_strategy: run_strategy)
69
72
  if answer == :yes
70
73
  step
71
74
  else
@@ -73,12 +76,12 @@ module ForemanMaintain
73
76
  end
74
77
  end
75
78
 
76
- def multiple_steps_decision(steps)
79
+ def multiple_steps_decision(steps, run_strategy)
77
80
  puts 'There are multiple steps to proceed:'
78
81
  steps.each_with_index do |step, index|
79
82
  puts "#{index + 1}) #{step.description}"
80
83
  end
81
- ask_to_select('Select step to continue', steps, &:description)
84
+ ask_to_select('Select step to continue', steps, run_strategy)
82
85
  end
83
86
 
84
87
  def filter_decision(answer)
@@ -90,13 +93,15 @@ module ForemanMaintain
90
93
  end
91
94
 
92
95
  # rubocop:disable Metrics/MethodLength
93
- def ask_to_select(message, steps)
96
+ def ask_to_select(message, steps, run_strategy)
94
97
  if assumeyes?
95
98
  puts('(assuming first option)')
96
99
  return steps.first
97
100
  end
98
101
  until_valid_decision do
99
- answer = ask("#{message}, [n(next), q(quit)]")
102
+ actions = run_strategy == :fail_slow ? 'n(next)' : 'n(next), q(quit)'
103
+
104
+ answer = ask("#{message}, [#{actions}]")
100
105
  if answer =~ /^\d+$/ && (answer.to_i - 1) < steps.size
101
106
  steps[answer.to_i - 1]
102
107
  else
@@ -167,8 +167,9 @@ module ForemanMaintain
167
167
  @assumeyes
168
168
  end
169
169
 
170
- def single_step_decision(step)
171
- answer = ask_decision("Continue with step [#{step.runtime_message}]?")
170
+ def single_step_decision(step, run_strategy)
171
+ answer = ask_decision("Continue with step [#{step.runtime_message}]?",
172
+ run_strategy: run_strategy)
172
173
  if answer == :yes
173
174
  step
174
175
  else
@@ -176,25 +177,28 @@ module ForemanMaintain
176
177
  end
177
178
  end
178
179
 
179
- def multiple_steps_decision(steps)
180
+ def multiple_steps_decision(steps, run_strategy)
180
181
  puts 'There are multiple steps to proceed:'
181
182
  steps.each_with_index do |step, index|
182
183
  puts "#{index + 1}) #{step.runtime_message}"
183
184
  end
184
- ask_to_select('Select step to continue', steps, &:runtime_message)
185
+ ask_to_select('Select step to continue', steps, run_strategy)
185
186
  end
186
187
 
187
- def ask_decision(message, options = 'y(yes), n(no), q(quit)', ignore_assumeyes: false)
188
+ # rubocop:disable Metrics/LineLength
189
+ def ask_decision(message, actions_msg: 'y(yes), n(no), q(quit)', ignore_assumeyes: false, run_strategy: :fail_fast)
190
+ actions_msg = 'y(yes), n(no)' if run_strategy == :fail_slow
188
191
  if !ignore_assumeyes && assumeyes?
189
192
  print("#{message} (assuming yes)\n")
190
193
  return :yes
191
194
  end
192
195
  until_valid_decision do
193
- filter_decision(ask("#{message}, [#{options}]"))
196
+ filter_decision(ask("#{message}, [#{actions_msg}]"))
194
197
  end
195
198
  ensure
196
199
  clear_line
197
200
  end
201
+ # rubocop:enable Metrics/LineLength
198
202
 
199
203
  def filter_decision(answer)
200
204
  decision = nil
@@ -206,13 +210,15 @@ module ForemanMaintain
206
210
  end
207
211
 
208
212
  # rubocop:disable Metrics/MethodLength
209
- def ask_to_select(message, steps)
213
+ def ask_to_select(message, steps, run_strategy)
210
214
  if assumeyes?
211
215
  puts('(assuming first option)')
212
216
  return steps.first
213
217
  end
218
+
214
219
  until_valid_decision do
215
- answer = ask("#{message}, [n(next), q(quit)]")
220
+ actions = run_strategy == :fail_slow ? 'n(next)' : 'n(next), q(quit)'
221
+ answer = ask("#{message}, [#{actions}]")
216
222
  if answer =~ /^\d+$/ && (answer.to_i - 1) < steps.size
217
223
  steps[answer.to_i - 1]
218
224
  else
@@ -277,6 +283,7 @@ module ForemanMaintain
277
283
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
278
284
  def scenario_failure_message(scenario)
279
285
  return if scenario.passed? && !scenario.warning?
286
+
280
287
  message = []
281
288
  message << <<-MESSAGE.strip_heredoc
282
289
  Scenario [#{scenario.description}] failed.
@@ -293,13 +300,15 @@ module ForemanMaintain
293
300
  end
294
301
 
295
302
  steps_with_error = scenario.steps_with_error(:whitelisted => false)
303
+ steps_with_skipped = scenario.steps_with_skipped(:whitelisted => true)
304
+ steps_to_whitelist = steps_with_error + steps_with_skipped
296
305
  unless steps_with_error.empty?
297
306
  message << format(<<-MESSAGE.strip_heredoc, format_steps(steps_with_error, "\n", 2))
298
307
  The following steps ended up in failing state:
299
308
 
300
309
  %s
301
310
  MESSAGE
302
- whitelist_labels = steps_with_error.map(&:label_dashed).join(',')
311
+ whitelist_labels = steps_to_whitelist.map(&:label_dashed).join(',')
303
312
  recommend << format(<<-MESSAGE.strip_heredoc, whitelist_labels)
304
313
  Resolve the failed steps and rerun
305
314
  the command. In case the failures are false positives,
@@ -70,7 +70,8 @@ module ForemanMaintain
70
70
  :quit
71
71
  elsif @last_scenario.steps_with_warning(:whitelisted => false).any?
72
72
  @last_scenario_continuation_confirmed = true
73
- reporter.ask_decision("Continue with [#{scenario.description}]")
73
+ reporter.ask_decision("Continue with [#{scenario.description}]",
74
+ run_strategy: scenario.run_strategy)
74
75
  end
75
76
 
76
77
  ask_to_quit if [:quit, :no].include?(decision)
@@ -131,7 +132,7 @@ module ForemanMaintain
131
132
  if execution.aborted?
132
133
  ask_to_quit
133
134
  else
134
- next_steps_decision = ask_about_offered_steps(step)
135
+ next_steps_decision = ask_about_offered_steps(step, scenario)
135
136
  if next_steps_decision != :yes &&
136
137
  execution.fail? && !execution.whitelisted? &&
137
138
  scenario.run_strategy == :fail_fast
@@ -141,7 +142,7 @@ module ForemanMaintain
141
142
  end
142
143
 
143
144
  # rubocop:disable Metrics/MethodLength
144
- def ask_about_offered_steps(step)
145
+ def ask_about_offered_steps(step, scenario)
145
146
  if assumeyes? && rerun_check?(step)
146
147
  @reporter.puts 'Check still failing after attempt to fix. Skipping'
147
148
  return :no
@@ -149,7 +150,8 @@ module ForemanMaintain
149
150
  if step.next_steps && !step.next_steps.empty?
150
151
  @last_decision_step = step
151
152
  steps = step.next_steps.map(&:ensure_instance)
152
- decision = @reporter.on_next_steps(steps)
153
+
154
+ decision = @reporter.on_next_steps(steps, scenario.run_strategy)
153
155
  case decision
154
156
  when :quit
155
157
  ask_to_quit
@@ -116,6 +116,10 @@ module ForemanMaintain
116
116
  filter_whitelisted(executed_steps.find_all(&:warning?), options)
117
117
  end
118
118
 
119
+ def steps_with_skipped(options = {})
120
+ filter_whitelisted(executed_steps.find_all(&:skipped?), options)
121
+ end
122
+
119
123
  def filter_whitelisted(steps, options)
120
124
  options.validate_options!(:whitelisted)
121
125
  if options.key?(:whitelisted)
@@ -22,10 +22,6 @@ module ForemanMaintain
22
22
  convert_kb_to_mb(execute!("df #{dir}|awk {'print $4'}|tail -1").to_i)
23
23
  end
24
24
 
25
- def space_used_in_percent
26
- execute!("df #{dir}|awk {'print $5'}|tail -1").to_i
27
- end
28
-
29
25
  private
30
26
 
31
27
  # In fio command, --direct option bypass the cache page
@@ -1,17 +1,16 @@
1
1
  module ForemanMaintain::Utils
2
2
  module Service
3
3
  class Systemd < Abstract
4
- attr_reader :instance_parent_unit
5
4
  def initialize(name, priority, options = {})
6
5
  super
7
6
  @sys = SystemHelpers.new
8
- @instance_parent_unit = options.fetch(:instance_parent_unit, nil)
9
7
  end
10
8
 
11
9
  def command(action, options = {})
12
10
  do_wait = options.fetch(:wait, true) # wait for service to start
13
11
  all = @options.fetch(:all, false)
14
12
  skip_enablement = @options.fetch(:skip_enablement, false)
13
+
15
14
  if skip_enablement && %w[enable disable].include?(action)
16
15
  return skip_enablement_message(action, @name)
17
16
  end
@@ -51,19 +50,29 @@ module ForemanMaintain::Utils
51
50
 
52
51
  def exist?
53
52
  if @sys.systemd_installed?
54
- systemd = @sys.execute("systemctl is-enabled #{@name} 2>&1 | tail -1").strip
53
+ systemd = service_enabled_status
55
54
  systemd == 'enabled' || systemd == 'disabled'
56
55
  else
57
56
  File.exist?("/etc/init.d/#{@name}")
58
57
  end
59
58
  end
60
59
 
60
+ def enabled?
61
+ if @sys.systemd_installed?
62
+ service_enabled_status == 'enabled'
63
+ end
64
+ end
65
+
61
66
  private
62
67
 
63
68
  def execute(action, options = {})
64
69
  @sys.execute_with_status(command(action, options))
65
70
  end
66
71
 
72
+ def service_enabled_status
73
+ @sys.execute("systemctl is-enabled #{@name} 2>&1 | tail -1").strip
74
+ end
75
+
67
76
  def skip_enablement_message(action, name)
68
77
  # Enable and disable does not work well with globs since they treat them literally.
69
78
  # We are skipping the pulpcore-workers@* for these actions until they are configured in
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '0.6.16'.freeze
2
+ VERSION = '0.7.0'.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.16
4
+ version: 0.7.0
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: 2021-03-08 00:00:00.000000000 Z
11
+ date: 2020-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -125,7 +125,6 @@ files:
125
125
  - definitions/checks/check_hotfix_installed.rb
126
126
  - definitions/checks/check_tmout.rb
127
127
  - definitions/checks/disk/available_space.rb
128
- - definitions/checks/disk/available_space_candlepin.rb
129
128
  - definitions/checks/disk/performance.rb
130
129
  - definitions/checks/env_proxy.rb
131
130
  - definitions/checks/foreman/check_checkpoint_segments.rb
@@ -148,6 +147,7 @@ files:
148
147
  - definitions/checks/mongo/db_up.rb
149
148
  - definitions/checks/mongo/tools_installed.rb
150
149
  - definitions/checks/original_assets.rb
150
+ - definitions/checks/package_manager/yum/validate_yum_config.rb
151
151
  - definitions/checks/pulpcore/db_up.rb
152
152
  - definitions/checks/puppet/provide_upgrade_guide.rb
153
153
  - definitions/checks/puppet/verify_no_empty_cacert_requests.rb
@@ -162,7 +162,6 @@ files:
162
162
  - definitions/checks/services_up.rb
163
163
  - definitions/checks/system_registration.rb
164
164
  - definitions/checks/version_locking_enabled.rb
165
- - definitions/checks/yum_exclude.rb
166
165
  - definitions/features/apache.rb
167
166
  - definitions/features/candlepin.rb
168
167
  - definitions/features/candlepin_database.rb
@@ -221,7 +220,9 @@ files:
221
220
  - definitions/procedures/backup/snapshot/mount_pulpcore_db.rb
222
221
  - definitions/procedures/backup/snapshot/prepare_mount.rb
223
222
  - definitions/procedures/candlepin/delete_orphaned_records_from_env_content.rb
223
+ - definitions/procedures/content/migration_stats.rb
224
224
  - definitions/procedures/content/prepare.rb
225
+ - definitions/procedures/content/prepare_abort.rb
225
226
  - definitions/procedures/content/switchover.rb
226
227
  - definitions/procedures/crond/start.rb
227
228
  - definitions/procedures/crond/stop.rb
@@ -254,6 +255,7 @@ files:
254
255
  - definitions/procedures/packages/update.rb
255
256
  - definitions/procedures/packages/update_all_confirmation.rb
256
257
  - definitions/procedures/passenger_recycler.rb
258
+ - definitions/procedures/prep_6_10_upgrade.rb
257
259
  - definitions/procedures/pulp/migrate.rb
258
260
  - definitions/procedures/pulpcore/migrate.rb
259
261
  - definitions/procedures/puppet/delete_empty_ca_cert_request_files.rb
@@ -289,10 +291,13 @@ files:
289
291
  - definitions/scenarios/content.rb
290
292
  - definitions/scenarios/maintenance_mode.rb
291
293
  - definitions/scenarios/packages.rb
294
+ - definitions/scenarios/prep_6_10_upgrade.rb
292
295
  - definitions/scenarios/restore.rb
293
296
  - definitions/scenarios/services.rb
294
297
  - definitions/scenarios/upgrade_to_capsule_6_8.rb
295
298
  - definitions/scenarios/upgrade_to_capsule_6_8_z.rb
299
+ - definitions/scenarios/upgrade_to_capsule_6_9.rb
300
+ - definitions/scenarios/upgrade_to_capsule_6_9_z.rb
296
301
  - definitions/scenarios/upgrade_to_satellite_6_2.rb
297
302
  - definitions/scenarios/upgrade_to_satellite_6_2_z.rb
298
303
  - definitions/scenarios/upgrade_to_satellite_6_3.rb
@@ -307,6 +312,8 @@ files:
307
312
  - definitions/scenarios/upgrade_to_satellite_6_7_z.rb
308
313
  - definitions/scenarios/upgrade_to_satellite_6_8.rb
309
314
  - definitions/scenarios/upgrade_to_satellite_6_8_z.rb
315
+ - definitions/scenarios/upgrade_to_satellite_6_9.rb
316
+ - definitions/scenarios/upgrade_to_satellite_6_9_z.rb
310
317
  - extras/foreman-maintain.sh
311
318
  - extras/foreman_protector/foreman-protector.conf
312
319
  - extras/foreman_protector/foreman-protector.py
@@ -339,7 +346,6 @@ files:
339
346
  - lib/foreman_maintain/concerns/hammer.rb
340
347
  - lib/foreman_maintain/concerns/logger.rb
341
348
  - lib/foreman_maintain/concerns/metadata.rb
342
- - lib/foreman_maintain/concerns/primary_checks.rb
343
349
  - lib/foreman_maintain/concerns/reporter.rb
344
350
  - lib/foreman_maintain/concerns/scenario_metadata.rb
345
351
  - lib/foreman_maintain/concerns/system_helpers.rb
@@ -1,27 +0,0 @@
1
- module Checks
2
- module Disk
3
- class AvailableSpaceCandlepin < ForemanMaintain::Check
4
- metadata do
5
- label :available_space_cp
6
- description 'Check to make sure /var/lib/candlepin has enough space'
7
- tags :pre_upgrade
8
- confine do
9
- feature(:candlepin) && check_min_version('candlepin', '3.1')
10
- end
11
- end
12
-
13
- MAX_USAGE_IN_PERCENT = 90
14
-
15
- def run
16
- assert(enough_space?, "System has more than #{MAX_USAGE_IN_PERCENT}% space used"\
17
- " on #{feature(:candlepin).work_dir}.\n"\
18
- 'See https://bugzilla.redhat.com/show_bug.cgi?id=1898605')
19
- end
20
-
21
- def enough_space?
22
- io_obj = ForemanMaintain::Utils::Disk::IODevice.new(feature(:candlepin).work_dir)
23
- io_obj.space_used_in_percent < MAX_USAGE_IN_PERCENT
24
- end
25
- end
26
- end
27
- end
@@ -1,21 +0,0 @@
1
- class Checks::YumExclude < ForemanMaintain::Check
2
- metadata do
3
- label :check_yum_exclude_list
4
- description 'Check if yum exclude list is configured'
5
- tags :pre_upgrade
6
- end
7
-
8
- EXCLUDE_SET_RE = /^exclude\s*=\s*\S+.*$/
9
-
10
- def run
11
- grep_result = grep_yum_exclude
12
- assert(!grep_result.match(EXCLUDE_SET_RE),
13
- 'The /etc/yum.conf has exclude list configured as below,'\
14
- "\n #{grep_result}"\
15
- "\nUnset this as it can cause yum update or upgrade failures !")
16
- end
17
-
18
- def grep_yum_exclude
19
- execute_with_status('grep -w exclude /etc/yum.conf')[1]
20
- end
21
- end
@@ -1,23 +0,0 @@
1
- module ForemanMaintain
2
- module Concerns
3
- module PrimaryChecks
4
- def validate_downstream_packages
5
- return unless detector.feature(:installer) && detector.feature(:installer).with_scenarios?
6
- if (package = package_name) && !package_manager.installed?(package)
7
- raise ForemanMaintain::Error::Fail,
8
- "Error: Important rpm package #{package} is not installed!"\
9
- "\nInstall #{package} rpm to ensure system consistency."
10
- end
11
- end
12
-
13
- def package_name
14
- installed_scenario = detector.feature(:installer).last_scenario
15
- if installed_scenario == 'satellite'
16
- 'satellite'
17
- elsif installed_scenario == 'capsule'
18
- 'satellite-capsule'
19
- end
20
- end
21
- end
22
- end
23
- end