foreman_maintain 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -1
  3. data/definitions/checks/foreman_tasks/not_paused.rb +1 -1
  4. data/definitions/checks/foreman_tasks/not_running.rb +1 -1
  5. data/definitions/features/downstream.rb +4 -9
  6. data/definitions/procedures/foreman_tasks/delete.rb +1 -1
  7. data/definitions/procedures/foreman_tasks/resume.rb +1 -1
  8. data/definitions/procedures/foreman_tasks/ui_investigate.rb +1 -1
  9. data/definitions/procedures/hammer_setup.rb +1 -1
  10. data/definitions/procedures/maintenance_mode/disable.rb +1 -1
  11. data/definitions/procedures/maintenance_mode/enable.rb +1 -1
  12. data/definitions/scenarios/upgrade_to_satellite_6_2.rb +5 -5
  13. data/definitions/scenarios/upgrade_to_satellite_6_2_z.rb +5 -5
  14. data/definitions/scenarios/upgrade_to_satellite_6_3.rb +5 -5
  15. data/definitions/scenarios/upgrade_to_satellite_6_3_z.rb +5 -5
  16. data/lib/foreman_maintain.rb +1 -1
  17. data/lib/foreman_maintain/cli.rb +31 -8
  18. data/lib/foreman_maintain/cli/advanced/procedure/abstract_by_tag_command.rb +11 -2
  19. data/lib/foreman_maintain/cli/advanced/procedure/abstract_procedure_command.rb +1 -0
  20. data/lib/foreman_maintain/cli/advanced/procedure/by_tag_command.rb +1 -1
  21. data/lib/foreman_maintain/cli/base.rb +8 -4
  22. data/lib/foreman_maintain/cli/health_command.rb +1 -0
  23. data/lib/foreman_maintain/cli/transform_clamp_options.rb +2 -1
  24. data/lib/foreman_maintain/cli/upgrade_command.rb +12 -0
  25. data/lib/foreman_maintain/concerns/metadata.rb +1 -1
  26. data/lib/foreman_maintain/reporter/cli_reporter.rb +7 -6
  27. data/lib/foreman_maintain/runner.rb +12 -5
  28. data/lib/foreman_maintain/upgrade_runner.rb +25 -2
  29. data/lib/foreman_maintain/version.rb +1 -1
  30. data/lib/foreman_maintain/yaml_storage.rb +5 -0
  31. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa7485ad5a283ccf2c2d057d39e7fda1c579fd4d
4
- data.tar.gz: aff6077a5e552e388e4d270d38f8e0795dc4dffc
3
+ metadata.gz: b7df7b95f8a1a9903c19af1e5b49ccfa40008e73
4
+ data.tar.gz: 70e9f58bfac04116906fb43b19b37c1cd93dc1df
5
5
  SHA512:
