foreman_maintain 0.0.6 → 0.0.7

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 (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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc75bb9cfa1bb98c97e017ca86a5eb283be27ebc
4
- data.tar.gz: ca4c72fb28c52a0a87e592730954d5b5c1d87106
3
+ metadata.gz: f06770124cbd3e2be20090877be87d6180a42eb5
4
+ data.tar.gz: ac4527d5767a4a83ac0a261acb7fc909e52e7388
5
5
  SHA512:
6
- metadata.gz: 9acd9ac4a3df158361684415bf94e0c82a7d582b0fb98313a6d1b9a111ea9ab65d4476a7098b7dc9f3cca66e3363ed44ae14cae6113c846212d602e27607a413
7
- data.tar.gz: 365618e5ab301e0ed0bcc530189e35d86525ac5707573d221e58f9540ca7779b2cbc1bb9cea7ed0bba2c8cb952cd47dfdfcf9e47d1c9218f30df21673cea7fc6
6
+ metadata.gz: e0ac14d818c8eef103783ac56812c86961c4e159cd7cadb1ee18a21391d754a62af9171b7162b5aa6f6ab0bfc0056ed21c52931cbe092cea95485b4329111e58
7
+ data.tar.gz: 78c4598b243767017b594f7ee3819843025f4c5c314a3713515a6333e4ffbcecdc3e25629eba63b347716e1136de8f87941b911d2180678614cc3dd5020a581c
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Foreman Maintenance
1
+ # Foreman Maintenance [![Build Status](https://travis-ci.org/theforeman/foreman_maintain.svg?branch=master)](https://travis-ci.org/theforeman/foreman_maintain)
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
@@ -17,8 +17,80 @@ Subcommands:
17
17
  --tags tags Limit only for specific set of tags
18
18
 
19
19
  upgrade Upgrade related commands
20
- list-versions List versions this system is upgradable to
21
- check TARGET_VERSION Run pre-upgrade checks for upgradeing to specified version
20
+ list-versions List versions this system is upgradable to
21
+ check --target-version TARGET_VERSION Run pre-upgrade checks for upgradeing to specified version
22
+ run --target-version TARGET_VERSION Run the full upgrade
23
+ [--phase=phase TARGET_VERSION] Run just a specific phase of the upgrade
24
+ ```
25
+
26
+ ### Upgrades
27
+
28
+ Foreman-maintain implements upgrade tooling that helps the administrator to go
29
+ through the upgrade process.
30
+
31
+ Foreman-maintain scans the system to know, what version are available
32
+ to upgrade to for the particular system. To see what versions are available
33
+ for upgrade, run:
34
+
35
+ ```
36
+ foreman-maintain upgrade list-versions
37
+ ```
38
+
39
+ To perform just the pre-upgrade checks for the system, run:
40
+
41
+ ```
42
+ foreman-maintain upgrade check --target-version TARGET_VERSION
43
+ ```
44
+
45
+ The upgrade tooling is able to handle the full end-to-end upgrade via:
46
+
47
+ ```
48
+ foreman-maintain upgrade run --target-version TARGET_VERSION
49
+ ```
50
+
51
+ The upgrade is split into several phases with different level of impact the run
52
+ of the system:
53
+
54
+ * **pre-upgrade check** - this phase performs the checks to ensure that the system is
55
+ in ready state before the upgrade. The system should still be operational
56
+ at the current version, while this phase runs.
57
+
58
+ * **pre-migrations** - these steps perform changes on the system before
59
+ the actual upgrade stars. An example is disabling access to the system from
60
+ external sources, a.k.a. maintenance mode or disabling sync plans during the run.
61
+
62
+ After this phase ends, the system is still running the old version, and it's possible
63
+ to revert the changes by running the post-migrations steps.
64
+
65
+ * **migrations** - this phase performs the actual migrations, starting with
66
+ configuring new repositories, updated the packages and running the installer.
67
+
68
+ At the end of this phase, the system should be fully migrated to the new version.
69
+ However, the system is not fully operational yet, as the post-migrations steps
70
+ need to revert the pre-migrations steps.
71
+
72
+ * **post-migrations** - these steps revert the changes made in pre-migrations phase,
73
+ turning the system into fully-operational again.
74
+
75
+ * **post-upgrade checks** - this steps should perform sanity check of the system
76
+ to ensure the system is valid and ready to be used again.
77
+
78
+
79
+ The state of the upgrade is kept between runs, allowing to re-run the `upgrade run`
80
+ in case of failure. The tool should start at the appropriate point. For example,
81
+ in case the upgrade is already in *migrations* phase, there is no point in running
82
+ the *pre-upgrade check* phase. In case the upgrade failed before **migrations**
83
+ phase made some modifying changes, the tool tries to rollback to the previous
84
+ state of the system.
85
+
86
+ #### Satellite notes
87
+
88
+ To use custom organzation/activation key for configuring repositories during
89
+ upgrade, set the following environment variables
90
+
91
+ ```
92
+ export EXTERNAL_SAT_ORG='Sat6-CI'
93
+ export EXTERNAL_SAT_ACTIVATION_KEY='Satellite QA RHEL7'
22
94
  ```
23
95
 
24
96
  ## Implementation
@@ -5,6 +5,9 @@
5
5
  # Logger levels: mention one of debug, info, warning, error, fatal
6
6
  :log_level: 'error'
7
7
 
8
+ # Mention log file size in KB. Default set to 10000KB.
9
+ # :log_file_size: 10000
10
+
8
11
  # Mention definitions directories. Default
9
12
  # :definitions_dirs:
10
13
 
@@ -13,3 +16,6 @@
13
16
 
14
17
  # Mention directory to store whole backup data
15
18
  # :backup_dir: '/lib/foreman-maintain'
19
+
20
+ # Mention path where foreman-proxy certificates stored on filesystem
21
+ # :foreman_proxy_cert_path: '/etc/foreman'
@@ -5,6 +5,9 @@
5
5
  # Logger levels: mention one of debug, info, warning, error, fatal
6
6
  # :log_level: 'error'
7
7
 
8
+ # Mention log file size in KB. Default set to 10000KB.
9
+ # :log_file_size: 10000
10
+
8
11
  # Mention definitions directories. Default
9
12
  # :definitions_dirs:
10
13
 
@@ -14,3 +17,6 @@
14
17
  # Mention directory to store whole backup data
15
18
  :backup_dir: '/var/lib/foreman-maintain'
16
19
 
20
+ # Mention path where foreman-proxy certificates stored on filesystem
21
+ # :foreman_proxy_cert_path: '/etc/foreman'
22
+
@@ -3,7 +3,7 @@ class Checks::DiskSpeedMinimal < ForemanMaintain::Check
3
3
  label :disk_io
4
4
  description 'Check for recommended disk speed of pulp, mongodb, pgsql dir.'
5
5
  tags :pre_upgrade
6
- preparation_steps { Procedures::InstallPackage.new(:packages => %w[hdparm fio]) }
6
+ preparation_steps { Procedures::Packages::Install.new(:packages => %w[hdparm fio]) }
7
7
  end
8
8
 
9
9
  EXPECTED_IO = 80
@@ -0,0 +1,17 @@
1
+ module Checks::ForemanProxy
2
+ class VerifyDhcpConfigSyntax < ForemanMaintain::Check
3
+ metadata do
4
+ for_feature :foreman_proxy
5
+ description 'Check for verifying syntax for ISP DHCP configurations'
6
+ tags :default
7
+ confine do
8
+ file_exists?('/etc/dhcp/dhcpd.conf')
9
+ end
10
+ end
11
+
12
+ def run
13
+ success = feature(:foreman_proxy).valid_dhcp_configs?
14
+ assert(success, 'Please check and verify DHCP configurations.')
15
+ end
16
+ end
17
+ end
@@ -11,7 +11,7 @@ class Checks::SystemRegistration < ForemanMaintain::Check
11
11
 
12
12
  def run
13
13
  if system_is_self_registerd?
14
- raise ForemanMaintain::Error::Warn, 'System is self registered'
14
+ warn! 'System is self registered'
15
15
  else
16
16
  puts 'System is not self registered'
17
17
  end
@@ -11,8 +11,39 @@ class Features::Downstream < ForemanMaintain::Feature
11
11
  @current_version ||= rpm_version('satellite') || version_from_source
12
12
  end
13
13
 
14
+ def current_minor_version
15
+ current_version.to_s[/^\d+\.\d+/]
16
+ end
17
+
18
+ def setup_repositories(version)
19
+ activation_key = ENV['EXTERNAL_SAT_ACTIVATION_KEY']
20
+ org = ENV['EXTERNAL_SAT_ORG']
21
+ if activation_key
22
+ org_options = org ? %(--org #{shellescape(org)}) : ''
23
+ execute!(%(subscription-manager register #{org_options}\
24
+ --activationkey #{shellescape(activation_key)} --force))
25
+ else
26
+ execute!(%(subscription-manager repos --disable '*'))
27
+ enable_options = rh_repos(version).map { |r| "--enable=#{r}" }.join(' ')
28
+ execute!(%(subscription-manager repos #{enable_options}))
29
+ end
30
+ end
31
+
14
32
  private
15
33
 
34
+ def rh_repos(sat_version)
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')
45
+ end
46
+
16
47
  def version_from_source
17
48
  version(File.read('/usr/share/foreman/lib/satellite/version.rb')[/6\.\d\.\d/])
18
49
  end
@@ -6,4 +6,37 @@ class Features::Foreman_1_7_x < ForemanMaintain::Feature
6
6
  check_min_version('foreman', '1.7')
7
7
  end
8
8
  end
9
+
10
+ def maintenance_mode(enable_disable)
11
+ case enable_disable
12
+ when :enable
13
+ custom_iptables_chain('FOREMAN_MAINTAIN',
14
+ ['-i lo -j ACCEPT',
15
+ '-p tcp --dport 443 -j REJECT'])
16
+ when :disable
17
+ del_custom_iptables_chain('FOREMAN_MAINTAIN')
18
+ else
19
+ raise "Unexpected argument #{enable_disable}"
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def custom_iptables_chain(name, rules)
26
+ # if the chain already exists, we assume it was set before: we're not touching
27
+ # it again
28
+ return if execute?("iptables -L #{name}")
29
+ execute!("iptables -N #{name}")
30
+ rules.each do |rule|
31
+ execute!("iptables -A #{name} #{rule}")
32
+ end
33
+ execute!("iptables -I INPUT -j #{name}")
34
+ end
35
+
36
+ def del_custom_iptables_chain(name)
37
+ return unless execute?("iptables -L #{name}") # the chain is already gone
38
+ execute!("iptables -D INPUT -j #{name}")
39
+ execute!("iptables -F #{name}")
40
+ execute!("iptables -X #{name}")
41
+ end
9
42
  end
@@ -0,0 +1,72 @@
1
+ class Features::ForemanProxy < ForemanMaintain::Feature
2
+ metadata do
3
+ label :foreman_proxy
4
+ end
5
+
6
+ attr_reader :dhcpd_conf_file, :cert_path
7
+
8
+ def initialize
9
+ @dhcpd_conf_file = '/etc/dhcp/dhcpd.conf'
10
+ @cert_path = ForemanMaintain.config.foreman_proxy_cert_path
11
+ end
12
+
13
+ def valid_dhcp_configs?
14
+ dhcp_req_pass? && !syntax_error_exists?
15
+ end
16
+
17
+ private
18
+
19
+ def dhcp_curl_cmd
20
+ "curl -w '\n%{http_code}' -slient -ks --cert #{cert_path}/client_cert.pem \
21
+ --key #{cert_path}/client_key.pem \
22
+ --cacert #{cert_path}/proxy_ca.pem https://$(hostname):9090/dhcp"
23
+ end
24
+
25
+ def find_http_error_msg(array_output, curl_http_status)
26
+ http_line = ''
27
+ array_output.each do |str|
28
+ next unless str.include?('HTTP')
29
+ http_line = str
30
+ end
31
+ http_line.split(curl_http_status.to_s).last.strip
32
+ end
33
+
34
+ def run_dhcp_curl
35
+ curl_resp = execute(dhcp_curl_cmd)
36
+ array_output = curl_resp.split(/\r\n/)
37
+ result_array = array_output.last.split(/\n/)
38
+ curl_http_status = result_array.delete_at(result_array.length - 1).strip.to_i
39
+ curl_http_resp = json_parse(result_array.join(''))
40
+ ForemanMaintain::Utils::CurlResponse.new(
41
+ curl_http_resp,
42
+ curl_http_status,
43
+ find_http_error_msg(array_output, curl_http_status)
44
+ )
45
+ end
46
+
47
+ def dhcp_req_pass?
48
+ dhcp_curl_resp = run_dhcp_curl
49
+ success = true
50
+ if dhcp_curl_resp.http_code.eql?(200)
51
+ if dhcp_curl_resp.result.empty?
52
+ success = false
53
+ puts "Verify DHCP Settings. Response: #{dhcp_curl_resp.result.inspect}"
54
+ end
55
+ else
56
+ success = false
57
+ puts dhcp_curl_resp.error_msg
58
+ end
59
+ success
60
+ end
61
+
62
+ def syntax_error_exists?
63
+ cmd = "dhcpd -t -cf #{dhcpd_conf_file}"
64
+ output = execute(cmd)
65
+ is_error = output.include?('Configuration file errors encountered')
66
+ if is_error
67
+ puts "\nFound syntax error in file #{dhcpd_conf_file}:"
68
+ puts output
69
+ end
70
+ is_error
71
+ end
72
+ end
@@ -20,10 +20,6 @@ class Features::SyncPlans < ForemanMaintain::Feature
20
20
  ).map { |r| r['id'].to_i }
21
21
  end
22
22
 
23
- def disabled_plans_count
24
- data[:disabled].length
25
- end
26
-
27
23
  def make_disable(ids)
28
24
  update_records(ids, false)
29
25
  end
@@ -32,6 +28,14 @@ class Features::SyncPlans < ForemanMaintain::Feature
32
28
  update_records(data[:disabled], true)
33
29
  end
34
30
 
31
+ def load_from_storage(storage)
32
+ @data = storage.data.fetch(:sync_plans, :enabled => [], :disabled => [])
33
+ end
34
+
35
+ def save_to_storage(storage)
36
+ storage[:sync_plans] = @data
37
+ end
38
+
35
39
  private
36
40
 
37
41
  def update_records(ids, enabled)
@@ -46,30 +50,20 @@ class Features::SyncPlans < ForemanMaintain::Feature
46
50
  end
47
51
  updated_record_ids
48
52
  ensure
49
- new_data = sync_plan_data(enabled, updated_record_ids)
50
- save_state(new_data)
53
+ update_data(enabled, updated_record_ids)
51
54
  end
52
55
 
53
56
  def data
54
- upgrade_storage = ForemanMaintain.storage(:upgrade)
55
- @data ||= upgrade_storage.data.fetch(:sync_plans, :enabled => [], :disabled => [])
57
+ raise 'Use load_from_storage before accessing the data' unless defined? @data
56
58
  @data
57
59
  end
58
60
 
59
- def sync_plan_data(enabled, new_ids)
60
- sync_plan_hash = data
61
+ def update_data(enabled, new_ids)
61
62
  if enabled
62
- sync_plan_hash[:disabled] -= new_ids
63
- sync_plan_hash[:enabled] = new_ids
63
+ @data[:disabled] -= new_ids
64
+ @data[:enabled] = new_ids
64
65
  else
65
- sync_plan_hash[:disabled].concat(new_ids)
66
+ @data[:disabled].concat(new_ids)
66
67
  end
67
- sync_plan_hash
68
- end
69
-
70
- def save_state(sync_plan_hash = {})
71
- storage = ForemanMaintain.storage(:upgrade)
72
- storage[:sync_plans] = sync_plan_hash
73
- storage.save
74
68
  end
75
69
  end
@@ -6,4 +6,8 @@ class Features::Upstream < ForemanMaintain::Feature
6
6
  !downstream_installation?
7
7
  end
8
8
  end
9
+
10
+ def setup_repositories(_version)
11
+ raise NotImplementedError
12
+ end
9
13
  end
@@ -2,6 +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
6
  end
6
7
 
7
8
  def run
@@ -26,7 +27,7 @@ module Procedures::ForemanTasks
26
27
  end
27
28
  end
28
29
 
29
- def description
30
+ def runtime_message
30
31
  "Delete #{@state} tasks"
31
32
  end
32
33
  end
@@ -1,4 +1,8 @@
1
1
  class Procedures::HammerSetup < ForemanMaintain::Procedure
2
+ metadata do
3
+ description 'setup hammer'
4
+ end
5
+
2
6
  def run
3
7
  setup_from_default || setup_from_answers
4
8
  puts "New settings saved into #{hammer.config_file}"
@@ -9,10 +13,6 @@ class Procedures::HammerSetup < ForemanMaintain::Procedure
9
13
  !hammer.ready?
10
14
  end
11
15
 
12
- def description
13
- 'Setup hammer'
14
- end
15
-
16
16
  private
17
17
 
18
18
  def setup_from_default
@@ -0,0 +1,19 @@
1
+ module Procedures::Installer
2
+ class Upgrade < ForemanMaintain::Procedure
3
+ def run
4
+ execute!("#{installer_command} --upgrade", :interactive => true)
5
+ end
6
+
7
+ private
8
+
9
+ def installer_command
10
+ if package_version('satellite-installer')
11
+ 'satellite-installer'
12
+ elsif package_version('katello-installer')
13
+ 'katello-installer'
14
+ else
15
+ 'foreman-installer'
16
+ end
17
+ end
18
+ end
19
+ end