foreman_maintain 1.1.14 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/definitions/checks/foreman/check_tuning_requirements.rb +79 -0
  3. data/definitions/checks/non_rh_packages.rb +1 -6
  4. data/definitions/checks/repositories/check_upstream_repository.rb +3 -1
  5. data/definitions/features/capsule.rb +1 -0
  6. data/definitions/features/foreman_install.rb +12 -0
  7. data/definitions/features/foreman_proxy.rb +1 -1
  8. data/definitions/features/foreman_server.rb +5 -0
  9. data/definitions/features/foreman_tasks.rb +0 -2
  10. data/definitions/features/installer.rb +12 -3
  11. data/definitions/features/instance.rb +9 -0
  12. data/definitions/features/katello.rb +2 -0
  13. data/definitions/features/katello_install.rb +12 -0
  14. data/definitions/features/satellite.rb +1 -0
  15. data/definitions/features/sync_plans.rb +1 -11
  16. data/definitions/procedures/content/switchover.rb +1 -1
  17. data/definitions/procedures/packages/enable_modules.rb +16 -0
  18. data/definitions/procedures/packages/uninstall.rb +30 -0
  19. data/definitions/procedures/repositories/setup.rb +2 -1
  20. data/definitions/scenarios/restore.rb +0 -5
  21. data/definitions/scenarios/self_upgrade.rb +48 -4
  22. data/definitions/scenarios/upgrade_to_foreman_nightly.rb +89 -0
  23. data/definitions/scenarios/upgrade_to_katello_nightly.rb +87 -0
  24. data/lib/foreman_maintain/cli/upgrade_command.rb +7 -3
  25. data/lib/foreman_maintain/concerns/downstream.rb +0 -12
  26. data/lib/foreman_maintain/concerns/foreman_and_katello_version_map.rb +17 -0
  27. data/lib/foreman_maintain/concerns/os_facts.rb +25 -0
  28. data/lib/foreman_maintain/concerns/upstream.rb +103 -0
  29. data/lib/foreman_maintain/concerns/versions.rb +17 -0
  30. data/lib/foreman_maintain/package_manager/apt.rb +7 -0
  31. data/lib/foreman_maintain/package_manager/dnf.rb +0 -18
  32. data/lib/foreman_maintain/scenario.rb +1 -0
  33. data/lib/foreman_maintain/version.rb +1 -1
  34. data/lib/foreman_maintain.rb +3 -16
  35. metadata +12 -7
  36. data/definitions/features/foreman_1_11_x.rb +0 -9
  37. data/definitions/features/foreman_1_7_x.rb +0 -9
  38. data/definitions/features/upstream.rb +0 -14
  39. data/definitions/features/upstream_repositories.rb +0 -23
  40. data/definitions/procedures/restore/reindex_databases.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b107bb35fc13fe807736e7bee91e6248335f03cd7ee254108d238f7e3f838dd3
4
- data.tar.gz: ef3d49ecbd7753101de6e1729e8a1365c790e0c6cacc154614177140b5866963
3
+ metadata.gz: 5bf9227086619d4fb28185c0fdb796c7045b9f35ea52df8fc3d9aa1a45fbb85d
4
+ data.tar.gz: 77281b4efd0cb3b2d1e6fed2badce28d183dcb7b16d65246987f57407eb92642
5
5
  SHA512:
6
- metadata.gz: 18700fc8376da5b92903d67b8cd85aed9005b7974d45cb0c3943e63a00c9c79684671e2e320e2e96e9d5cd63c11cf17861407abb3ce24399f3a8eea2b1913484
7
- data.tar.gz: d56a5be7d5ebddf6663b25c6dbbf95d526d5d05eeb19b1cd8002b38056c391fc1c60cb5e9e4138db6121da2103806c5332c9ba6330e2e727b50fafb384105ba4
6
+ metadata.gz: 3b2e771c53927fa0f637da5a5066eb1afecbfe7876b9a241a68dfc8300ac82f8835fa308a42742d7b2a126716bac825e37179ddd91695a529de0b64e5272e245
7
+ data.tar.gz: 283f7004e4268f19cadc052dcd044273be28f96e786fd012bca57692276a3765eaded4848a596a66efdfe36d490870f6cfbbee07ccfa4c0dcdcf6362a9fda740
@@ -0,0 +1,79 @@
1
+ module Checks
2
+ module Foreman
3
+ class TuningRequirements < ForemanMaintain::Check
4
+ metadata do
5
+ label :check_tuning_requirements
6
+ tags :pre_upgrade
7
+ description 'Check if system requirements match current tuning profile'
8
+ confine do
9
+ feature(:katello)
10
+ end
11
+ do_not_whitelist
12
+ end
13
+
14
+ def run
15
+ failure_message = check_tuning_profile
16
+ fail! failure_message if failure_message
17
+ end
18
+
19
+ def check_tuning_profile
20
+ installer_config = feature(:installer).configuration
21
+ tuning_profile = installer_config[:facts]['tuning']
22
+
23
+ cpu_message = check_cpu_cores(tuning_profile)
24
+ memory_message = check_memory(tuning_profile)
25
+
26
+ return unless cpu_message || memory_message
27
+
28
+ message = failure_message(tuning_profile)
29
+ if cpu_message
30
+ message += "#{cpu_message}\n"
31
+ end
32
+ if memory_message
33
+ message += "#{memory_message}\n"
34
+ end
35
+
36
+ message
37
+ end
38
+
39
+ def check_memory(tuning_profile)
40
+ # Check if it's actually 90% of the required. If a crash kernel is enabled
41
+ # then the reported total memory is lower than in reality.
42
+ kb_to_gb = (1024 * 1024)
43
+ memory_percentile = 0.9
44
+ tuning_memory = tuning_sizes[tuning_profile][:memory]
45
+ system_memory = memory.to_i
46
+
47
+ unless system_memory.to_i >= (tuning_memory * kb_to_gb * memory_percentile)
48
+ "The system memory is #{system_memory / kb_to_gb} GB but the currently configured tuning profile requires #{tuning_memory} GB." # rubocop:disable Metrics/LineLength
49
+ end
50
+ end
51
+
52
+ def check_cpu_cores(tuning_profile)
53
+ tuning_cpu_cores = tuning_sizes[tuning_profile][:cpu_cores]
54
+ system_cpu_cores = cpu_cores
55
+
56
+ unless system_cpu_cores.to_i >= tuning_cpu_cores
57
+ "The number of CPU cores for the system is #{system_cpu_cores} but the currently configured tuning profile requires #{tuning_cpu_cores}." # rubocop:disable Metrics/LineLength
58
+ end
59
+ end
60
+
61
+ def tuning_sizes
62
+ {
63
+ 'development' => { cpu_cores: 1, memory: 6 },
64
+ 'default' => { cpu_cores: 4, memory: 20 },
65
+ 'medium' => { cpu_cores: 8, memory: 32 },
66
+ 'large' => { cpu_cores: 16, memory: 64 },
67
+ 'extra-large' => { cpu_cores: 32, memory: 128 },
68
+ 'extra-extra-large' => { cpu_cores: 48, memory: 256 }
69
+ }
70
+ end
71
+
72
+ def failure_message(tuning_profile)
73
+ <<-MESSAGE.strip_heredoc
74
+ \nERROR: The installer is configured to use the #{tuning_profile} tuning profile and does not meet the requirements.
75
+ MESSAGE
76
+ end
77
+ end
78
+ end
79
+ end
@@ -11,8 +11,7 @@ class Checks::NonRhPackages < ForemanMaintain::Check
11
11
  def run
