foreman_maintain 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +75 -3
  3. data/config/foreman_maintain.yml.example +6 -0
  4. data/config/foreman_maintain.yml.packaging +6 -0
  5. data/definitions/checks/disk_speed_minimal.rb +1 -1
  6. data/definitions/checks/foreman_proxy/verify_dhcp_config_syntax.rb +17 -0
  7. data/definitions/checks/system_registration.rb +1 -1
  8. data/definitions/features/downstream.rb +31 -0
  9. data/definitions/features/foreman_1_7_x.rb +33 -0
  10. data/definitions/features/foreman_proxy.rb +72 -0
  11. data/definitions/features/sync_plans.rb +14 -20
  12. data/definitions/features/upstream.rb +4 -0
  13. data/definitions/procedures/foreman_tasks/delete.rb +2 -1
  14. data/definitions/procedures/hammer_setup.rb +4 -4
  15. data/definitions/procedures/installer/upgrade.rb +19 -0
  16. data/definitions/procedures/maintenance_mode/disable.rb +13 -0
  17. data/definitions/procedures/maintenance_mode/enable.rb +13 -0
  18. data/definitions/procedures/packages/install.rb +20 -0
  19. data/definitions/procedures/packages/update.rb +20 -0
  20. data/definitions/procedures/repositories/setup.rb +18 -0
  21. data/definitions/procedures/sync_plans/disable.rb +4 -0
  22. data/definitions/procedures/sync_plans/enable.rb +5 -0
  23. data/definitions/scenarios/upgrade_to_satellite_6_2.rb +77 -0
  24. data/lib/foreman_maintain.rb +5 -2
  25. data/lib/foreman_maintain/check.rb +11 -4
  26. data/lib/foreman_maintain/cli.rb +23 -0
  27. data/lib/foreman_maintain/cli/advanced/procedure/abstract_by_tag_command.rb +38 -0
  28. data/lib/foreman_maintain/cli/advanced/procedure/abstract_procedure_command.rb +17 -0
  29. data/lib/foreman_maintain/cli/advanced/procedure/by_tag_command.rb +32 -0
  30. data/lib/foreman_maintain/cli/advanced/procedure/run_command.rb +17 -0
  31. data/lib/foreman_maintain/cli/advanced/procedure_command.rb +11 -0
  32. data/lib/foreman_maintain/cli/advanced_command.rb +9 -0
  33. data/lib/foreman_maintain/cli/base.rb +52 -7
  34. data/lib/foreman_maintain/cli/health_command.rb +0 -12
  35. data/lib/foreman_maintain/cli/transform_clamp_options.rb +66 -0
  36. data/lib/foreman_maintain/cli/upgrade_command.rb +45 -33
  37. data/lib/foreman_maintain/concerns/metadata.rb +28 -2
  38. data/lib/foreman_maintain/concerns/scenario_metadata.rb +44 -0
  39. data/lib/foreman_maintain/concerns/system_helpers.rb +27 -5
  40. data/lib/foreman_maintain/config.rb +10 -5
  41. data/lib/foreman_maintain/core_ext.rb +5 -1
  42. data/lib/foreman_maintain/csv_parser.rb +81 -0
  43. data/lib/foreman_maintain/dependency_graph.rb +10 -48
  44. data/lib/foreman_maintain/error.rb +4 -0
  45. data/lib/foreman_maintain/executable.rb +64 -13
  46. data/lib/foreman_maintain/param.rb +1 -0
  47. data/lib/foreman_maintain/reporter.rb +84 -3
  48. data/lib/foreman_maintain/reporter/cli_reporter.rb +57 -21
  49. data/lib/foreman_maintain/runner.rb +80 -21
  50. data/lib/foreman_maintain/runner/execution.rb +29 -4
  51. data/lib/foreman_maintain/runner/stored_execution.rb +23 -0
  52. data/lib/foreman_maintain/scenario.rb +90 -7
  53. data/lib/foreman_maintain/upgrade_runner.rb +194 -0
  54. data/lib/foreman_maintain/utils.rb +1 -0
  55. data/lib/foreman_maintain/utils/curl_response.rb +21 -0
  56. data/lib/foreman_maintain/version.rb +1 -1
  57. metadata +24 -14
  58. data/definitions/checks/sync_plans/with_disabled_status.rb +0 -18
  59. data/definitions/checks/sync_plans/with_enabled_status.rb +0 -19
  60. data/definitions/procedures/install_package.rb +0 -17
  61. data/definitions/scenarios/pre_upgrade_check_foreman_1_14.rb +0 -13
  62. data/definitions/scenarios/pre_upgrade_check_satellite_6_0_z.rb +0 -14
  63. data/definitions/scenarios/pre_upgrade_check_satellite_6_1.rb +0 -14
  64. data/definitions/scenarios/pre_upgrade_check_satellite_6_1_z.rb +0 -14
  65. data/definitions/scenarios/pre_upgrade_check_satellite_6_2.rb +0 -14
  66. data/definitions/scenarios/pre_upgrade_check_satellite_6_2_z.rb +0 -14
  67. data/definitions/scenarios/pre_upgrade_check_satellite_6_3.rb +0 -14
  68. data/lib/foreman_maintain/object_cache.rb +0 -34
