foreman_maintain 0.8.20 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/definitions/checks/check_for_newer_packages.rb +5 -3
  3. data/definitions/checks/disk/performance.rb +19 -8
  4. data/definitions/checks/foreman/check_puppet_capsules.rb +43 -0
  5. data/definitions/checks/repositories/validate.rb +1 -2
  6. data/definitions/checks/restore/validate_interfaces.rb +24 -0
  7. data/definitions/features/candlepin.rb +1 -2
  8. data/definitions/features/foreman_tasks.rb +11 -0
  9. data/definitions/features/pulpcore.rb +2 -1
  10. data/definitions/features/system_repos.rb +8 -0
  11. data/definitions/procedures/backup/metadata.rb +11 -0
  12. data/definitions/procedures/content/prepare.rb +1 -1
  13. data/definitions/procedures/installer/upgrade_rake_task.rb +3 -1
  14. data/definitions/procedures/pulpcore/migrate.rb +1 -1
  15. data/definitions/procedures/puppet/remove_puppet.rb +50 -0
  16. data/definitions/procedures/puppet/remove_puppet_data.rb +21 -0
  17. data/definitions/procedures/repositories/backup_enabled_repos.rb +16 -0
  18. data/definitions/procedures/repositories/enable.rb +13 -0
  19. data/definitions/procedures/repositories/setup.rb +0 -4
  20. data/definitions/procedures/restore/configs.rb +5 -1
  21. data/definitions/scenarios/puppet.rb +21 -0
  22. data/definitions/scenarios/restore.rb +14 -1
  23. data/definitions/scenarios/self_upgrade.rb +102 -0
  24. data/lib/foreman_maintain/cli/plugin_command.rb +14 -0
  25. data/lib/foreman_maintain/cli/restore_command.rb +5 -1
  26. data/lib/foreman_maintain/cli/self_upgrade_command.rb +38 -0
  27. data/lib/foreman_maintain/cli.rb +4 -0
  28. data/lib/foreman_maintain/concerns/os_facts.rb +70 -0
  29. data/lib/foreman_maintain/concerns/system_helpers.rb +12 -33
  30. data/lib/foreman_maintain/utils/backup.rb +36 -11
  31. data/lib/foreman_maintain/utils/command_runner.rb +2 -1
  32. data/lib/foreman_maintain/utils.rb +0 -1
  33. data/lib/foreman_maintain/version.rb +1 -1
  34. data/lib/foreman_maintain.rb +1 -0
  35. metadata +31 -7
  36. data/lib/foreman_maintain/utils/facter.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72beb43529d9eb83adadc1f644b7e67cf8276d19527af380a94405affc16894b
4
- data.tar.gz: 6a08f0bb85ad408f9dac5e904e7c6f5af30eba339e919e44d8740332fb8d33d3
3
+ metadata.gz: dcef2fd68b963d566c30be2531b1f09bf71da02eb8cd06e2c280f9d4a6222fc0
4
+ data.tar.gz: 5a1448015d72fe8e8ae19c73eff430b13387c699689a5dbbdd0b73bbbe49c9f0
5
5
  SHA512:
6
- metadata.gz: 480de2bbfe003b974b86d8f5baebdd624f3ebf407260f914b368c615fbc8481eb2b6c8d7592bd25f30f1055d892d7170385cbbdd06e84ec7100cd554fae993c8
7
- data.tar.gz: 752ed2fb124297336e477357786adb1f8b157fe319bb13872d6cf684a5fbd9908d4e66c482bedf23cd5ef84ff75f573030e377a0e92a65e8f555fa793b85846a
6
+ metadata.gz: 348bedd61056cffd63610b9a91d0e8c2a31e3012ec0e41880e05195ae840a61bd14c7d84ea23715cae771272f555b95f05085e4fb1fefc01a4f1a1f84880648d
7
+ data.tar.gz: 76f1871c0edb9671ec0a45fec272afed10ae05bb9ebab4b92ecc3f7960bb1a7625b9267eba032fb6335fac1e8cc32116047e87dab109fb8745ce37e212399768
@@ -33,9 +33,11 @@ class Checks::CheckForNewerPackages < ForemanMaintain::Check
33
33
  end
34
34
 
35
35
  unless packages_with_updates.empty?
36
- failure_message = 'An update is available for package(s): '\
37
- "#{packages_with_updates.join(',')}. Please update before proceeding!"
38
- fail! failure_message
36
+ command = ForemanMaintain.pkg_and_cmd_name[1]
37
+ fail! 'Required updates for some packages detected.'\
38
+ "\nPlease update to the latest #{@manual_confirmation_version}.z release "\
39
+ 'before proceeding, using:'\
40
+ "\n# #{command} upgrade run --target-version #{@manual_confirmation_version}.z"
39
41
  end
40
42
  end
41
43
 
@@ -39,8 +39,8 @@ module Checks
39
39
  end
40
40
  end
41
41
 
42
- def default_dirs
43
- @default_dirs ||= %i[pulp2 pulpcore_database mongo foreman_database].inject({}) do |dirs, f|
42
+ def data_dirs
43
+ @data_dirs ||= %i[pulpcore_database mongo foreman_database].inject({}) do |dirs, f|
44
44
  if feature(f) && File.directory?(feature(f).data_dir)
45
45
  dirs[feature(f).label_dashed] = feature(f).data_dir
46
46
  end
@@ -48,20 +48,32 @@ module Checks
48
48
  end
49
49
  end
50
50
 
51
+ def pulp_dir
52
+ @pulp_dir ||= begin
53
+ pulp_feature = feature(:pulp2) || feature(:pulpcore_database)
54
+ { pulp_feature.label_dashed => pulp_feature.pulp_data_dir }
55
+ end
56
+ end
57
+
51
58
  def description