12
12
  rpm_query_format = '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH} : %{VENDOR}\n'
13
13
  all_packages = package_manager.list_installed_packages(rpm_query_format)
14
- non_rh_packages = all_packages - \
15
- all_packages.grep(Regexp.union(rh_regexp_list + ansible_runner_regexp_list))
14
+ non_rh_packages = all_packages - all_packages.grep(Regexp.union(rh_regexp_list))
16
15
  assert(non_rh_packages.empty?, error_msg(non_rh_packages), :warn => true)
17
16
  end
18
17
 
@@ -27,8 +26,4 @@ class Checks::NonRhPackages < ForemanMaintain::Check
27
26
  /-qpid-router-server/, /java-client/, /pulp-client/, /katello-default-ca/, /katello-server-ca/,
28
27
  /katello-ca-consumer/, /gpg-pubkey/, /-tomcat/]
29
28
  end
30
-
31
- def ansible_runner_regexp_list
32
- [/ansible-runner/, /[python\d]+-ansible-runner/]
33
- end
34
29
  end
@@ -1,4 +1,6 @@
1
1
  class Checks::CheckUpstreamRepository < ForemanMaintain::Check
2
+ include ForemanMaintain::Concerns::Upstream
3
+
2
4
  metadata do
3
5
  label :check_upstream_repository
4
6
  description 'Check if any upstream repositories are enabled on system'
@@ -14,7 +16,7 @@ class Checks::CheckUpstreamRepository < ForemanMaintain::Check
14
16
 
15
17
  def run
16
18
  with_spinner('Checking for presence of upstream repositories') do
17
- enabled_repo_ids = feature(:upstream_repositories).repoids_and_urls.keys
19
+ enabled_repo_ids = repoids_and_urls.keys
18
20
  assert(enabled_repo_ids.empty?,
19
21
  "System has upstream #{enabled_repo_ids.join(',')} repositories enabled",
20
22
  :next_steps => Procedures::Repositories::Disable.new(:repos => enabled_repo_ids))
@@ -1,5 +1,6 @@
1
1
  class Features::Capsule < ForemanMaintain::Feature
2
2
  include ForemanMaintain::Concerns::Downstream
3
+ include ForemanMaintain::Concerns::Versions
3
4
 
4
5
  metadata do
5
6
  label :capsule
@@ -0,0 +1,12 @@
1
+ class Features::ForemanInstall < ForemanMaintain::Feature
2
+ include ForemanMaintain::Concerns::Upstream
3
+ include ForemanMaintain::Concerns::Versions
4
+
5
+ metadata do
6
+ label :foreman_install
7
+
8
+ confine do
9
+ !feature(:instance).downstream && !feature(:katello) && feature(:foreman_server)
10
+ end
11
+ end
12
+ end
@@ -144,7 +144,7 @@ class Features::ForemanProxy < ForemanMaintain::Feature
144
144
 
145
145
  cmd = "curl -w '\n%{http_code}' -s "
146
146
  cmd += format_shell_args('--cert' => ssl_cert, '--key' => ssl_key, '--cacert' => ssl_ca)
147
- cmd += " https://#{hostname}:#{proxy_settings[:https_port]}"
147
+ cmd += " https://$(hostname):#{proxy_settings[:https_port]}"
148
148
  cmd
149
149
  end
150
150
 
@@ -1,6 +1,7 @@
1
1
  module ForemanMaintain
2
2
  module Features
3
3
  class ForemanServer < ForemanMaintain::Feature
4
+ include ForemanMaintain::Concerns::Versions
4
5
  metadata do
5
6
  label :foreman_server
6
7
  confine do
@@ -47,6 +48,10 @@ module ForemanMaintain
47
48
  def services_running?
48
49
  services.all?(&:running?)
49
50
  end
51
+
52
+ def current_version
53
+ @current_version ||= package_version('foreman')
54
+ end
50
55
  end
51
56
  end
52
57
  end
@@ -17,7 +17,6 @@ class Features::ForemanTasks < ForemanMaintain::Feature
17
17
  Actions::Candlepin::ListenOnCandlepinEvents
18
18
  Actions::Katello::EventQueue::Monitor
19
19
  Actions::Insights::EmailPoller
20
- ForemanInventoryUpload::Async::GenerateAllReportsJob
21
20
  ForemanInventoryUpload::Async::GenerateReportJob
22
21
  ForemanInventoryUpload::Async::QueueForUploadJob
23
22
  ForemanInventoryUpload::Async::UploadReportJob
@@ -25,7 +24,6 @@ class Features::ForemanTasks < ForemanMaintain::Feature
25
24
  InsightsCloud::Async::InsightsFullSync