@@ -0,0 +1,13 @@
1
+ module Procedures::MaintenanceMode
2
+ class Disable < ForemanMaintain::Procedure
3
+ metadata do
4
+ for_feature :foreman
5
+ description 'turn off maintenance mode'
6
+ tags :post_migrations
7
+ end
8
+
9
+ def run
10
+ feature(:foreman).maintenance_mode(:disable)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Procedures::MaintenanceMode
2
+ class Enable < ForemanMaintain::Procedure
3
+ metadata do
4
+ for_feature :foreman
5
+ description 'turn on maintenance mode'
6
+ tags :pre_migrations
7
+ end
8
+
9
+ def run
10
+ feature(:foreman).maintenance_mode(:enable)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ module Procedures::Packages
2
+ class Install < ForemanMaintain::Procedure
3
+ metadata do
4
+ param :packages, 'List of packages to install', :array => true
5
+ param :assumeyes, 'Do not ask for confirmation'
6
+ end
7
+
8
+ def run
9
+ packages_action(:install, @packages, :assumeyes => @assumeyes.nil? ? assumeyes? : @assumeyes)
10
+ end
11
+
12
+ def necessary?
13
+ @packages.any? { |package| package_version(package).nil? }
14
+ end
15
+
16
+ def runtime_message
17
+ "Install package(s) #{@packages.join(', ')}"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module Procedures::Packages
2
+ class Update < ForemanMaintain::Procedure
3
+ metadata do
4
+ param :packages, 'List of packages to update', :array => true
5
+ param :assumeyes, 'Do not ask for confirmation'
6
+ end
7
+
8
+ def run
9
+ packages_action(:update, @packages, :assumeyes => @assumeyes.nil? ? assumeyes? : @assumeyes)
10
+ end
11
+
12
+ def necessary?
13
+ @packages.any? { |package| package_version(package).nil? }
14
+ end
15
+
16
+ def description
17
+ "Update package(s) #{@packages.join(', ')}"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ module Procedures::Repositories
2
+ class Setup < ForemanMaintain::Procedure
3
+ metadata do
4
+ description 'Setup repositories'
5
+ confine do
6
+ feature(:downstream) || feature(:upstream)
7
+ end
8
+ param :version, :required => true
9
+ run_once
10
+ end
11
+
12
+ def run
13
+ with_spinner("Configuring repositories for #{@version}") do
14
+ (feature(:downstream) || feature(:upstream)).setup_repositories(@version)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -3,6 +3,7 @@ module Procedures::SyncPlans
3
3
  metadata do
4
4
  for_feature :sync_plans
5
5
  description 'disable active sync plans'
6
+ tags :pre_migrations
6
7
  end
7
8
 
8
9
  def run
@@ -12,11 +13,14 @@ module Procedures::SyncPlans
12
13
  private
13
14
 
14
15
  def disable_all_enabled_sync_plans
16
+ feature(:sync_plans).load_from_storage(storage)
15
17
  with_spinner('disabling sync plans') do |spinner|