52
- "Check recommended disk speed for #{default_dirs.keys.join(', ')} directories."
59
+ 'Check recommended disk speed for '\
60
+ "#{[data_dirs.keys | pulp_dir.keys].join(', ')} directories."
61
+ end
62
+
63
+ def all_dirs
64
+ data_dirs.values | pulp_dir.values
53
65
  end
54
66
 
55
67
  def check_only_single_device?
56
- default_dirs.values do |dir|
68
+ all_dirs.each do |dir|
57
69
  ForemanMaintain::Utils::Disk::Device.new(dir).name
58
70
  end.uniq.length <= 1
59
71
  end
60
72
 
61
73
  def dirs_to_check
62
- return default_dirs.values.first(1) if check_only_single_device?
74
+ return all_dirs.first(1) if check_only_single_device?
63
75
 
64
- default_dirs.values
76
+ all_dirs
65
77
  end
66
78
 
67
79
  private
@@ -74,11 +86,10 @@ module Checks
74
86
  def compute_disk_speed(spinner)
75
87
  success = true
76
88
  io_obj = ForemanMaintain::Utils::Disk::NilDevice.new
77
-
78
89
  dirs_to_check.each do |dir|
79
90
  io_obj = ForemanMaintain::Utils::Disk::Device.new(dir)
80
91
 
81
- spinner.update("[Speed check In-Progress] device: #{io_obj.name}")
92
+ spinner.update("[Speed check In-Progress] device:#{io_obj.name}")
82
93
  stats << io_obj
83
94
 
84
95
  next if io_obj.read_speed >= EXPECTED_IO
@@ -0,0 +1,43 @@
1
+ module Checks
2
+ class CheckPuppetCapsules < ForemanMaintain::Check
3
+ metadata do
4
+ label :puppet_capsules
5
+ for_feature :foreman_database
6
+ description 'Check for Puppet capsules from the database'
7
+ manual_detection
8
+ end
9
+
10
+ def run
11
+ puppet_proxies = find_puppet_proxies.reject { |proxy| local_proxy?(proxy['url']) }
12
+ unless puppet_proxies.empty?
13
+ names = puppet_proxies.map { |proxy| proxy['name'] }
14
+ print('You have proxies with Puppet feature enabled, '\
15
+ "please disable Puppet on all proxies first.\n"\
16
+ "The following proxies have Puppet feature: #{names.join(', ')}.")
17
+ abort!
18
+ end
19
+ end
20
+
21
+ def find_puppet_proxies
22
+ feature(:foreman_database).query(puppet_proxies_query)
23
+ end
24
+
25
+ private
26
+
27
+ def local_proxy?(url)
28
+ URI.parse(url).hostname.casecmp(hostname) == 0
29
+ end
30
+
31
+ def puppet_proxies_query
32
+ <<-SQL
33
+ SELECT \"smart_proxies\".*
34
+ FROM \"smart_proxies\"
35
+ INNER JOIN \"smart_proxy_features\"
36
+ ON \"smart_proxies\".\"id\" = \"smart_proxy_features\".\"smart_proxy_id\"
37
+ INNER JOIN \"features\"
38
+ ON \"features\".\"id\" = \"smart_proxy_features\".\"feature_id\"
39
+ WHERE \"features\".\"name\" = 'Puppet'
40
+ SQL
41
+ end
42
+ end
43
+ end
@@ -3,8 +3,7 @@ module Checks::Repositories
3
3
  metadata do
4
4
  description 'Validate availability of repositories'
5
5
  preparation_steps do
6
- [Checks::Repositories::CheckNonRhRepository.new,
7
- Procedures::Packages::Install.new(:packages => [ForemanMaintain::Utils::Facter.package])]
6
+ Checks::Repositories::CheckNonRhRepository.new
8
7
  end
9
8
 
10
9
  confine do
@@ -0,0 +1,24 @@
1
+ require 'foreman_maintain/utils/backup'
2
+
3
+ module Checks::Restore
4
+ class ValidateInterfaces < ForemanMaintain::Check
5
+ metadata do
6
+ description 'Validate network interfaces match the backup'
7
+
8
+ param :backup_dir,
9
+ 'Path to backup directory',
10
+ :required => true
11
+ manual_detection
12
+ end
13
+
14
+ def run
15
+ backup = ForemanMaintain::Utils::Backup.new(@backup_dir)
16
+ invalid_interfaces = backup.validate_interfaces
17
+ msg = 'The following features are enabled in the backup, '\
18
+ "\nbut the system does not have the interfaces used by these features: "
19
+ msg << invalid_interfaces.map { |k, v| "#{k} (#{v['configured']})" }.join(', ')
20
+ msg << '.'
21
+ assert(backup.validate_interfaces.empty?, msg)
22
+ end
23
+ end
24
+ end
@@ -13,8 +13,7 @@ class Features::Candlepin < ForemanMaintain::Feature
13
13
 
14
14
  def services
15
15
  [
16
- system_service('tomcat', 20),
17
- system_service('tomcat6', 20)
16
+ system_service('tomcat', 20)
18
17
  ]
19
18
  end
20
19
  end
@@ -17,6 +17,17 @@ class Features::ForemanTasks < ForemanMaintain::Feature
17
17
  Actions::Candlepin::ListenOnCandlepinEvents
18
18
  Actions::Katello::EventQueue::Monitor
19
19
  Actions::Insights::EmailPoller
20
+ ForemanInventoryUpload::Async::GenerateReportJob
21
+ ForemanInventoryUpload::Async::QueueForUploadJob
22
+ ForemanInventoryUpload::Async::UploadReportJob
23
+ InsightsCloud::Async::InsightsClientStatusAging
24
+ InsightsCloud::Async::InsightsFullSync
25
+ InsightsCloud::Async::InsightsResolutionsSync
26
+ InsightsCloud::Async::InsightsRulesSync
27
+ InventorySync::Async::InventoryFullSync
28
+ InventorySync::Async::InventoryHostsSync
29
+ InventorySync::Async::InventoryScheduledSync
30
+ InventorySync::Async::InventorySelfHostSync
20
31
  ].freeze