26
25
  InsightsCloud::Async::InsightsResolutionsSync
27
26
  InsightsCloud::Async::InsightsRulesSync
28
- InsightsCloud::Async::InsightsScheduledSync
29
27
  InventorySync::Async::InventoryFullSync
30
28
  InventorySync::Async::InventoryHostsSync
31
29
  InventorySync::Async::InventoryScheduledSync
@@ -92,11 +92,18 @@ class Features::Installer < ForemanMaintain::Feature
92
92
  end
93
93
 
94
94
  def run(arguments = '', exec_options = {})
95
- out = execute!("LANG=en_US.utf-8 #{installer_command} #{arguments}".strip, exec_options)
95
+ out = execute!("#{installer_command} #{arguments}".strip, exec_options)
96
96
  @configuration = nil
97
97
  out
98
98
  end
99
99
 
100
+ def run_with_status(arguments = '', exec_options = {})
101
+ cmd_with_arguments = "#{installer_command} #{arguments}".strip
102
+ cmd_status, out = execute_with_status(cmd_with_arguments, exec_options)
103
+ @configuration = nil
104
+ [cmd_status, out]
105
+ end
106
+
100
107
  def upgrade(exec_options = {})
101
108
  run(installer_arguments, exec_options)
102
109
  end
@@ -105,13 +112,15 @@ class Features::Installer < ForemanMaintain::Feature
105
112
  installer_args = ''
106
113
 
107
114
  if feature(:foreman_proxy) &&
108
- feature(:foreman_proxy).with_content?
115
+ feature(:foreman_proxy).with_content? &&
116
+ check_max_version('foreman-installer', '3.4')
109
117
  installer_args += ' --disable-system-checks'
110
118
  end
111
119
 
112
- unless check_min_version('foreman', '2.1') || check_min_version('foreman-proxy', '2.1')
120
+ unless check_min_version('foreman-installer', '2.1')
113
121
  installer_args += ' --upgrade' if can_upgrade?
114
122
  end
123
+
115
124
  installer_args
116
125
  end
117
126
 
@@ -60,8 +60,13 @@ class Features::Instance < ForemanMaintain::Feature
60
60
  end
61
61
  end
62
62
 
63
+ def foreman_server_ssl_ca
64
+ @foreman_server_ssl_ca ||= feature(:installer).answers['foreman']['server_ssl_ca']
65
+ end
66
+
63
67
  def server_connection
64
68
  net = Net::HTTP.new(ForemanMaintain.config.foreman_url, ForemanMaintain.config.foreman_port)
69
+ net.ca_file = foreman_server_ssl_ca
65
70
  net.use_ssl = true
66
71
  net
67
72
  end
@@ -74,6 +79,10 @@ class Features::Instance < ForemanMaintain::Feature
74
79
  feature(:nftables) || feature(:iptables)
75
80
  end
76
81
 
82
+ def upstream_install
83
+ feature(:foreman_install) || feature(:katello_install)
84
+ end
85
+
77
86
  private
78
87
 
79
88
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
@@ -1,4 +1,6 @@
1
1
  class Features::Katello < ForemanMaintain::Feature
2
+ include ForemanMaintain::Concerns::Versions
3
+
2
4
  metadata do
3
5
  label :katello
4
6
 
@@ -0,0 +1,12 @@
1
+ class Features::KatelloInstall < ForemanMaintain::Feature
2
+ include ForemanMaintain::Concerns::Upstream
3
+ include ForemanMaintain::Concerns::Versions
4
+
5
+ metadata do
6
+ label :katello_install
7
+
8
+ confine do
9
+ !feature(:instance).downstream && feature(:katello)
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,6 @@
1
1
  class Features::Satellite < ForemanMaintain::Feature
2
2
  include ForemanMaintain::Concerns::Downstream
3
+ include ForemanMaintain::Concerns::Versions
3
4
 
4
5
  metadata do
5
6
  label :satellite
@@ -33,22 +33,12 @@ class Features::SyncPlans < ForemanMaintain::Feature
33
33
  feature(:foreman_database).query(query).map { |r| r['id'].to_i }
34
34
  end
35
35
 
36
- def validate_sync_plan_ids(ids)
37
- return [] if ids.empty?
38
-
39
- ids_condition = ids.map { |id| "'#{id}'" }.join(',')
40
- query = "SELECT id FROM katello_sync_plans WHERE id IN (#{ids_condition})"
41
- feature(:foreman_database).query(query).map { |r| r['id'].to_i }
42
- end
43
-
44
36
  def make_disable(ids)
45
37
  update_records(ids, false)
46
38
  end
47
39
 
48
40
  def make_enable
49
- # remove ids of sync plans which no longer exist in DB
50
- @data[:disabled] = validate_sync_plan_ids(@data[:disabled])
51
- update_records(@data[:disabled], true)
41
+ update_records(data[:disabled], true)
52
42
  end
53
43
 
54
44
  def load_from_storage(storage)
@@ -19,7 +19,7 @@ module Procedures::Content
19
19
  puts execute!('foreman-rake katello:pulp3_post_migration_check')
20
20
  puts 'Switching specified content over to pulp 3'
21
21
  puts execute!('foreman-rake katello:pulp3_content_switchover')
22
- run_installer if feature(:upstream)
22
+ run_installer if feature(:katello_install)
23
23
  end
24
24
 
25
25
  def run_installer