16
18
  ids = feature(:sync_plans).ids_by_status(true)
17
19
  feature(:sync_plans).make_disable(ids)
18
20
  spinner.update "Total #{ids.length} sync plans are now disabled."
19
21
  end
22
+ ensure
23
+ feature(:sync_plans).save_to_storage(storage)
20
24
  end
21
25
  end
22
26
  end
@@ -3,6 +3,8 @@ module Procedures::SyncPlans
3
3
  metadata do
4
4
  for_feature :sync_plans
5
5
  description 're-enable sync plans'
6
+ tags :post_migrations
7
+ before :disk_io
6
8
  end
7
9
 
8
10
  def run
@@ -12,10 +14,13 @@ module Procedures::SyncPlans
12
14
  private
13
15
 
14
16
  def enabled_sync_plans
17
+ feature(:sync_plans).load_from_storage(storage)
15
18
  with_spinner('re-enabling sync plans') do |spinner|
16
19
  record_ids = feature(:sync_plans).make_enable
17
20
  spinner.update "Total #{record_ids.length} sync plans are now enabled."
18
21
  end
22
+ ensure
23
+ feature(:sync_plans).save_to_storage(storage)
19
24
  end
20
25
  end
21
26
  end
@@ -0,0 +1,77 @@
1
+ module Scenarios::Satellite_6_2
2
+ class Abstract < ForemanMaintain::Scenario
3
+ def self.upgrade_metadata(&block)
4
+ metadata do
5
+ tags :upgrade_to_satellite_6_2
6
+ confine do
7
+ feature(:downstream) && feature(:downstream).current_minor_version == '6.1'
8
+ end
9
+ instance_eval(&block)
10
+ end
11
+ end
12
+ end
13
+
14
+ class PreUpgradeCheck < Abstract
15
+ upgrade_metadata do
16
+ description 'checks before upgrading to Satellite 6.2'
17
+ tags :pre_upgrade_checks
18
+ run_strategy :fail_slow
19
+ end
20
+
21
+ def compose
22
+ add_steps(find_checks(:default))
23
+ add_steps(find_checks(:pre_upgrade))
24
+ end
25
+ end
26
+
27
+ class PreMigrations < Abstract
28
+ upgrade_metadata do
29
+ description 'procedures before migrating to Satellite 6.2'
30
+ tags :pre_migrations
31
+ end
32
+
33
+ def compose
34
+ add_steps(find_procedures(:pre_migrations))
35
+ end
36
+ end
37
+
38
+ class Migrations < Abstract
39
+ upgrade_metadata do
40
+ description 'migration scripts to Satellite 6.2'
41
+ tags :migrations
42
+ end
43
+
44
+ def compose
45
+ add_step(Procedures::Repositories::Setup.new(:version => '6.2'))
46
+ add_step(Procedures::Packages::Update.new(:assumeyes => false))
47
+ add_step(Procedures::Installer::Upgrade.new)
48
+ add_steps(find_procedures(:label => :installer_upgrade))
49
+ end
50
+ end
51
+
52
+ class PostMigrations < Abstract
53
+ upgrade_metadata do
54
+ description 'procedures after migrating to Satellite 6.2'
55
+ tags :post_migrations
56
+ end
57
+
58
+ def compose
59
+ add_steps(find_procedures(:post_migrations))
60
+ end
61
+ end
62
+
63
+ class PostUpgradeChecks < Abstract
64
+ upgrade_metadata do
65
+ description 'checks after upgrading to Satellite 6.2'
66
+ tags :post_upgrade_checks
67
+ run_strategy :fail_slow
68
+ end
69
+
70
+ def compose
71
+ add_steps(find_checks(:default))
72
+ add_steps(find_checks(:post_upgrade))
73
+ end
74
+ end
75
+ end
76
+
77
+ ForemanMaintain::UpgradeRunner.register_version('6.2', :upgrade_to_satellite_6_2)
@@ -12,6 +12,7 @@ module ForemanMaintain
12
12
  require 'foreman_maintain/concerns/logger'
13
13
  require 'foreman_maintain/concerns/finders'