21
32
 
22
33
  metadata do
@@ -37,7 +37,8 @@ class Features::Pulpcore < ForemanMaintain::Feature
37
37
 
38
38
  def config_files
39
39
  [
40
- '/etc/pulp/settings.py'
40
+ '/etc/pulp/settings.py',
41
+ '/etc/pulp/certs/database_fields.symmetric.key'
41
42
  ]
42
43
  end
43
44
 
@@ -21,6 +21,10 @@ class Features::SystemRepos < ForemanMaintain::Feature
21
21
  Hash[*repos.delete!(' ').split("\n")]
22
22
  end
23
23
 
24
+ def enabled_repos_ids
25
+ trim_repoids(enabled_repos_hash.keys)
26
+ end
27
+
24
28
  def upstream_repos_ids
25
29
  trim_repoids(upstream_repos.keys)
26
30
  end
@@ -29,6 +33,10 @@ class Features::SystemRepos < ForemanMaintain::Feature
29
33
  execute!("yum-config-manager --disable #{repo_ids.join(',')}")
30
34
  end
31
35
 
36
+ def enable_repos(repo_ids)
37
+ execute!("yum-config-manager --enable #{repo_ids.join(',')}")
38
+ end
39
+
32
40
  private
33
41
 
34
42
  def trim_repoids(repos)
@@ -9,6 +9,8 @@ module Procedures::Backup
9
9
  param :online_backup, 'Select for online backup', :flag => true, :default => false
10
10
  end
11
11
 
12
+ PROXY_CONFIG_ENTRIES = %w[dns dns_interface dhcp dhcp_interface].freeze
13
+
12
14
  def run
13
15
  with_spinner('Collecting metadata') do |spinner|
14
16
  metadata = {}
@@ -18,6 +20,8 @@ module Procedures::Backup
18
20
  metadata['rpms'] = rpms(spinner)
19
21
  metadata['incremental'] = @incremental_dir || false
20
22
  metadata['online'] = @online_backup
23
+ metadata['hostname'] = hostname
24
+ metadata['proxy_config'] = proxy_config(spinner)
21
25
  save_metadata(metadata, spinner)
22
26
  end
23
27
  end
@@ -54,5 +58,12 @@ module Procedures::Backup
54
58
  feature(:foreman_proxy).features
55
59
  end
56
60
  end
61
+
62
+ def proxy_config(spinner)
63
+ spinner.update('Collecting proxy configuration')
64
+ feature(:installer).answers['foreman_proxy'].select do |key, _|
65
+ PROXY_CONFIG_ENTRIES.include?(key)
66
+ end
67
+ end
57
68
  end
58
69
  end
@@ -10,7 +10,7 @@ module Procedures::Content
10
10
  sleep(20) # in satellite 6.9 the services are still coming up
11
11
  # use interactive to get realtime output
12
12
  env_vars = @quiet ? '' : 'preserve_output=true '
13
- puts execute!("#{env_vars}foreman-rake katello:pulp3_migration", :interactive => true)
13
+ execute!("#{env_vars}foreman-rake katello:pulp3_migration", :interactive => true)
14
14
  end
15
15
  end
16
16
  end
@@ -5,7 +5,9 @@ module Procedures::Installer
5
5
  end
6
6
 
7
7
  def run
8
- execute!('foreman-rake upgrade:run')
8
+ # only run this in the Satellite scenario, as in others
9
+ # the installer runs this rake task for us already
10
+ execute!('foreman-rake upgrade:run') if feature(:satellite)
9
11
  end
10
12
  end
11
13
  end
@@ -18,7 +18,7 @@ module Procedures::Pulpcore
18
18
  spinner.update('Migrating pulpcore database')
19
19
  execute!('sudo PULP_SETTINGS=/etc/pulp/settings.py '\
20
20
  'DJANGO_SETTINGS_MODULE=pulpcore.app.settings '\
21
- 'python3-django-admin migrate --noinput')
21
+ 'pulpcore-manager migrate --noinput')
22
22
  end
23
23
  end
24
24
  end