@@ -0,0 +1,16 @@
1
+ module Procedures::Packages
2
+ class EnableModules < ForemanMaintain::Procedure
3
+ metadata do
4
+ description 'Enable the given stream modules'
5
+ confine do
6
+ package_manager.class.name == 'ForemanMaintain::PackageManager::Dnf'
7
+ end
8
+ param :module_names, 'Module names', :array => true, :required => true
9
+ advanced_run false
10
+ end
11
+
12
+ def run
13
+ execute!("dnf module enable #{@module_names.join(' ')} -y")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,30 @@
1
+ module Procedures::Packages
2
+ class Uninstall < ForemanMaintain::Procedure
3
+ metadata do
4
+ description 'Uninstall packages'
5
+ param :packages, 'List of packages to uninstall', :array => true
6
+ param :assumeyes, 'Do not ask for confirmation'
7
+ param :warn_on_errors, 'Do not interrupt scenario on failure',
8
+ :flag => true, :default => false
9
+ end
10
+
11
+ def run
12
+ assumeyes_val = @assumeyes.nil? ? assumeyes? : @assumeyes
13
+ packages_action(:remove, @packages, :assumeyes => assumeyes_val)
14
+ rescue ForemanMaintain::Error::ExecutionError => e
15
+ if @warn_on_errors
16
+ set_status(:warning, e.message)
17
+ else
18
+ raise
19
+ end
20
+ end
21
+
22
+ def necessary?
23
+ @force || @packages.any? { |package| package_version(package).nil? }
24
+ end
25
+
26
+ def runtime_message
27
+ "Uninstalling package(s) #{@packages.join(', ')}"
28
+ end
29
+ end
30
+ end
@@ -13,7 +13,8 @@ module Procedures::Repositories
13
13
 
14
14
  def run
15
15
  with_spinner("Configuring repositories for #{@version}") do
16
- (feature(:instance).downstream || feature(:upstream)).setup_repositories(@version)
16
+ (feature(:instance).downstream || \
17
+ feature(:instance).upstream_install).setup_repositories(@version)
17
18
  end
18
19
  end
19
20
  end
@@ -45,11 +45,6 @@ module ForemanMaintain::Scenarios
45
45
  add_step(Procedures::Service::Stop.new(:only => ['postgresql']))
46
46
  end
47
47
  restore_mongo_dump(backup)
48
-
49
- if feature(:instance).postgresql_local? && !backup.online_backup?
50
- add_step_with_context(Procedures::Restore::ReindexDatabases)
51
- end
52
-
53
48
  add_steps_with_context(Procedures::Pulp::Migrate,
54
49
  Procedures::Pulpcore::Migrate,
55
50
  Procedures::Restore::CandlepinResetMigrations)
@@ -1,6 +1,8 @@
1
1
  module ForemanMaintain::Scenarios
2
2
  class SelfUpgradeBase < ForemanMaintain::Scenario
3
3
  include ForemanMaintain::Concerns::Downstream
4
+ include ForemanMaintain::Concerns::Versions
5
+
4
6
  def target_version
5
7
  @target_version ||= Gem::Version.new(current_version).bump.to_s
6
8
  end
@@ -48,6 +50,14 @@ module ForemanMaintain::Scenarios
48
50
  [maintenance_repo_id(target_version)]
49
51
  end
50
52
  end
53
+
54
+ def upstream_target_version
55
+ if feature(:katello_install)
56
+ return foreman_version_by_katello(target_version)
57
+ else
58
+ target_version
59
+ end
60
+ end
51
61
  end
52
62
 
53
63
  class SelfUpgrade < SelfUpgradeBase
@@ -58,11 +68,8 @@ module ForemanMaintain::Scenarios
58
68
  manual_detection
59
69
  end
60
70
 
61
- def compose
62
- ForemanMaintain.enable_maintenance_module
63
-
71
+ def downstream_self_upgrade(pkgs_to_update)
64
72
  if check_min_version('foreman', '2.5') || check_min_version('foreman-proxy', '2.5')
65
- pkgs_to_update = %w[satellite-maintain rubygem-foreman_maintain]
66
73
  yum_options = req_repos_to_update_pkgs.map do |id|
67
74
  "--enablerepo=#{id}"
68
75
  end
@@ -70,5 +77,42 @@ module ForemanMaintain::Scenarios
70
77
  yum_options: yum_options))
71
78
  end
72
79
  end
80
+
81
+ def upstream_self_upgrade(pkgs_to_update)
82
+ # This method is responsible for
83
+ # 1. Setup the repositories of next major version
84
+ # 2. Update the foreman-maintain packages from next major version repository
85
+ # 3. Rollback the repository to current major version
86
+
87
+ add_step(Procedures::Repositories::Setup.new(:version => upstream_target_version))
88
+ add_step(Procedures::Packages::Update.new(packages: pkgs_to_update, assumeyes: true))
89
+ ensure
90
+ rollback_repositories
91
+ end
92
+
93
+ def rollback_repositories
94
+ installed_release_pkg = package_manager.find_installed_package('foreman-release',
95
+ '%{VERSION}')
96
+
97
+ unless current_version.nil? && installed_release_pkg.nil?
98
+ current_major_version = current_version[0..2]
99
+ installed_foreman_release_major_version = installed_release_pkg[0..2]
100
+ if installed_foreman_release_major_version != current_major_version
101
+ add_step(Procedures::Packages::Uninstall.new(packages: %w[foreman-release katello-repos],
102
+ assumeyes: true))
103
+ add_step(Procedures::Repositories::Setup.new(:version => current_major_version))
104
+ end
105
+ end
106
+ end
107
+
108
+ def compose
109
+ pkgs_to_update = %w[rubygem-foreman_maintain]
110
+ if feature(:instance).downstream
111
+ pkgs_to_update << 'satellite-maintain'
112
+ downstream_self_upgrade(pkgs_to_update)
113
+ elsif feature(:instance).upstream_install
114
+ upstream_self_upgrade(pkgs_to_update)
115
+ end
116
+ end
73
117
  end
74
118
  end