14
14
  require 'foreman_maintain/concerns/metadata'
15
+ require 'foreman_maintain/concerns/scenario_metadata'
15
16
  require 'foreman_maintain/concerns/system_helpers'
16
17
  require 'foreman_maintain/concerns/hammer'
17
18
  require 'foreman_maintain/top_level_modules'
@@ -23,10 +24,10 @@ module ForemanMaintain
23
24
  require 'foreman_maintain/feature'
24
25
  require 'foreman_maintain/executable'
25
26
  require 'foreman_maintain/check'
26
- require 'foreman_maintain/object_cache'
27
27
  require 'foreman_maintain/procedure'
28
28
  require 'foreman_maintain/scenario'
29
29
  require 'foreman_maintain/runner'
30
+ require 'foreman_maintain/upgrade_runner'
30
31
  require 'foreman_maintain/reporter'
31
32
  require 'foreman_maintain/utils'
32
33
  require 'foreman_maintain/error'
@@ -92,7 +93,9 @@ module ForemanMaintain
92
93
  # Note - If timestamp added to filename then number of log files i.e second
93
94
  # argument to Logger.new will not work as expected
94
95
  filename = File.expand_path("#{config.log_dir}/foreman-maintain.log")
95
- @logger = Logger.new(filename, 10, 10_240_000).tap do |logger|
96
+ # convert size in KB to Bytes
97
+ log_fsize = config.log_file_size.to_i * 1024
98
+ @logger = Logger.new(filename, 10, log_fsize).tap do |logger|
96
99
  logger.level = LOGGER_LEVEL_MAPPING[config.log_level] || Logger::DEBUG
97
100
  logger.datetime_format = '%Y-%m-%d %H:%M:%S%z '
98
101
  end
@@ -14,12 +14,19 @@ module ForemanMaintain
14
14
  # * +:next_steps* - one or more procedures that can be followed to address
15
15
  # the failure, will be offered to the user when running
16
16
  # in interactive mode
17
+ #
18
+ # * +:warn* - issue warning instead of failure: this is less strict check,
19
+ # that could be considered as non-critical for continuing with the scenario
17
20
  def assert(condition, error_message, options = {})
18
- options = options.validate_options!(:next_steps)
21
+ options = options.validate_options!(:next_steps, :warn)
19
22
  unless condition
20
23
  next_steps = Array(options.fetch(:next_steps, []))
21
24
  self.next_steps.concat(next_steps)
22
- raise Error::Fail, error_message
25
+ if options[:warn]
26
+ warn!(error_message)
27
+ else
28
+ fail!(error_message)
29
+ end
23
30
  end
24
31
  end
25
32
 
@@ -32,9 +39,9 @@ module ForemanMaintain
32
39
  def __run__(execution)
33
40
  super
34
41
  rescue Error::Fail => e
35
- fail!(e.message)
42
+ set_fail(e.message)
36
43
  rescue Error::Warn => e
37
- warn!(e.message)
44
+ set_warn(e.message)
38
45
  end
39
46
  end
40
47
  end
@@ -1,14 +1,37 @@
1
1
  require 'clamp'
2
2
  require 'highline'
3
3
  require 'foreman_maintain/cli/base'
4
+ require 'foreman_maintain/cli/transform_clamp_options'
4
5
  require 'foreman_maintain/cli/health_command'
5
6
  require 'foreman_maintain/cli/upgrade_command'
7
+ require 'foreman_maintain/cli/advanced_command'
6
8
 
7
9
  module ForemanMaintain
8
10
  module Cli
9
11
  class MainCommand < Base
12
+ include Concerns::Logger
13
+
10
14
  subcommand 'health', 'Health related commands', HealthCommand
11
15
  subcommand 'upgrade', 'Upgrade related commands', UpgradeCommand
16
+ subcommand 'advanced', 'Advanced tools for server maintenance', AdvancedCommand
17
+
18
+ def run(*arguments)
19
+ logger.info("Running foreman-maintain command with arguments #{arguments.inspect}")
20
+ begin
21
+ super
22
+ exit_code = 0
23
+ 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
30
+ end
31
+ return exit_code
32
+ ensure
33
+ logger.info("foreman-maintain command finished with #{exit_code}")
34
+ end
12
35
  end