@@ -0,0 +1,50 @@
1
+ module Procedures::Puppet
2
+ class RemovePuppet < ForemanMaintain::Procedure
3
+ metadata do
4
+ description 'Remove Puppet feature'
5
+ confine do
6
+ feature(:puppet_server) &&
7
+ (check_min_version('foreman', '3.0') || check_min_version('foreman-proxy', '3.0'))
8
+ end
9
+ advanced_run false
10
+ end
11
+
12
+ def run
13
+ services = feature(:foreman_server).services + feature(:dynflow_sidekiq).services
14
+ Procedures::Service::Stop.new(:only => services)
15
+ execute!('foreman-rake db:migrate VERSION=0 SCOPE=foreman_puppet') if server_with_puppet?
16
+ feature(:installer).run(installer_arguments_disabling_puppet.join(' '), :interactive => false)
17
+ packages_action(:remove, packages_to_remove, :assumeyes => true)
18
+ end
19
+
20
+ private
21
+
22
+ def server_with_puppet?
23
+ find_package(foreman_plugin_name('foreman_puppet'))
24
+ end
25
+
26
+ def installer_arguments_disabling_puppet
27
+ answers = feature(:installer).answers
28
+
29
+ options = []
30
+ options << '--no-enable-puppet' if answers.key?('puppet')
31
+ options << '--no-enable-foreman-plugin-puppet' if answers['foreman::plugin::puppet']
32
+ options << '--no-enable-foreman-cli-puppet' if answers['foreman::cli::puppet']
33
+ if answers['foreman_proxy']
34
+ options << '--foreman-proxy-puppet false'
35
+ options << '--foreman-proxy-puppetca false'
36
+ end
37
+ options << '--foreman-proxy-content-puppet false' if answers.key?('foreman_proxy_content')
38
+ options
39
+ end
40
+
41
+ def packages_to_remove
42
+ packages = ['puppetserver']
43
+ if server_with_puppet?
44
+ packages << foreman_plugin_name('foreman_puppet')
45
+ packages << hammer_plugin_name('foreman_puppet')
46
+ end
47
+ packages
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,21 @@
1
+ module Procedures::Puppet
2
+ class RemovePuppetData < ForemanMaintain::Procedure
3
+ metadata do
4
+ description 'Remove Puppet data'
5
+ end
6
+
7
+ def run
8
+ execute!('foreman-rake purge:puppet')
9
+ execute!('rm -r ' + files_to_purge.join(' '))
10
+ end
11
+
12
+ private
13
+
14
+ def files_to_purge
15
+ %w[
16
+ /etc/puppetlabs
17
+ /opt/puppetlabs/server/data
18
+ ]
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ module Procedures::Repositories
2
+ class BackupEnabledRepos < ForemanMaintain::Procedure
3
+ metadata do
4
+ label :backup_enabled_repos
5
+ description 'Stores enabled repositories in yaml file'
6
+ end
7
+
8
+ def run
9
+ enabled_repos_ids = feature(:system_repos).enabled_repos_ids
10
+ unless enabled_repos_ids.empty?
11
+ backup_dir = File.expand_path(ForemanMaintain.config.backup_dir)
12
+ File.write(File.join(backup_dir, 'enabled_repos.yml'), enabled_repos_ids.to_yaml)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Procedures::Repositories
2
+ class Enable < ForemanMaintain::Procedure
3
+ metadata do
4
+ param :repos, 'List of repositories to enable'
5
+ description 'Enable repositories'
6
+ end
7
+ def run
8
+ with_spinner('Enabling repositories') do
9
+ feature(:system_repos).enable_repos(@repos)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -2,10 +2,6 @@ module Procedures::Repositories
2
2
  class Setup < ForemanMaintain::Procedure
3
3
  metadata do
4
4
  description 'Setup repositories'
5
- preparation_steps do
6
- Procedures::Packages::Install.new(:packages => [ForemanMaintain::Utils::Facter.package])
7
- end
8
-
9
5
  confine do
10
6
  feature(:instance).downstream || feature(:upstream)
11
7
  end
@@ -56,7 +56,11 @@ module Procedures::Restore
56
56
  def reset_qpid_jrnls
57
57
  # on restore without pulp data qpid fails to start
58
58
  # https://access.redhat.com/solutions/4645231
59
- execute('rm -rf /var/lib/qpidd/.qpidd/qls/dat2/__db.00*')
59
+ ['/var/lib/qpidd/.qpidd/', '/var/lib/qpidd/'].each do |qpidd_path|
60
+ if Dir.exist?("#{qpidd_path}/qls/dat2/")
61
+ execute("rm -rf #{qpidd_path}/qls/dat2/__db.00*")
62
+ end
63
+ end
60
64
  end
61
65
  end
62
66
  end
@@ -0,0 +1,21 @@
1
+ module ForemanMaintain::Scenarios
2
+ module Puppet
3
+ class RemovePuppet < ForemanMaintain::Scenario
4
+ metadata do
5
+ description 'Remove Puppet feature'
6
+ tags :puppet_disable
7
+ label :puppet_disable
8
+ param :remove_data, 'Purge the Puppet data after disabling plugin'
9
+ manual_detection
10
+ end
11
+
12
+ def compose
13
+ if check_min_version('foreman', '3.0') || check_min_version('foreman-proxy', '3.0')
14
+ add_step(Checks::CheckPuppetCapsules) if server?
15
+ add_step(Procedures::Puppet::RemovePuppet)
16
+ add_step(Procedures::Puppet::RemovePuppetData) if context.get(:remove_data)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -6,18 +6,27 @@ module ForemanMaintain::Scenarios
6
6
  description 'Restore backup'
7
7
  param :backup_dir, 'Path to backup directory'
8
8
  param :incremental_backup, 'Is the backup incremental?'
9
+ param :dry_run, 'Check if backup could be restored, without performing the restore'
9
10
  manual_detection
10
11
  end
11
12
 
12
13
  # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
14
+ # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
13
15
  def compose
14
16
  backup = ForemanMaintain::Utils::Backup.new(context.get(:backup_dir))
15
17
 
16
18
  add_steps(find_checks(:root_user))
17
19
  supported_version_check
18
20
  add_steps_with_context(Checks::Restore::ValidateBackup,
19
- Procedures::Restore::Confirmation,
20
21
  Checks::Restore::ValidateHostname,
22
+ Checks::Restore::ValidateInterfaces)
23
+
24
+ if context.get(:dry_run)
25
+ self.class.metadata[:run_strategy] = :fail_slow
26
+ return
27
+ end
28
+
29
+ add_steps_with_context(Procedures::Restore::Confirmation,
21
30
  Procedures::Selinux::SetFileSecurity,
22
31
  Procedures::Restore::Configs)
23
32
  add_step_with_context(Procedures::Crond::Stop) if feature(:cron)
@@ -42,9 +51,12 @@ module ForemanMaintain::Scenarios
42
51
  add_steps_with_context(Procedures::Restore::RegenerateQueues) if backup.online_backup?
43
52
  add_steps_with_context(Procedures::Service::Start,
44
53
  Procedures::Service::DaemonReload)
54
+ add_step(Procedures::Installer::Upgrade.new(:assumeyes => true))
55
+ add_step_with_context(Procedures::Installer::UpgradeRakeTask)
45
56
  add_step_with_context(Procedures::Crond::Start) if feature(:cron)
46
57
  end
47
58
  # rubocop:enable Metrics/MethodLength,Metrics/AbcSize
59
+ # rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
48
60
 
49
61
  def drop_dbs(backup)