@@ -0,0 +1,89 @@
1
+ module Scenarios::Foreman_Nightly
2
+ class Abstract < ForemanMaintain::Scenario
3
+ def self.upgrade_metadata(&block)
4
+ metadata do
5
+ tags :upgrade_scenario
6
+ confine do
7
+ feature(:foreman_install) || ForemanMaintain.upgrade_in_progress == 'nightly'
8
+ end
9
+ instance_eval(&block)
10
+ end
11
+ end
12
+
13
+ def target_version
14
+ 'nightly'
15
+ end
16
+ end
17
+
18
+ class PreUpgradeCheck < Abstract
19
+ upgrade_metadata do
20
+ description 'Checks before upgrading to Foreman nightly'
21
+ tags :pre_upgrade_checks
22
+ run_strategy :fail_slow
23
+ end
24
+
25
+ def compose
26
+ add_steps(find_checks(:default))
27
+ add_steps(find_checks(:pre_upgrade))
28
+ end
29
+ end
30
+
31
+ class PreMigrations < Abstract
32
+ upgrade_metadata do
33
+ description 'Procedures before upgrading to Foreman nightly'
34
+ tags :pre_migrations
35
+ end
36
+
37
+ def compose
38
+ add_steps(find_procedures(:pre_migrations))
39
+ end
40
+ end
41
+
42
+ class Migrations < Abstract
43
+ upgrade_metadata do
44
+ description 'Upgrade steps for Foreman nightly'
45
+ tags :migrations
46
+ run_strategy :fail_fast
47
+ end
48
+
49
+ def set_context_mapping
50
+ context.map(:assumeyes, Procedures::Installer::Upgrade => :assumeyes)
51
+ end
52
+
53
+ def compose
54
+ add_step(Procedures::Repositories::Setup.new(:version => 'nightly'))
55
+ if el?
56
+ modules_to_enable = ["foreman:#{el_short_name}"]
57
+ add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable))
58
+ end
59
+ add_step(Procedures::Packages::Update.new(:assumeyes => true))
60
+ add_step_with_context(Procedures::Installer::Upgrade)
61
+ end
62
+ end
63
+
64
+ class PostMigrations < Abstract
65
+ upgrade_metadata do
66
+ description 'Post upgrade procedures for Foreman nightly'
67
+ tags :post_migrations
68
+ end
69
+
70
+ def compose
71
+ add_step(Procedures::RefreshFeatures)
72
+ add_step(Procedures::Service::Start.new)
73
+ add_steps(find_procedures(:post_migrations))
74
+ end
75
+ end
76
+
77
+ class PostUpgradeChecks < Abstract
78
+ upgrade_metadata do
79
+ description 'Checks after upgrading to Foreman nightly'
80
+ tags :post_upgrade_checks
81
+ run_strategy :fail_slow
82
+ end
83
+
84
+ def compose
85
+ add_steps(find_checks(:default))
86
+ add_steps(find_checks(:post_upgrade))
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,87 @@
1
+ module Scenarios::Katello_Nightly
2
+ class Abstract < ForemanMaintain::Scenario
3
+ def self.upgrade_metadata(&block)
4
+ metadata do
5
+ tags :upgrade_scenario
6
+ confine do
7
+ feature(:katello_install) || ForemanMaintain.upgrade_in_progress == 'nightly'
8
+ end
9
+ instance_eval(&block)
10
+ end
11
+ end
12
+
13
+ def target_version
14
+ 'nightly'
15
+ end
16
+ end
17
+
18
+ class PreUpgradeCheck < Abstract
19
+ upgrade_metadata do
20
+ description 'Checks before upgrading to Katello nightly'
21
+ tags :pre_upgrade_checks
22
+ run_strategy :fail_slow
23
+ end
24
+
25
+ def compose
26
+ add_steps(find_checks(:default))
27
+ add_steps(find_checks(:pre_upgrade))
28
+ end
29
+ end
30
+
31
+ class PreMigrations < Abstract
32
+ upgrade_metadata do
33
+ description 'Procedures before upgrading to Katello nightly'
34
+ tags :pre_migrations
35
+ end
36
+
37
+ def compose
38
+ add_steps(find_procedures(:pre_migrations))
39
+ end
40
+ end
41
+
42
+ class Migrations < Abstract
43
+ upgrade_metadata do
44
+ description 'Upgrade steps for Katello nightly'
45
+ tags :migrations
46
+ run_strategy :fail_fast
47
+ end
48
+
49
+ def set_context_mapping
50
+ context.map(:assumeyes, Procedures::Installer::Upgrade => :assumeyes)
51
+ end
52
+
53
+ def compose
54
+ add_step(Procedures::Repositories::Setup.new(:version => 'nightly'))
55
+ modules_to_enable = ["katello:#{el_short_name}", "pulpcore:#{el_short_name}"]
56
+ add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable))
57
+ add_step(Procedures::Packages::Update.new(:assumeyes => true))
58
+ add_step_with_context(Procedures::Installer::Upgrade)
59
+ end
60
+ end
61
+
62
+ class PostMigrations < Abstract
63
+ upgrade_metadata do
64
+ description 'Post upgrade procedures for Katello nightly'
65
+ tags :post_migrations
66
+ end
67
+
68
+ def compose
69
+ add_step(Procedures::RefreshFeatures)
70
+ add_step(Procedures::Service::Start.new)
71
+ add_steps(find_procedures(:post_migrations))
72
+ end
73
+ end
74
+
75
+ class PostUpgradeChecks < Abstract
76
+ upgrade_metadata do
77
+ description 'Checks after upgrading to Katello nightly'
78
+ tags :post_upgrade_checks
79
+ run_strategy :fail_slow
80
+ end
81
+
82
+ def compose
83
+ add_steps(find_checks(:default))
84
+ add_steps(find_checks(:post_upgrade))
85
+ end
86
+ end
87
+ end
@@ -52,12 +52,16 @@ module ForemanMaintain
52
52
  target_versions.sort.each { |version| puts version }
53
53
  end
54
54
 
55
+ def allow_self_upgrade?
56
+ !disable_self_upgrade?
57
+ end
58
+
55
59
  subcommand 'list-versions', 'List versions this system is upgradable to' do
56
60
  disable_self_upgrade_option
57
61
 
58
62
  def execute
59
63
  ForemanMaintain.validate_downstream_packages
60
- ForemanMaintain.perform_self_upgrade unless disable_self_upgrade?
64
+ ForemanMaintain.perform_self_upgrade if allow_self_upgrade?
61
65
  print_versions(UpgradeRunner.available_targets)
62
66
  end
63
67
  end
@@ -69,7 +73,7 @@ module ForemanMaintain
69
73
 
70
74
  def execute
71
75
  ForemanMaintain.validate_downstream_packages
72
- ForemanMaintain.perform_self_upgrade unless disable_self_upgrade?
76
+ ForemanMaintain.perform_self_upgrade if allow_self_upgrade?
73
77
  upgrade_runner.run_phase(:pre_upgrade_checks)