13
36
  end
14
37
  end
@@ -0,0 +1,38 @@
1
+ module ForemanMaintain
2
+ module Cli
3
+ module Procedure
4
+ class AbstractByTagCommand < AbstractProcedureCommand
5
+ def self.tag_params_to_options(tag)
6
+ params = params_for_tag(tag)
7
+ params.values.each do |param|
8
+ mapping = param[:procedures]
9
+ instance = param[:instance]
10
+ param_to_option(instance, :description => instance.description + " #{mapping}")
11
+ end
12
+ end
13
+
14
+ def self.params_for_tag(tag)
15
+ params = {}
16
+ ForemanMaintain.available_procedures(:tags => tag).each do |procedure|
17
+ procedure.params.values.each do |param|
18
+ unless params.key?(param.name)
19
+ params[param.name] = { :instance => param, :procedures => [] }
20
+ end
21
+ params[param.name][:procedures] += [procedure.label.to_s]
22
+ end
23
+ end
24
+ params
25
+ end
26
+
27
+ def execute
28
+ tag = underscorize(invocation_path.split.last).to_sym
29
+ scenario = ForemanMaintain::Scenario.new
30
+ ForemanMaintain.available_procedures(:tags => tag).sort_by(&:label).each do |procedure|
31
+ scenario.add_step(procedure.new(params_for_procedure(procedure)))
32
+ end
33
+ run_scenario(scenario)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,17 @@
1
+ module ForemanMaintain
2
+ module Cli
3
+ module Procedure
4
+ class AbstractProcedureCommand < Base
5
+ include ForemanMaintain::Cli::TransformClampOptions
6
+
7
+ def execute
8
+ label = underscorize(invocation_path.split.last)
9
+ procedure = procedure(label.to_sym)
10
+ scenario = ForemanMaintain::Scenario.new
11
+ scenario.add_step(procedure.new(get_params_for(procedure)))
12
+ run_scenario(scenario)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ require 'foreman_maintain/cli/advanced/procedure/abstract_by_tag_command'
2
+
3
+ module ForemanMaintain
4
+ module Cli
5
+ module Procedure
6
+ class ByTagCommand < Base
7
+ available_tags(ForemanMaintain.available_procedures(nil)).each do |tag|
8
+ klass = Class.new(AbstractByTagCommand) do
9
+ tag_params_to_options(tag)
10
+ interactive_option
11
+ end
12
+ procedures = ForemanMaintain.available_procedures(:tags => tag).map do |procedure|
13
+ procedure.label.to_s
14
+ end
15
+
16
+ subcommand(dashize(tag), "Run procedures tagged ##{tag} #{procedures}", klass)
17
+ end
18
+
19
+ def execute
20
+ puts help
21
+ end
22
+
23
+ def help
24
+ if self.class.recognised_subcommands.empty?
25
+ warn 'WARNING: There were no tags found in procedures'
26
+ end
27
+ super
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,17 @@
1
+ require 'foreman_maintain/cli/advanced/procedure/abstract_procedure_command'
2
+
3
+ module ForemanMaintain
4
+ module Cli
5
+ module Procedure
6
+ class RunCommand < Base
7
+ ForemanMaintain.available_procedures(nil).each do |procedure|
8
+ klass = Class.new(AbstractProcedureCommand) do
9
+ params_to_options(procedure.params)
10
+ interactive_option
11
+ end
12
+ subcommand(dashize(procedure.label), procedure.description, klass)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ require 'foreman_maintain/cli/advanced/procedure/run_command'
2
+ require 'foreman_maintain/cli/advanced/procedure/by_tag_command'
3
+
4
+ module ForemanMaintain
5
+ module Cli
6
+ class ProcedureCommand < Base
7
+ subcommand 'run', 'Run maintain procedures manually', Procedure::RunCommand
8
+ subcommand 'by-tag', 'Run maintain procedures in bulks', Procedure::ByTagCommand
9
+ end
10
+ end
11
+ end