6
- metadata.gz: 3e3a2e5956ba633975aa415a923cd5f3621d941a1683b07d727d28810c9673db2776a7e04a8090144bb149e99cebfc045153d2399f6e28908f5cee9b76d5ae4a
7
- data.tar.gz: 40b1aa56498bc6e80f88ca3330df6c7fff946146fde9879179735d82dab24ecf45778b66d79c7a91949f8c0dbf5f64913e80259bb6aa12a060798ffc65f472fd
6
+ metadata.gz: a0aa83732512f0daa0d549d805c5ad354df123ac54731e7650912f928bde6ab7ef82a9c59e15da33df4dbf2f3e40ef5a68ebee3e5d028e3290a23c7f7d7a0a2a
7
+ data.tar.gz: 6b311731eff01767e2aac5ed8cccd45e9e49f019b292e7bde6b59a28300816426f2dcd260549dfe5a716104d5076eda0873562d0ae7483686f015ad563305224
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Foreman Maintenance [![Build Status](https://travis-ci.org/theforeman/foreman_maintain.svg?branch=master)](https://travis-ci.org/theforeman/foreman_maintain)
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
3
  `foreman_maintain` aims to provide various features that helps keeping the
4
4
  Foreman/Satellite up and running. It supports multiple versions and subparts
@@ -347,6 +347,14 @@ foreman-maintain console
347
347
  foreman-maintain config
348
348
  ```
349
349
 
350
+ ## How to contribute?
351
+
352
+ 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:
353
+ * [Follow the rules](https://theforeman.org/contribute.html#SubmitPatches) about commit message style and create a [Redmine issue](http://projects.theforeman.org/projects/foreman-maintain/issues/new). Doing this right will help reviewers to get your contribution merged faster.
354
+ * We have a [development handbook](https://theforeman.org/handbook.html) to help developers understand how Foreman developers code.
355
+ * All of our pull requests run the full test suite in our [Travis CI system](https://travis-ci.org/theforeman/foreman_maintain). Please include tests in your pull requests for any additions or changes in functionality
356
+
357
+
350
358
  ## License
351
359
 
352
360
  This project is licensed under the GPLv3+
@@ -3,7 +3,7 @@ module Checks::ForemanTasks
3
3
  include ForemanMaintain::Concerns::Hammer
4
4
  metadata do
5
5
  for_feature :foreman_tasks
6
- description 'check for paused tasks'
6
+ description 'Check for paused tasks'
7
7
  tags :default
8
8
  end
9
9
 
@@ -2,7 +2,7 @@ module Checks::ForemanTasks
2
2
  class NotRunning < ForemanMaintain::Check
3
3
  metadata do
4
4
  for_feature :foreman_tasks
5
- description 'check for running tasks'
5
+ description 'Check for running tasks'
6
6
  tags :pre_upgrade
7
7
  after :foreman_tasks_not_paused
8
8
  before :check_old_foreman_tasks
@@ -33,15 +33,10 @@ class Features::Downstream < ForemanMaintain::Feature
33
33
 
34
34
  def rh_repos(sat_version)
35
35
  sat_version = version(sat_version)
36
- ["rhel-#{rh_version.major}-server-rpms",
37
- "rhel-#{rh_version.major}-rhscl-#{rh_version.major}-rpms",
38
- "rhel-#{rh_version.major}-server-satellite-#{sat_version.major}.#{sat_version.minor}-rpms"]
39
- end
40
-
41
- def rh_version
42
- return @rh_version if defined? @rh_version
43
- release_package = execute!('rpm -qf /etc/redhat-release')
44
- @rh_version = rpm_version(release_package, 'RELEASE')
36
+ rh_version_major = execute!('facter operatingsystemmajrelease')
37
+ ["rhel-#{rh_version_major}-server-rpms",
38
+ "rhel-server-rhscl-#{rh_version_major}-rpms",
39
+ "rhel-#{rh_version_major}-server-satellite-#{sat_version.major}.#{sat_version.minor}-rpms"]
45
40
  end
46
41
 
47
42
  def version_from_source
@@ -2,7 +2,7 @@ module Procedures::ForemanTasks
2
2
  class Delete < ForemanMaintain::Procedure
3
3
  metadata do
4
4
  param :state, 'In what state should the task be deleted'
5
- description 'delete tasks'
5
+ description 'Delete tasks'
6
6
  end
7
7
 
8
8
  def run
@@ -2,7 +2,7 @@ module Procedures::ForemanTasks
2
2
  class Resume < ForemanMaintain::Procedure
3
3
  metadata do
4
4
  for_feature :foreman_tasks
5
- description 'resume paused tasks'
5
+ description 'Resume paused tasks'
6
6
  end
7
7
 
8
8
  def run
@@ -3,7 +3,7 @@ module Procedures::ForemanTasks
3
3
  class UiInvestigate < ForemanMaintain::Procedure
4
4
  metadata do
5
5
  for_feature :foreman_tasks
6
- description 'investigate the tasks via UI'
6
+ description 'Investigate the tasks via UI'
7
7
  param :search_query
8
8
  end
9
9
 
@@ -1,6 +1,6 @@
1
1
  class Procedures::HammerSetup < ForemanMaintain::Procedure
2
2
  metadata do
3
- description 'setup hammer'
3
+ description 'Setup hammer'
4
4
  end
5
5
 
6
6
  def run
@@ -2,7 +2,7 @@ module Procedures::MaintenanceMode
2
2
  class Disable < ForemanMaintain::Procedure
3
3
  metadata do
4
4
  for_feature :foreman
5
- description 'turn off maintenance mode'
5
+ description 'Turn off maintenance mode'
6
6
  tags :post_migrations
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ module Procedures::MaintenanceMode
2
2
  class Enable < ForemanMaintain::Procedure
3
3
  metadata do
4
4
  for_feature :foreman
5
- description 'turn on maintenance mode'
5
+ description 'Turn on maintenance mode'
6
6
  tags :pre_migrations
7
7
  end
8
8
 
@@ -13,7 +13,7 @@ module Scenarios::Satellite_6_2
13
13
 
14
14
  class PreUpgradeCheck < Abstract
15
15
  upgrade_metadata do
16
- description 'checks before upgrading to Satellite 6.2'
16
+ description 'Checks before upgrading to Satellite 6.2'
17
17
  tags :pre_upgrade_checks
18
18
  run_strategy :fail_slow
19
19
  end
@@ -26,7 +26,7 @@ module Scenarios::Satellite_6_2
26
26
 
27
27
  class PreMigrations < Abstract
28
28
  upgrade_metadata do
29
- description 'procedures before migrating to Satellite 6.2'
29
+ description 'Procedures before migrating to Satellite 6.2'
30
30
  tags :pre_migrations
31
31
  end
32
32
 
@@ -37,7 +37,7 @@ module Scenarios::Satellite_6_2
37
37
 
38
38
  class Migrations < Abstract
39
39
  upgrade_metadata do
40
- description 'migration scripts to Satellite 6.2'
40
+ description 'Migration scripts to Satellite 6.2'
41
41
  tags :migrations
42
42
  end
43
43
 
@@ -50,7 +50,7 @@ module Scenarios::Satellite_6_2
50
50
 
51
51
  class PostMigrations < Abstract
52
52
  upgrade_metadata do
53
- description 'procedures after migrating to Satellite 6.2'
53
+ description 'Procedures after migrating to Satellite 6.2'
54
54
  tags :post_migrations
55
55
  end
56
56
 
@@ -61,7 +61,7 @@ module Scenarios::Satellite_6_2
61
61
 
62
62
  class PostUpgradeChecks < Abstract
63
63
  upgrade_metadata do
64
- description 'checks after upgrading to Satellite 6.2'
64
+ description 'Checks after upgrading to Satellite 6.2'
65
65
  tags :post_upgrade_checks
66
66
  run_strategy :fail_slow
67
67
  end
@@ -13,7 +13,7 @@ module Scenarios::Satellite_6_2_z
13
13
 
14
14
  class PreUpgradeCheck < Abstract
15
15
  upgrade_metadata do
16
- description 'checks before upgrading to Satellite 6.2.z'
16
+ description 'Checks before upgrading to Satellite 6.2.z'
17
17
  tags :pre_upgrade_checks
18
18
  run_strategy :fail_slow
19
19
  end
@@ -26,7 +26,7 @@ module Scenarios::Satellite_6_2_z
26
26
 
27
27
  class PreMigrations < Abstract
28
28
  upgrade_metadata do
29
- description 'procedures before migrating to Satellite 6.2.z'
29
+ description 'Procedures before migrating to Satellite 6.2.z'
30
30
  tags :pre_migrations
31
31
  end
32
32
 
@@ -37,7 +37,7 @@ module Scenarios::Satellite_6_2_z
37
37
 
38
38
  class Migrations < Abstract
39
39
  upgrade_metadata do
40
- description 'migration scripts to Satellite 6.2.z'
40
+ description 'Migration scripts to Satellite 6.2.z'
41
41
  tags :migrations
42
42
  end
43
43
 
@@ -49,7 +49,7 @@ module Scenarios::Satellite_6_2_z
49
49
 
50
50
  class PostMigrations < Abstract
51
51
  upgrade_metadata do
52
- description 'procedures after migrating to Satellite 6.2.z'
52
+ description 'Procedures after migrating to Satellite 6.2.z'
53
53
  tags :post_migrations
54
54
  end
55
55
 
@@ -60,7 +60,7 @@ module Scenarios::Satellite_6_2_z
60
60
 
61
61
  class PostUpgradeChecks < Abstract
62
62
  upgrade_metadata do
63
- description 'checks after upgrading to Satellite 6.2.z'
63
+ description 'Checks after upgrading to Satellite 6.2.z'
64
64
  tags :post_upgrade_checks
65
65
  run_strategy :fail_slow
66
66
  end
@@ -13,7 +13,7 @@ module Scenarios::Satellite_6_3
13
13
 
14
14
  class PreUpgradeCheck < Abstract
15
15
  upgrade_metadata do
16
- description 'checks before upgrading to Satellite 6.3'
16
+ description 'Checks before upgrading to Satellite 6.3'
17
17
  tags :pre_upgrade_checks
18
18
  run_strategy :fail_slow
19
19
  end
@@ -26,7 +26,7 @@ module Scenarios::Satellite_6_3
26
26
 
27
27
  class PreMigrations < Abstract
28
28
  upgrade_metadata do
29
- description 'procedures before migrating to Satellite 6.3'
29
+ description 'Procedures before migrating to Satellite 6.3'
30
30
  tags :pre_migrations
31
31
  end
32
32
 
@@ -37,7 +37,7 @@ module Scenarios::Satellite_6_3
37
37
 
38
38
  class Migrations < Abstract
39
39
  upgrade_metadata do
40
- description 'migration scripts to Satellite 6.3'
40
+ description 'Migration scripts to Satellite 6.3'
41
41
  tags :migrations
42
42
  end
43
43
 
@@ -50,7 +50,7 @@ module Scenarios::Satellite_6_3
50
50
 
51
51
  class PostMigrations < Abstract
52
52
  upgrade_metadata do
53
- description 'procedures after migrating to Satellite 6.3'
53
+ description 'Procedures after migrating to Satellite 6.3'
54
54
  tags :post_migrations
55
55
  end
56
56
 
@@ -61,7 +61,7 @@ module Scenarios::Satellite_6_3
61
61
 
62
62
  class PostUpgradeChecks < Abstract
63
63
  upgrade_metadata do
64
- description 'checks after upgrading to Satellite 6.3'
64
+ description 'Checks after upgrading to Satellite 6.3'
65
65
  tags :post_upgrade_checks
66
66
  run_strategy :fail_slow
67
67
  end
@@ -13,7 +13,7 @@ module Scenarios::Satellite_6_3_z
13
13
 
14
14
  class PreUpgradeCheck < Abstract
15
15
  upgrade_metadata do
16
- description 'checks before upgrading to Satellite 6.3.z'
16
+ description 'Checks before upgrading to Satellite 6.3.z'
17
17
  tags :pre_upgrade_checks
18
18
  run_strategy :fail_slow
19
19
  end
@@ -26,7 +26,7 @@ module Scenarios::Satellite_6_3_z
26
26
 
27
27
  class PreMigrations < Abstract
28
28
  upgrade_metadata do
29
- description 'procedures before migrating to Satellite 6.3.z'
29
+ description 'Procedures before migrating to Satellite 6.3.z'
30
30
  tags :pre_migrations
31
31
  end
32
32
 
@@ -37,7 +37,7 @@ module Scenarios::Satellite_6_3_z
37
37
 
38
38
  class Migrations < Abstract
39
39
  upgrade_metadata do
40
- description 'migration scripts to Satellite 6.3.z'
40
+ description 'Migration scripts to Satellite 6.3.z'
41
41
  tags :migrations
42
42
  end
43
43
 
@@ -49,7 +49,7 @@ module Scenarios::Satellite_6_3_z
49
49
 
50
50
  class PostMigrations < Abstract
51
51
  upgrade_metadata do
52
- description 'procedures after migrating to Satellite 6.3.z'
52
+ description 'Procedures after migrating to Satellite 6.3.z'
53
53
  tags :post_migrations
54
54
  end
55
55
 
@@ -60,7 +60,7 @@ module Scenarios::Satellite_6_3_z
60
60
 
61
61
  class PostUpgradeChecks < Abstract
62
62
  upgrade_metadata do
63
- description 'checks after upgrading to Satellite 6.3.z'
63
+ description 'Checks after upgrading to Satellite 6.3.z'
64
64
  tags :post_upgrade_checks
65
65
  run_strategy :fail_slow
66
66
  end
@@ -108,7 +108,7 @@ module ForemanMaintain
108
108
  config.pre_setup_log_messages.clear
109
109
  end
110
110
 
111
- def storage(label)
111
+ def storage(label = :default)
112
112
  ForemanMaintain::YamlStorage.load(label)
113
113
  rescue => e
114
114
  logger.error "Invalid Storage label i.e #{label}. Error - #{e.message}"
@@ -19,19 +19,42 @@ module ForemanMaintain
19
19
  logger.info("Running foreman-maintain command with arguments #{arguments.inspect}")
20
20
  begin
21
21
  super
22
- exit_code = 0
22
+ @exit_code = 0
23
+ rescue Error::UsageError => e
24
+ process_usage_error(e)
23
25
  rescue StandardError => e
24
- if e.is_a?(Clamp::HelpWanted) || e.is_a?(ArgumentError) || e.is_a?(Clamp::UsageError)
25
- raise e
26
- end
27
- puts e.message
28
- logger.error(e)
29
- exit_code = 1
26
+ process_standard_error(e)
30
27
  end
31
- return exit_code
28
+
29
+ return @exit_code
32
30
  ensure
31
+ log_exit_code_info(@exit_code)
32
+ end
33
+
34
+ private
35
+
36
+ def log_exit_code_info(exit_code)
33
37
  logger.info("foreman-maintain command finished with #{exit_code}")
34
38
  end
39
+
40
+ def process_standard_error(error)
41
+ if error.is_a?(Clamp::HelpWanted) ||
42
+ error.is_a?(ArgumentError) ||
43
+ error.is_a?(Clamp::UsageError)
44
+ raise error
45
+ end
46
+
47
+ puts error.message
48
+ logger.error(error)
49
+
50
+ @exit_code = 1
51
+ end
52
+
53
+ def process_usage_error(error)
54
+ log_exit_code_info(1)
55
+ puts error.message
56
+ exit!
57
+ end
35
58
  end
36
59
  end
37
60
  end
@@ -25,12 +25,21 @@ module ForemanMaintain
25
25
  end
26
26
 
27
27
  def execute
28
+ run_scenario(scenario(invocation_path))
29
+ exit runner.exit_code
30
+ end
31
+
32
+ private
33
+
34
+ def scenario(invocation_path)
28
35
  tag = underscorize(invocation_path.split.last).to_sym
29
36
  scenario = ForemanMaintain::Scenario.new
37
+
30
38
  ForemanMaintain.available_procedures(:tags => tag).sort_by(&:label).each do |procedure|
31
- scenario.add_step(procedure.new(params_for_procedure(procedure)))
39
+ scenario.add_step(procedure.new(get_params_for(procedure)))
32
40
  end
33
- run_scenario(scenario)
41
+
42
+ scenario
34
43
  end
35
44
  end
36
45
  end
@@ -10,6 +10,7 @@ module ForemanMaintain
10
10
  scenario = ForemanMaintain::Scenario.new
11
11
  scenario.add_step(procedure.new(get_params_for(procedure)))
12
12
  run_scenario(scenario)
13
+ exit runner.exit_code
13
14
  end
14
15
  end
15
16
  end
@@ -13,7 +13,7 @@ module ForemanMaintain
13
13
  procedure.label.to_s
14
14
  end
15
15
 
16
- subcommand(dashize(tag), "Run procedures tagged ##{tag} #{procedures}", klass)
16
+ subcommand(dashize(tag), "Run procedures tagged ##{tag}: #{procedures.join(', ')}", klass)
17
17
  end
18
18
 
19
19
  def execute
@@ -5,6 +5,8 @@ module ForemanMaintain
5
5
  class Base < Clamp::Command
6
6
  include Concerns::Finders
7
7
 
8
+ attr_reader :runner
9
+
8
10
  def self.dashize(string)
9
11
  string.to_s.tr('_', '-')
10
12
  end
@@ -38,10 +40,12 @@ module ForemanMaintain
38
40
  end
39
41
 
40
42
  def run_scenario(scenarios)
41
- ForemanMaintain::Runner.new(reporter, scenarios,
42
- :assumeyes => assumeyes?,
43
- :whitelist => whitelist || [],
44
- :force => force?).run
43
+ @runner ||=
44
+ ForemanMaintain::Runner.new(reporter, scenarios,
45
+ :assumeyes => assumeyes?,
46
+ :whitelist => whitelist || [],
47
+ :force => force?)
48
+ runner.run
45
49
  end
46
50
 
47
51
  def available_checks
@@ -30,6 +30,7 @@ module ForemanMaintain
30
30
  else
31
31
  run_scenario(scenario)
32
32
  end
33
+ exit runner.exit_code
33
34
  end
34
35
 
35
36
  def filter
@@ -26,7 +26,8 @@ module ForemanMaintain
26
26
  private
27
27
 
28
28
  def option_sym(option)
29
- option.switches.first[2..-1].to_sym
29
+ option = option.switches.first[2..-1].to_s
30
+ option.to_sym unless option.empty?
30
31
  end
31
32
 
32
33
  def metadata_option?(option)
@@ -6,7 +6,19 @@ module ForemanMaintain
6
6
  :required => false
7
7
  end
8
8
 
9
+ def current_target_version
10
+ current_target_version = ForemanMaintain::UpgradeRunner.current_target_version
11
+ if current_target_version && target_version && target_version != current_target_version
12
+ raise Error::UsageError,
13
+ "Can't set target version #{target_version}, "\
14
+ "#{current_target_version} already in progress"
15
+ end
16
+ @target_version = current_target_version if current_target_version
17
+ return true if current_target_version
18
+ end
19
+
9
20
  def validate_target_version!
21
+ return if current_target_version
10
22
  unless UpgradeRunner.available_targets.include?(target_version)
11
23
  message_start = if target_version
12
24
  "Can't upgrade to #{target_version}"
@@ -253,7 +253,7 @@ module ForemanMaintain
253
253
  end
254
254
 
255
255
  def runtime_message
256
- description + (params.empty? ? '' : " (#{params})")
256
+ description
257
257
  end
258
258
 
259
259
  def tags
@@ -277,24 +277,25 @@ module ForemanMaintain
277
277
  recommend = []
278
278
  steps_with_error = scenario.steps_with_error(:whitelisted => false)
279
279
  unless steps_with_error.empty?
280
- message << <<-MESSAGE.strip_heredoc
280
+ message << format(<<-MESSAGE.strip_heredoc, format_steps(steps_with_error, "\n", 2))
281
281
  The following steps ended up in failing state:
282
282
 
283
- #{format_steps(steps_with_error, "\n", 2)}
283
+ %s
284
284
  MESSAGE
285
- recommend << <<-MESSAGE.strip_heredoc
285
+ whitelist_labels = steps_with_error.map(&:label_dashed).join(',')
286
+ recommend << format(<<-MESSAGE.strip_heredoc, whitelist_labels)
286
287
  Resolve the failed steps and rerun
287
288
  the command. In case the failures are false positives,
288
- use --whitelist="#{steps_with_error.map(&:label_dashed).join(',')}"
289
+ use --whitelist="%s"
289
290
  MESSAGE
290
291
  end
291
292
 
292
293
  steps_with_warning = scenario.steps_with_warning(:whitelisted => false)
293
294
  unless steps_with_warning.empty?
294
- message << <<-MESSAGE.strip_heredoc
295
+ message << format(<<-MESSAGE.strip_heredoc, format_steps(steps_with_warning, "\n", 2))
295
296
  The following steps ended up in warning state:
296
297
 
297
- #{format_steps(steps_with_warning, "\n", 2)}
298
+ %s
298
299
  MESSAGE
299
300
 
300
301
  recommend << <<-MESSAGE.strip_heredoc
@@ -36,17 +36,16 @@ module ForemanMaintain
36
36
  def run_scenario(scenario, confirm = true)
37
37
  return if scenario.steps.empty?
38
38
  raise 'The runner is already in quit state' if quit?
39
+
39
40
  if confirm
40
41
  confirm_scenario(scenario)
41
42
  return if quit?
42
43
  end
43
- scenario.before_scenarios.flatten.each { |before_scenario| run_scenario(before_scenario) }
44
- return if quit? # the before scenarios caused the stop of the execution
45
- @reporter.before_scenario_starts(scenario)
46
- run_steps(scenario, scenario.steps)
47
- @reporter.after_scenario_finishes(scenario)
44
+
45
+ execute_scenario_steps(scenario)
48
46
  ensure
49
47
  @last_scenario = scenario unless scenario.steps.empty?
48
+ @exit_code = 1 if scenario.failed?
50
49
  end
51
50
 
52
51
  def whitelisted_step?(step)
@@ -84,6 +83,14 @@ module ForemanMaintain
84
83
 
85
84
  private
86
85
 
86
+ def execute_scenario_steps(scenario)
87
+ scenario.before_scenarios.flatten.each { |before_scenario| run_scenario(before_scenario) }
88
+ return if quit? # the before scenarios caused the stop of the execution
89
+ @reporter.before_scenario_starts(scenario)
90
+ run_steps(scenario, scenario.steps)
91
+ @reporter.after_scenario_finishes(scenario)
92
+ end
93
+
87
94
  def run_steps(scenario, steps)
88
95
  @steps_to_run = ForemanMaintain::DependencyGraph.sort(steps)
89
96
  while !@quit && !@steps_to_run.empty?
@@ -13,13 +13,15 @@ module ForemanMaintain
13
13
  include Concerns::Finders
14
14
 
15
15
  def available_targets
16
+ # when some upgrade is in progress, we don't allow upgrade to different version
17
+ return [current_target_version] if current_target_version
16
18
  versions_to_tags.inject([]) do |available_targets, (version, tag)|
17
19
  if !find_scenarios(:tags => [tag]).empty?
18
20
  available_targets << version
19
21
  else
20
22
  available_targets
21
23
  end
22
- end
24
+ end.sort
23
25
  end
24
26
 
25
27
  def versions_to_tags
@@ -37,6 +39,18 @@ module ForemanMaintain
37
39
  def clear_register
38
40
  versions_to_tags.lear
39
41
  end
42
+
43
+ def current_target_version
44
+ ForemanMaintain.storage[:upgrade_target_version]
45
+ end
46
+
47
+ def current_target_version=(value)
48
+ ForemanMaintain.storage.update_and_save(:upgrade_target_version => value)
49
+ end
50
+
51
+ def clear_current_target_version
52
+ ForemanMaintain.storage.update_and_save(:upgrade_target_version => nil)
53
+ end
40
54
  end
41
55
 
42
56
  attr_reader :version, :tag, :phase
@@ -59,6 +73,7 @@ module ForemanMaintain
59
73
  end
60
74
 
61
75
  def run
76
+ self.class.current_target_version = @version
62
77
  PHASES.each do |phase|
63
78
  return run_rollback if quit?
64
79
  if skip?(phase)
@@ -70,6 +85,14 @@ module ForemanMaintain
70
85
  unless quit?
71
86
  finish_upgrade
72
87
  end
88
+ ensure
89
+ update_current_target_version
90
+ end
91
+
92
+ def update_current_target_version
93
+ if phase == :pre_upgrade_checks || @finished
94
+ UpgradeRunner.clear_current_target_version
95
+ end
73
96
  end
74
97
 
75
98
  def run_rollback
@@ -124,7 +147,7 @@ module ForemanMaintain
124
147
  @reporter.before_scenario_starts(scenario)
125
148
  @reporter.puts <<-MESSAGE.strip_heredoc
126
149
  Skipping #{skipped_phase} phase as it was already run before.
127
- To enforce to run the phase, use `upgrade run --phase #{phase}`
150
+ To enforce to run the phase, use `upgrade run --phase #{skipped_phase}`
128
151
  MESSAGE
129
152
  @reporter.after_scenario_finishes(scenario)
130
153
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '0.0.8'.freeze
2
+ VERSION = '0.0.9'.freeze
3
3
  end
@@ -13,6 +13,11 @@ module ForemanMaintain
13
13
  self.class.save_sub_key(sub_key, data)
14
14
  end
15
15
 
16
+ def update_and_save(attributes)
17
+ @data.merge!(attributes)
18
+ save
19
+ end
20
+
16
21
  class << self
17
22
  def load_file
18
23
  if File.exist?(storage_file_path)
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.0.8
4
+ version: 0.0.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: 2017-08-24 00:00:00.000000000 Z
11
+ date: 2017-09-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -211,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
211
  version: '0'
212
212
  requirements: []
213
213
  rubyforge_project:
214
- rubygems_version: 2.6.12
214
+ rubygems_version: 2.5.2
215
215
  signing_key:
216
216
  specification_version: 4
217
217
  summary: Foreman maintenance tool belt