74
78
  exit upgrade_runner.exit_code
75
79
  end
@@ -89,7 +93,7 @@ module ForemanMaintain
89
93
 
90
94
  def execute
91
95
  ForemanMaintain.validate_downstream_packages
92
- ForemanMaintain.perform_self_upgrade unless disable_self_upgrade?
96
+ ForemanMaintain.perform_self_upgrade if allow_self_upgrade?
93
97
  if phase
94
98
  upgrade_runner.run_phase(phase.to_sym)
95
99
  else
@@ -5,18 +5,6 @@ module ForemanMaintain
5
5
  raise NotImplementedError
6
6
  end
7
7
 
8
- def less_than_version?(version)
9
- Gem::Version.new(current_version) < Gem::Version.new(version)
10
- end
11
-
12
- def at_least_version?(version)
13
- Gem::Version.new(current_version) >= Gem::Version.new(version)
14
- end
15
-
16
- def current_minor_version
17
- current_version.to_s[/^\d+\.\d+/]
18
- end
19
-
20
8
  def repository_manager
21
9
  ForemanMaintain.repository_manager
22
10
  end
@@ -0,0 +1,17 @@
1
+ module ForemanMaintain
2
+ module Concerns
3
+ module ForemanAndKatelloVersionMap
4
+ FOREMAN_AND_KATELLO_VERSION_MAP = {
5
+ 'nightly' => 'nightly'
6
+ }.freeze
7
+
8
+ def foreman_version_by_katello(version)
9
+ FOREMAN_AND_KATELLO_VERSION_MAP.key(version)
10
+ end
11
+
12
+ def katello_version_by_foreman(version)
13
+ FOREMAN_AND_KATELLO_VERSION_MAP.fetch(version)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -89,6 +89,31 @@ module ForemanMaintain
89
89
  def os_version
90
90
  facts.fetch('VERSION')
91
91
  end
92
+
93
+ def os_version_codename
94
+ facts.fetch('VERSION_CODENAME')
95
+ end
96
+
97
+ def rhel?
98
+ os_id == 'rhel'
99
+ end
100
+
101
+ def centos?
102
+ os_id == 'centos'
103
+ end
104
+
105
+ def el_short_name
106
+ "el#{el_major_version}"
107
+ end
108
+
109
+ def memory
110
+ meminfo = File.read('/proc/meminfo')
111
+ meminfo.match(/^MemTotal:\s+(?<memory>\d+) kB/)['memory']
112
+ end
113
+
114
+ def cpu_cores
115
+ execute('nproc')
116
+ end
92
117
  end
93
118
  end
94
119
  end