50
62
  if backup.file_map[:candlepin_dump][:present] ||
@@ -87,6 +99,7 @@ module ForemanMaintain::Scenarios
87
99
  context.map(:backup_dir,
88
100
  Checks::Restore::ValidateBackup => :backup_dir,
89
101
  Checks::Restore::ValidateHostname => :backup_dir,
102
+ Checks::Restore::ValidateInterfaces => :backup_dir,
90
103
  Procedures::Restore::Configs => :backup_dir,
91
104
  Procedures::Restore::DropDatabases => :backup_dir,
92
105
  Procedures::Restore::PgGlobalObjects => :backup_dir,
@@ -0,0 +1,102 @@
1
+ module ForemanMaintain::Scenarios
2
+ class SelfUpgradeBase < ForemanMaintain::Scenario
3
+ def enabled_system_repos_id
4
+ feature(:system_repos).enabled_repos_ids
5
+ end
6
+
7
+ def enable_repos(repo_ids = stored_enabled_repos_ids)
8
+ add_step(Procedures::Repositories::Enable.new(repos: repo_ids))
9
+ end
10
+
11
+ def disable_repos(repo_ids = stored_enabled_repos_ids)
12
+ add_step(Procedures::Repositories::Disable.new(repos: repo_ids))
13
+ end
14
+
15
+ def target_version
16
+ @target_version ||= context.get(:target_version)
17
+ end
18
+
19
+ def current_version
20
+ feature(:instance).downstream.current_minor_version
21
+ end
22
+
23
+ def maintenance_repo_id(version)
24
+ if (repo = ENV['maintenance_repo'])
25
+ return repo unless repo.empty?
26
+ end
27
+
28
+ maintenance_repo(version)
29
+ end
30
+
31
+ def maintenance_repo(version)
32
+ if el7?
33
+ "rhel-#{el_major_version}-server-satellite-maintenance-#{version}-rpms"
34
+ else
35
+ "satellite-maintenance-#{version}-for-rhel-#{el_major_version}-x86_64-rpms"
36
+ end
37
+ end
38
+
39
+ def maintenance_repo_version
40
+ return '6' if current_version == '6.10'
41
+
42
+ current_version
43
+ end
44
+
45
+ def stored_enabled_repos_ids
46
+ @stored_enabled_repos_ids ||= begin
47
+ path = File.expand_path('enabled_repos.yml', ForemanMaintain.config.backup_dir)
48
+ @stored_enabled_repos_ids = File.file?(path) ? YAML.load(File.read(path)) : []
49
+ end
50
+ end
51
+
52
+ def all_maintenance_repos
53
+ repo_regex = if el7?
54
+ /rhel-\d-server-satellite-maintenance-\d.\d-rpms/
55
+ else
56
+ /satellite-maintenance-\d.\d-for-rhel-\d-x86_64-rpms/
57
+ end
58
+ stored_enabled_repos_ids.select { |id| !id.match(repo_regex).nil? }
59
+ end
60
+
61
+ def repos_ids_to_reenable
62
+ repos_ids_to_reenable = stored_enabled_repos_ids - all_maintenance_repos
63
+ repos_ids_to_reenable << maintenance_repo(maintenance_repo_version)
64
+ end
65
+ end
66
+
67
+ class SelfUpgrade < SelfUpgradeBase
68
+ metadata do
69
+ label :self_upgrade_foreman_maintain
70
+ description "Enables the specified version's maintenance repository and, "\
71
+ 'updates the foreman-maintain packages'
72
+ manual_detection
73
+ end
74
+
75
+ def compose
76
+ if check_min_version('foreman', '2.5') || check_min_version('foreman-proxy', '2.5')
77
+ pkgs_to_update = %w[satellite-maintain rubygem-foreman_maintain]
78
+ add_step(Procedures::Repositories::BackupEnabledRepos.new)
79
+ disable_repos
80
+ add_step(Procedures::Repositories::Enable.new(repos: [maintenance_repo_id(target_version)]))
81
+ add_step(Procedures::Packages::Update.new(packages: pkgs_to_update, assumeyes: true))
82
+ enable_repos(repos_ids_to_reenable)
83
+ end
84
+ end
85
+ end
86
+
87
+ class SelfUpgradeRescue < SelfUpgradeBase
88
+ metadata do
89
+ label :rescue_self_upgrade
90
+ description 'Disables all version specific maintenance repos and,'\
91
+ ' enables the repositories which were configured prior to self upgrade'
92
+ manual_detection
93
+ run_strategy :fail_slow
94
+ end
95
+
96
+ def compose
97
+ if check_min_version('foreman', '2.5') || check_min_version('foreman-proxy', '2.5')
98
+ enable_repos(repos_ids_to_reenable)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,14 @@
1
+ module ForemanMaintain
2
+ module Cli
3
+ class PluginCommand < Base
4
+ subcommand 'purge-puppet', 'Remove the Puppet feature' do
5
+ option ['-f', '--remove-all-data'], :flag, 'Purge all the Puppet data',
6
+ :attribute_name => :remove_data
7
+
8
+ def execute
9
+ run_scenarios_and_exit(Scenarios::Puppet::RemovePuppet.new(:remove_data => remove_data?))
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -7,11 +7,15 @@ module ForemanMaintain
7
7
 
8
8
  option ['-i', '--incremental'], :flag, 'Restore an incremental backup',
9
9
  :attribute_name => :incremental, :completion => { :type => :directory }
10
+ option ['-n', '--dry-run'], :flag,
11
+ 'Check if backup could be restored, without performing the restore',
12
+ :attribute_name => :dry_run
10
13
 
11
14
  def execute
12
15
  scenario = Scenarios::Restore.new(
13
16
  :backup_dir => @backup_dir,
14
- :incremental_backup => @incremental || incremental_backup?
17
+ :incremental_backup => @incremental || incremental_backup?,
18
+ :dry_run => @dry_run
15
19
  )
16
20
  rescue_scenario = Scenarios::RestoreRescue.new
17
21
  run_scenario(scenario, rescue_scenario)
@@ -0,0 +1,38 @@
1
+ module ForemanMaintain
2
+ module Cli
3
+ class SelfUpgradeCommand < Base
4
+ option ['--target-version'], 'TARGET_VERSION',\
5
+ 'Major version of the Satellite or Capsule'\
6
+ ', e.g 7.0', :required => true
7
+ def execute
8
+ allow_major_version_upgrade_only
9
+ run_scenario(upgrade_scenario, upgrade_rescue_scenario)
10
+ end
11
+
12
+ def upgrade_scenario
13
+ Scenarios::SelfUpgrade.new(target_version: target_version)
14
+ end
15
+
16
+ def upgrade_rescue_scenario
17
+ Scenarios::SelfUpgradeRescue.new(target_version: target_version)
18
+ end
19
+
20
+ def current_downstream_version
21
+ ForemanMaintain.detector.feature(:instance).downstream.current_version
22
+ end
23
+
24
+ def allow_major_version_upgrade_only
25
+ begin
26
+ next_version = Gem::Version.new(target_version)
27
+ rescue ArgumentError => err
28
+ raise Error::UsageError, "Invalid version! #{err}"
29
+ end
30
+ if current_downstream_version >= next_version
31
+ message = "The target-version #{target_version} should be "\
32
+ "greater than existing version #{current_downstream_version}!"
33
+ raise Error::UsageError, message
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -11,6 +11,8 @@ require 'foreman_maintain/cli/restore_command'
11
11
  require 'foreman_maintain/cli/maintenance_mode_command'
12
12
  require 'foreman_maintain/cli/packages_command'
13
13
  require 'foreman_maintain/cli/content_command'
14
+ require 'foreman_maintain/cli/plugin_command'
15
+ require 'foreman_maintain/cli/self_upgrade_command'
14
16
 
15
17
  module ForemanMaintain
16
18
  module Cli
@@ -25,6 +27,8 @@ module ForemanMaintain
25
27
  subcommand 'packages', 'Lock/Unlock package protection, install, update', PackagesCommand
26
28
  subcommand 'advanced', 'Advanced tools for server maintenance', AdvancedCommand
27
29
  subcommand 'content', 'Content related commands', ContentCommand
30
+ subcommand 'plugin', 'Manage optional plugins on your server', PluginCommand
31
+ subcommand 'self-upgrade', 'Perform major version self upgrade', SelfUpgradeCommand
28
32
  subcommand 'maintenance-mode', 'Control maintenance-mode for application',
29
33
  MaintenanceModeCommand
30
34
  if ForemanMaintain.detector.feature(:satellite) &&
@@ -0,0 +1,70 @@
1
+ module ForemanMaintain
2
+ module Concerns
3
+ module OsFacts
4
+ OS_RELEASE_FILE = '/etc/os-release'.freeze
5
+ FALLBACK_OS_RELEASE_FILE = '/usr/lib/os-release'.freeze
6
+
7
+ def os_release_file
8
+ if File.file?(OS_RELEASE_FILE)
9
+ return OS_RELEASE_FILE
10
+ elsif File.file?(FALLBACK_OS_RELEASE_FILE)
11
+ return FALLBACK_OS_RELEASE_FILE
12
+ else
13
+ puts "The #{OS_RELEASE_FILE} and #{FALLBACK_OS_RELEASE_FILE} files are missing! "\
14
+ "Can't continue the execution without Operating System's facts!"
15
+ exit 1
16
+ end
17
+ end
18
+
19
+ def facts
20
+ unless defined?(@facts)
21
+ @facts = {}
22
+ regex = /^(["'])(.*)(\1)$/
23
+ File.open(os_release_file) do |file|
24
+ file.readlines.each do |line|
25
+ line.strip! # drop any whitespace, including newlines from start and end of the line
26
+ next if line.start_with?('#') # ignore comments
27
+ # split at most into 2 items, if the value ever contains an =
28
+ key, value = line.split('=', 2)
29
+ next unless key && value
30
+ @facts[key] = value.gsub(regex, '\2').delete('\\')
31
+ end
32
+ end
33
+ end
34
+ @facts
35
+ end
36
+
37
+ def os_version_id
38
+ facts.fetch('VERSION_ID')
39
+ end
40
+
41
+ def os_id
42
+ facts.fetch('ID')
43
+ end
44
+
45
+ def os_id_like_list
46
+ facts.fetch('ID_LIKE', '').split
47
+ end
48
+
49
+ def el?
50
+ File.exist?('/etc/redhat-release')
51
+ end
52
+
53
+ def debian?
54
+ File.exist?('/etc/debian_version')
55
+ end
56
+
57
+ def el7?
58
+ el_major_version == 7
59
+ end
60
+
61
+ def el8?
62
+ el_major_version == 8
63
+ end
64
+
65
+ def el_major_version
66
+ return os_version_id.to_i if el?
67
+ end
68
+ end
69
+ end
70
+ end
@@ -8,6 +8,7 @@ module ForemanMaintain
8
8
  module SystemHelpers
9
9
  include Logger
10
10
  include Concerns::Finders
11
+ include ForemanMaintain::Concerns::OsFacts
11
12
 
12
13
  def self.included(klass)
13
14
  klass.extend(self)
@@ -184,51 +185,24 @@ module ForemanMaintain
184
185
  ForemanMaintain.package_manager
185
186
  end
186
187
 
187
- def os_facts
188
- facter = ForemanMaintain::Utils::Facter.path
189
- @os_facts ||= JSON.parse(execute("#{facter} -j os"))
190
- end
191
-
192
- def el?
193
- os_facts['os']['family'] == 'RedHat'
194
- end
195
-
196
- def debian?
197
- os_facts['os']['family'] == 'Debian'
198
- end
199
-
200
- def el7?
201
- os_facts['os']['release']['major'] == '7' && el?
202
- end
203
-
204
- def el8?
205
- os_facts['os']['release']['major'] == '8' && el?
206
- end
207
-
208
- def el_major_version
209
- return os_facts['os']['release']['major'] if el?
210
- end
211
-
212
188
  def ruby_prefix(scl = true)
213
- if el7? && scl
189
+ if debian?
190
+ 'ruby-'
191
+ elsif el7? && scl
214
192
  'tfm-rubygem-'
215
- elsif el7? || el8?
193
+ else
216
194
  'rubygem-'
217
- elsif debian?
218
- 'ruby-'
219
195
  end
220
196
  end
221
197
 
222
198
  def foreman_plugin_name(plugin)
223
- if debian?
224
- plugin.tr!('_', '-')
225
- end
199
+ plugin = plugin.tr('_', '-') if debian?
226
200
  ruby_prefix + plugin
227
201
  end
228
202
 
229
203
  def proxy_plugin_name(plugin)
230
204
  if debian?
231
- plugin.tr!('_', '-')
205
+ plugin = plugin.tr('_', '-')
232
206
  proxy_plugin_prefix = 'smart-proxy-'
233
207
  else
234
208
  proxy_plugin_prefix = 'smart_proxy_'
@@ -237,6 +211,11 @@ module ForemanMaintain
237
211
  ruby_prefix(scl) + proxy_plugin_prefix + plugin
238
212
  end
239
213
 
214
+ def hammer_plugin_name(plugin)
215
+ plugin = plugin.tr('_', '-') if debian?
216
+ [hammer_package, plugin].join(debian? ? '-' : '_')
217
+ end
218
+
240
219
  def hammer_package
241
220
  hammer_prefix = if debian?
242
221
  'hammer-cli'
@@ -267,21 +267,46 @@ module ForemanMaintain
267
267
 
268
268
  def validate_hostname?
269
269
  # make sure that the system hostname is the same as the backup
270
- config_tarball = file_map[:config_files][:path]
271
- tar_cmd = "tar zxf #{config_tarball} etc/httpd/conf/httpd.conf --to-stdout --occurrence=1"
272
- status, httpd_config = execute_with_status(tar_cmd)
273
-
274
- # Incremental backups sometimes don't include httpd.conf. Since a "base" backup
275
- # is restored before an incremental, we can assume that the hostname is checked
276
- # during the base backup restore
277
- if status == 0
278
- match = httpd_config.match(/\s*ServerName\s+"*([^ "]+)"*\s*$/)
279
- match ? match[1] == hostname : false
270
+ hostname_from_metadata = metadata.fetch('hostname', nil)
271
+ if hostname_from_metadata
272
+ hostname_from_metadata == hostname
280
273
  else
281
- true
274
+ config_tarball = file_map[:config_files][:path]
275
+ tar_cmd = "tar zxf #{config_tarball} etc/httpd/conf/httpd.conf --to-stdout --occurrence=1"
276
+ status, httpd_config = execute_with_status(tar_cmd)
277
+
278
+ # Incremental backups sometimes don't include httpd.conf. Since a "base" backup
279
+ # is restored before an incremental, we can assume that the hostname is checked
280
+ # during the base backup restore
281
+ if status == 0
282
+ match = httpd_config.match(/\s*ServerName\s+"*([^ "]+)"*\s*$/)
283
+ match ? match[1] == hostname : false
284
+ else
285
+ true
286
+ end
282
287
  end
283
288
  end
284
289
 
290
+ def validate_interfaces
291
+ # I wanted to do `Socket.getifaddrs.map(&:name).uniq`,
292
+ # but this has to work with Ruby 2.0, and Socket.getifaddrs is 2.1+
293
+ errors = {}
294
+ system_interfaces = Dir.entries('/sys/class/net') - ['.', '..']
295
+
296
+ proxy_config = metadata.fetch('proxy_config', {})
297
+
298
+ %w[dns dhcp].each do |feature|
299
+ next unless proxy_config.fetch(feature, false)
300
+
301
+ wanted_interface = proxy_config.fetch("#{feature}_interface", 'lo')
302
+ unless system_interfaces.include?(wanted_interface)
303
+ errors[feature] = { 'configured' => wanted_interface, 'available' => system_interfaces }
304
+ end
305
+ end
306
+
307
+ return errors
308
+ end
309
+
285
310
  def metadata
286
311
  if file_map[:metadata][:present]
287
312
  YAML.load_file(file_map[:metadata][:path])
@@ -66,7 +66,8 @@ module ForemanMaintain
66
66
  log_file = Tempfile.open('captured-output')
67
67
  exit_file = Tempfile.open('captured-exit-code')
68
68
  Kernel.system(
69
- "bash -c '#{full_command}; echo $? > #{exit_file.path}' | tee -i #{log_file.path}"
69
+ "stdbuf -oL -eL bash -c '#{full_command}; echo $? > #{exit_file.path}'"\
70
+ "| tee -i #{log_file.path}"
70
71
  )
71
72
  File.open(log_file.path) { |f| @output = f.read }
72
73
  File.open(exit_file.path) do |f|
@@ -7,4 +7,3 @@ require 'foreman_maintain/utils/curl_response'
7
7
  require 'foreman_maintain/utils/mongo_core'
8
8
  require 'foreman_maintain/utils/service'
9
9
  require 'foreman_maintain/utils/system_helpers'
10
- require 'foreman_maintain/utils/facter'
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '0.8.20'.freeze
2
+ VERSION = '0.9.3'.freeze
3
3
  end
@@ -15,6 +15,7 @@ module ForemanMaintain
15
15
  require 'foreman_maintain/concerns/finders'
16
16
  require 'foreman_maintain/concerns/metadata'
17
17
  require 'foreman_maintain/concerns/scenario_metadata'
18
+ require 'foreman_maintain/concerns/os_facts'
18
19
  require 'foreman_maintain/concerns/system_helpers'
19
20
  require 'foreman_maintain/concerns/system_service'
20
21
  require 'foreman_maintain/concerns/hammer'
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.8.20
4
+ version: 0.9.3
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-10-19 00:00:00.000000000 Z
11
+ date: 2021-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -84,16 +84,30 @@ dependencies:
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "<"
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
88
102
  - !ruby/object:Gem::Version
89
- version: 11.0.0
103
+ version: 0.50.0
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - "<"
108
+ - - '='
95
109
  - !ruby/object:Gem::Version
96
- version: 11.0.0
110
+ version: 0.50.0
97
111
  description: Provides various features that helps keeping the Foreman/Satellite up
98
112
  and running.
99
113
  email: inecas@redhat.com
@@ -135,6 +149,7 @@ files:
135
149
  - definitions/checks/foreman/check_duplicate_permission.rb
136
150
  - definitions/checks/foreman/check_duplicate_roles.rb
137
151
  - definitions/checks/foreman/check_https_proxies.rb
152
+ - definitions/checks/foreman/check_puppet_capsules.rb
138
153
  - definitions/checks/foreman/db_up.rb
139
154
  - definitions/checks/foreman/facts_names.rb
140
155
  - definitions/checks/foreman/puppet_class_duplicates.rb
@@ -163,6 +178,7 @@ files:
163
178
  - definitions/checks/repositories/validate.rb
164
179
  - definitions/checks/restore/validate_backup.rb
165
180
  - definitions/checks/restore/validate_hostname.rb
181
+ - definitions/checks/restore/validate_interfaces.rb
166
182
  - definitions/checks/root_user.rb
167
183
  - definitions/checks/server_ping.rb
168
184
  - definitions/checks/services_up.rb
@@ -271,9 +287,13 @@ files:
271
287
  - definitions/procedures/pulp/remove.rb
272
288
  - definitions/procedures/pulpcore/migrate.rb
273
289
  - definitions/procedures/puppet/delete_empty_ca_cert_request_files.rb
290
+ - definitions/procedures/puppet/remove_puppet.rb
291
+ - definitions/procedures/puppet/remove_puppet_data.rb
274
292
  - definitions/procedures/refresh_features.rb
275
293
  - definitions/procedures/remote_execution/remove_existing_settingsd.rb
294
+ - definitions/procedures/repositories/backup_enabled_repos.rb
276
295
  - definitions/procedures/repositories/disable.rb
296
+ - definitions/procedures/repositories/enable.rb
277
297
  - definitions/procedures/repositories/setup.rb
278
298
  - definitions/procedures/restore/candlepin_dump.rb
279
299
  - definitions/procedures/restore/configs.rb
@@ -305,7 +325,9 @@ files:
305
325
  - definitions/scenarios/maintenance_mode.rb
306
326
  - definitions/scenarios/packages.rb
307
327
  - definitions/scenarios/prep_6_10_upgrade.rb
328
+ - definitions/scenarios/puppet.rb
308
329
  - definitions/scenarios/restore.rb
330
+ - definitions/scenarios/self_upgrade.rb
309
331
  - definitions/scenarios/services.rb
310
332
  - definitions/scenarios/upgrade_to_capsule_6_10.rb
311
333
  - definitions/scenarios/upgrade_to_capsule_6_10_z.rb
@@ -352,7 +374,9 @@ files:
352
374
  - lib/foreman_maintain/cli/health_command.rb
353
375
  - lib/foreman_maintain/cli/maintenance_mode_command.rb
354
376
  - lib/foreman_maintain/cli/packages_command.rb
377
+ - lib/foreman_maintain/cli/plugin_command.rb
355
378
  - lib/foreman_maintain/cli/restore_command.rb
379
+ - lib/foreman_maintain/cli/self_upgrade_command.rb
356
380
  - lib/foreman_maintain/cli/service_command.rb
357
381
  - lib/foreman_maintain/cli/transform_clamp_options.rb
358
382
  - lib/foreman_maintain/cli/upgrade_command.rb
@@ -363,6 +387,7 @@ files:
363
387
  - lib/foreman_maintain/concerns/hammer.rb
364
388
  - lib/foreman_maintain/concerns/logger.rb
365
389
  - lib/foreman_maintain/concerns/metadata.rb
390
+ - lib/foreman_maintain/concerns/os_facts.rb
366
391
  - lib/foreman_maintain/concerns/primary_checks.rb
367
392
  - lib/foreman_maintain/concerns/pulp_common.rb
368
393
  - lib/foreman_maintain/concerns/reporter.rb
@@ -402,7 +427,6 @@ files:
402
427
  - lib/foreman_maintain/utils/disk/io_device.rb
403
428
  - lib/foreman_maintain/utils/disk/nil_device.rb
404
429
  - lib/foreman_maintain/utils/disk/stats.rb
405
- - lib/foreman_maintain/utils/facter.rb
406
430
  - lib/foreman_maintain/utils/hash_tools.rb
407
431
  - lib/foreman_maintain/utils/mongo_core.rb
408
432
  - lib/foreman_maintain/utils/response.rb
@@ -1,17 +0,0 @@
1
- module ForemanMaintain::Utils
2
- module Facter
3
- include ForemanMaintain::Concerns::SystemHelpers
4
-
5
- FACTER_FILES = %w[/usr/bin/facter /opt/puppetlabs/bin/facter].freeze
6
-
7
- def self.package
8
- puppet_version = version(execute!('/opt/puppetlabs/bin/puppet --version'))
9
-
10
- puppet_version.major >= 4 ? 'puppet-agent' : 'facter'
11
- end
12
-
13
- def self.path
14
- FACTER_FILES.find { |path| File.exist?(path) }
15
- end
16
- end
17
- end