@@ -0,0 +1,103 @@
1
+ module ForemanMaintain
2
+ module Concerns
3
+ module Upstream
4
+ include Concerns::ForemanAndKatelloVersionMap
5
+
6
+ def server_url
7
+ if el?
8
+ 'https://yum.theforeman.org/'
9
+ elsif debian_or_ubuntu?
10
+ 'https://deb.theforeman.org/'
11
+ else
12
+ raise 'Unknown operating system detected!'
13
+ end
14
+ end
15
+
16
+ def foreman_release_pkg_url(version)
17
+ if el?
18
+ "#{server_url}releases/#{version}/#{el_short_name}/x86_64/foreman-release.rpm"
19
+ elsif debian_or_ubuntu?
20
+ "#{server_url}pool/#{os_version_codename}/#{version}"\
21
+ '/f/foreman-release/foreman-release.deb'
22
+ else
23
+ raise 'Unknown operating system detected!'
24
+ end
25
+ end
26
+
27
+ def katello_pkgs_url(katello_version)
28
+ "#{server_url}katello/#{katello_version}/katello/#{el_short_name}/x86_64/"
29
+ end
30
+
31
+ def katello_release_pkg(version)
32
+ "#{katello_pkgs_url(katello_version_by_foreman(version))}katello-repos-latest.rpm"
33
+ end
34
+
35
+ def update_release_pkg_el(pkg_url)
36
+ package_manager.install(pkg_url, assumeyes: true)
37
+ end
38
+
39
+ def update_release_pkg_deb(pkg_url)
40
+ Dir.mktmpdir do |dir|
41
+ release_file_path = "#{dir}/foreman-release.deb"
42
+ exit_status, = execute_with_status("wget -q -O #{release_file_path} #{pkg_url}")
43
+ if exit_status == 0
44
+ package_manager.install(release_file_path, assumeyes: true)
45
+ else
46
+ warn! "Couldn't install Foreman release package: #{pkg_url}"
47
+ end
48
+ end
49
+ end
50
+
51
+ def use_activation_key(activation_key, org)
52
+ org_options = org ? %(--org #{shellescape(org)}) : ''
53
+ execute!(%(subscription-manager register #{org_options}\
54
+ --activationkey #{shellescape(activation_key)} --force))
55
+ end
56
+
57
+ def update_foreman_release_pkg(version)
58
+ pkg_url = foreman_release_pkg_url(version)
59
+ if el?
60
+ update_release_pkg_el(pkg_url)
61
+ elsif debian_or_ubuntu?
62
+ update_release_pkg_deb(pkg_url)
63
+ end
64
+ end
65
+
66
+ def update_katello_release_pkg(version)
67
+ if feature(:katello)
68
+ pkg_url = katello_release_pkg(version)
69
+ update_release_pkg_el(pkg_url)
70
+ end
71
+ end
72
+
73
+ def setup_repositories(version)
74
+ # Documentation needs update with respect to new env vars
75
+ activation_key = ENV['ACTIVATION_KEY']
76
+ org = ENV['FOREMAN_ORG']
77
+ if activation_key
78
+ use_activation_key(activation_key, org)
79
+ else
80
+ update_foreman_release_pkg(version)
81
+ update_katello_release_pkg(version)
82
+ end
83
+ end
84
+
85
+ def repoids_and_urls
86
+ repoids_and_urls = {}
87
+ repository_manager.enabled_repos.each do |repo, url|
88
+ repo_urls.each do |regex|
89
+ repoids_and_urls[repo] = url if url =~ regex
90
+ end
91
+ end
92
+ repoids_and_urls
93
+ end
94
+
95
+ private
96
+
97
+ def repo_urls
98
+ [%r{yum.theforeman.org\/*},
99
+ %r{yum.puppetlabs.com\/*}]
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,17 @@
1
+ module ForemanMaintain
2
+ module Concerns
3
+ module Versions
4
+ def less_than_version?(version)
5
+ Gem::Version.new(current_version) < Gem::Version.new(version)
6
+ end
7
+
8
+ def at_least_version?(version)
9
+ Gem::Version.new(current_version) >= Gem::Version.new(version)
10
+ end
11
+
12
+ def current_minor_version
13
+ current_version.to_s[/^\d+\.\d+/]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,5 @@
1
+ require 'open3'
2
+
1
3
  module ForemanMaintain::PackageManager
2
4
  class Apt < Base
3
5
  def installed?(packages)
@@ -41,6 +43,11 @@ module ForemanMaintain::PackageManager
41
43
  apt_action('upgrade --dry-run', packages, :with_status => with_status)
42
44
  end
43
45
 
46
+ def update_available?(package)
47
+ output, status = Open3.capture2("apt-get install #{package} --dry-run")
48
+ status.success? && output.include?("Inst #{package}")
49
+ end
50
+
44
51
  def list_installed_packages(queryfm = '${binary:Package}-${VERSION}\n')
45
52
  # The queryfm should only include valid tag(s) as per `dpkg-query` man page.
46
53
  # If any special formatting is required with querytag then it should be provided with tag i.e,
@@ -9,24 +9,6 @@ module ForemanMaintain::PackageManager
9
9
  true
10
10
  end
11
11
 
12
- def module_enabled?(name)
13
- _status, result = info(name)
14
- result.match?(/Stream.+\[e\].+/)
15
- end
16
-
17
- def enable_module(name)
18
- dnf_action('module enable', name, assumeyes: true)
19
- end
20
-
21
- def module_exists?(name)
22
- status, _result = info(name)
23
- status == 0
24
- end
25
-
26
- def info(name)
27
- dnf_action('module info', name, with_status: true, assumeyes: true)
28
- end
29
-
30
12
  private
31
13
 
32
14
  def dnf_action(action, packages, with_status: false, assumeyes: false)
@@ -4,6 +4,7 @@ module ForemanMaintain
4
4
  include Concerns::SystemHelpers
5
5
  include Concerns::ScenarioMetadata
6
6
  include Concerns::Finders
7
+ include Concerns::Versions
7
8
  extend Concerns::Finders
8
9
 
9
10
  attr_reader :steps, :context
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '1.1.14'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
@@ -21,7 +21,10 @@ module ForemanMaintain
21
21
  require 'foreman_maintain/concerns/hammer'
22
22
  require 'foreman_maintain/concerns/base_database'
23
23
  require 'foreman_maintain/concerns/directory_marker'
24
+ require 'foreman_maintain/concerns/versions'
24
25
  require 'foreman_maintain/concerns/downstream'
26
+ require 'foreman_maintain/concerns/foreman_and_katello_version_map'
27
+ require 'foreman_maintain/concerns/upstream'
25
28
  require 'foreman_maintain/concerns/primary_checks'
26
29
  require 'foreman_maintain/concerns/pulp_common'
27
30
  require 'foreman_maintain/concerns/firewall/iptables_maintenance_mode'
@@ -175,9 +178,6 @@ module ForemanMaintain
175
178
  package_name, command = pkg_and_cmd_name
176
179
 
177
180
  puts "Checking for new version of #{package_name}..."
178
-
179
- enable_maintenance_module
180
-
181
181
  if ForemanMaintain.package_manager.update_available?(main_package_name)
182
182
  puts "\nUpdating #{package_name} package."
183
183
  ForemanMaintain.package_manager.update(main_package_name, :assumeyes => true)
@@ -188,19 +188,6 @@ module ForemanMaintain
188
188
  puts "Nothing to update, can't find new version of #{package_name}."
189
189
  end
190
190
 
191
- def enable_maintenance_module
192
- return unless el? && !el7?
193
-
194
- maintenance_module = 'satellite-maintenance:el8'
195
- package_manager = ForemanMaintain.package_manager
196
-
197
- if package_manager.module_exists?(maintenance_module) &&
198
- !package_manager.module_enabled?(maintenance_module)
199
- puts "\nEnabling #{maintenance_module} module"
200
- package_manager.enable_module(maintenance_module)
201
- end
202
- end
203
-
204
191
  def main_package_name
205
192
  'rubygem-foreman_maintain'
206
193
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_maintain
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.14
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-13 00:00:00.000000000 Z
11
+ date: 2022-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -161,6 +161,7 @@ files:
161
161
  - definitions/checks/foreman/check_duplicate_roles.rb
162
162
  - definitions/checks/foreman/check_https_proxies.rb
163
163
  - definitions/checks/foreman/check_puppet_capsules.rb
164
+ - definitions/checks/foreman/check_tuning_requirements.rb
164
165
  - definitions/checks/foreman/db_up.rb
165
166
  - definitions/checks/foreman/facts_names.rb
166
167
  - definitions/checks/foreman/puppet_class_duplicates.rb
@@ -201,10 +202,9 @@ files:
201
202
  - definitions/features/capsule.rb
202
203
  - definitions/features/cron.rb
203
204
  - definitions/features/dynflow_sidekiq.rb
204
- - definitions/features/foreman_1_11_x.rb
205
- - definitions/features/foreman_1_7_x.rb
206
205
  - definitions/features/foreman_cockpit.rb
207
206
  - definitions/features/foreman_database.rb
207
+ - definitions/features/foreman_install.rb
208
208
  - definitions/features/foreman_openscap.rb
209
209
  - definitions/features/foreman_proxy.rb
210
210
  - definitions/features/foreman_server.rb
@@ -215,6 +215,7 @@ files:
215
215
  - definitions/features/instance.rb
216
216
  - definitions/features/iptables.rb
217
217
  - definitions/features/katello.rb
218
+ - definitions/features/katello_install.rb
218
219
  - definitions/features/mongo.rb
219
220
  - definitions/features/nftables.rb
220
221
  - definitions/features/pulp2.rb
@@ -226,8 +227,6 @@ files:
226
227
  - definitions/features/service.rb
227
228
  - definitions/features/sync_plans.rb
228
229
  - definitions/features/tar.rb
229
- - definitions/features/upstream.rb
230
- - definitions/features/upstream_repositories.rb
231
230
  - definitions/procedures/backup/accessibility_confirmation.rb
232
231
  - definitions/procedures/backup/clean.rb
233
232
  - definitions/procedures/backup/compress_data.rb
@@ -285,10 +284,12 @@ files:
285
284
  - definitions/procedures/maintenance_mode/enable_maintenance_mode.rb
286
285
  - definitions/procedures/maintenance_mode/is_enabled.rb
287
286
  - definitions/procedures/packages/check_update.rb
287
+ - definitions/procedures/packages/enable_modules.rb
288
288
  - definitions/procedures/packages/install.rb
289
289
  - definitions/procedures/packages/installer_confirmation.rb
290
290
  - definitions/procedures/packages/lock_versions.rb
291
291
  - definitions/procedures/packages/locking_status.rb
292
+ - definitions/procedures/packages/uninstall.rb
292
293
  - definitions/procedures/packages/unlock_versions.rb
293
294
  - definitions/procedures/packages/update.rb
294
295
  - definitions/procedures/packages/update_all_confirmation.rb
@@ -322,7 +323,6 @@ files:
322
323
  - definitions/procedures/restore/postgres_owner.rb
323
324
  - definitions/procedures/restore/pulpcore_dump.rb
324
325
  - definitions/procedures/restore/regenerate_queues.rb
325
- - definitions/procedures/restore/reindex_databases.rb
326
326
  - definitions/procedures/selinux/set_file_security.rb
327
327
  - definitions/procedures/service/base.rb
328
328
  - definitions/procedures/service/daemon_reload.rb
@@ -354,6 +354,8 @@ files:
354
354
  - definitions/scenarios/upgrade_to_capsule_6_8_z.rb
355
355
  - definitions/scenarios/upgrade_to_capsule_6_9.rb
356
356
  - definitions/scenarios/upgrade_to_capsule_6_9_z.rb
357
+ - definitions/scenarios/upgrade_to_foreman_nightly.rb
358
+ - definitions/scenarios/upgrade_to_katello_nightly.rb
357
359
  - definitions/scenarios/upgrade_to_satellite_6_10.rb
358
360
  - definitions/scenarios/upgrade_to_satellite_6_10_z.rb
359
361
  - definitions/scenarios/upgrade_to_satellite_6_11.rb
@@ -410,6 +412,7 @@ files:
410
412
  - lib/foreman_maintain/concerns/firewall/iptables_maintenance_mode.rb
411
413
  - lib/foreman_maintain/concerns/firewall/maintenance_mode.rb
412
414
  - lib/foreman_maintain/concerns/firewall/nftables_maintenance_mode.rb
415
+ - lib/foreman_maintain/concerns/foreman_and_katello_version_map.rb
413
416
  - lib/foreman_maintain/concerns/hammer.rb
414
417
  - lib/foreman_maintain/concerns/logger.rb
415
418
  - lib/foreman_maintain/concerns/metadata.rb
@@ -420,6 +423,8 @@ files:
420
423
  - lib/foreman_maintain/concerns/scenario_metadata.rb
421
424
  - lib/foreman_maintain/concerns/system_helpers.rb
422
425
  - lib/foreman_maintain/concerns/system_service.rb
426
+ - lib/foreman_maintain/concerns/upstream.rb
427
+ - lib/foreman_maintain/concerns/versions.rb
423
428
  - lib/foreman_maintain/config.rb
424
429
  - lib/foreman_maintain/context.rb
425
430
  - lib/foreman_maintain/core_ext.rb
@@ -1,9 +0,0 @@
1
- require 'features/foreman_1_7_x'
2
-
3
- class Features::Foreman_1_11_x < Features::Foreman_1_7_x
4
- metadata do
5
- confine do
6
- check_min_version('foreman', '1.11')
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- class Features::Foreman_1_7_x < ForemanMaintain::Feature
2
- metadata do
3
- label :foreman
4
-
5
- confine do
6
- check_min_version('foreman', '1.7')
7
- end
8
- end
9
- end
@@ -1,14 +0,0 @@
1
- class Features::Upstream < ForemanMaintain::Feature
2
- metadata do
3
- label :upstream
4
-
5
- confine do
6
- # TODO: remove this upstream feature
7
- !feature(:instance).downstream
8
- end
9
- end
10
-
11
- def setup_repositories(_version)
12
- raise NotImplementedError
13
- end
14
- end
@@ -1,23 +0,0 @@
1
- class Features::UpstreamRepositories < ForemanMaintain::Feature
2
- metadata do
3
- label :upstream_repositories
4
- description 'Feature for operations on upstream repositories'
5
- end
6
-
7
- def repoids_and_urls
8
- repoids_and_urls = {}
9
- repository_manager.enabled_repos.each do |repo, url|
10
- repo_urls.each do |regex|
11
- repoids_and_urls[repo] = url if url =~ regex
12
- end
13
- end
14
- repoids_and_urls
15
- end
16
-
17
- private
18
-
19
- def repo_urls
20
- [%r{yum.theforeman.org\/*},
21
- %r{yum.puppetlabs.com\/*}]
22
- end
23
- end
@@ -1,22 +0,0 @@
1
- module Procedures::Restore
2
- class ReindexDatabases < ForemanMaintain::Procedure
3
- include ForemanMaintain::Concerns::SystemService
4
-
5
- metadata do
6
- description 'REINDEX databases'
7
-
8
- confine do
9
- feature(:instance).postgresql_local?
10
- end
11
- end
12
-
13
- def run
14
- with_spinner('Reindexing the databases') do |spinner|
15
- feature(:service).handle_services(spinner, 'start', :only => ['postgresql'])
16
-
17
- spinner.update('Reindexing the databases')
18
- execute!('runuser - postgres -c "reindexdb -a"')
19
- end
20
- end
21
- end
22
- end