foreman_maintain 0.9.3 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/definitions/checks/check_hotfix_installed.rb +3 -1
  3. data/definitions/checks/foreman_proxy/check_tftp_storage.rb +8 -6
  4. data/definitions/checks/pulpcore/group_ownership_check.rb +18 -0
  5. data/definitions/checks/repositories/check_non_rh_repository.rb +9 -4
  6. data/definitions/checks/repositories/check_upstream_repository.rb +4 -4
  7. data/definitions/features/upstream_repositories.rb +23 -0
  8. data/definitions/procedures/pulp/remove.rb +12 -0
  9. data/definitions/procedures/puppet/remove_puppet.rb +11 -3
  10. data/definitions/procedures/puppet/remove_puppet_data.rb +3 -1
  11. data/definitions/procedures/repositories/backup_enabled_repos.rb +1 -1
  12. data/definitions/procedures/repositories/disable.rb +2 -2
  13. data/definitions/procedures/repositories/enable.rb +2 -2
  14. data/definitions/scenarios/puppet.rb +1 -0
  15. data/definitions/scenarios/self_upgrade.rb +1 -1
  16. data/definitions/scenarios/upgrade_to_capsule_7_0.rb +89 -0
  17. data/definitions/scenarios/upgrade_to_capsule_7_0_z.rb +89 -0
  18. data/definitions/scenarios/upgrade_to_satellite_6_10.rb +1 -8
  19. data/definitions/scenarios/upgrade_to_satellite_7_0.rb +93 -0
  20. data/definitions/scenarios/upgrade_to_satellite_7_0_z.rb +90 -0
  21. data/lib/foreman_maintain/concerns/downstream.rb +57 -29
  22. data/lib/foreman_maintain/concerns/system_helpers.rb +4 -0
  23. data/lib/foreman_maintain/repository_manager/el.rb +85 -0
  24. data/lib/foreman_maintain/repository_manager.rb +13 -0
  25. data/lib/foreman_maintain/version.rb +1 -1
  26. data/lib/foreman_maintain.rb +1 -0
  27. metadata +10 -3
  28. data/definitions/features/system_repos.rb +0 -58
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcef2fd68b963d566c30be2531b1f09bf71da02eb8cd06e2c280f9d4a6222fc0
4
- data.tar.gz: 5a1448015d72fe8e8ae19c73eff430b13387c699689a5dbbdd0b73bbbe49c9f0
3
+ metadata.gz: '092ba2224bd80eeef29cbcc522cf6ef3a438094125e8a4ad87e0c99281fdd251'
4
+ data.tar.gz: 0f71a35dc5325391b51a9648cd633ccf681eae203dfa9b49e6626e2b1bd6b602
5
5
  SHA512:
6
- metadata.gz: 348bedd61056cffd63610b9a91d0e8c2a31e3012ec0e41880e05195ae840a61bd14c7d84ea23715cae771272f555b95f05085e4fb1fefc01a4f1a1f84880648d
7
- data.tar.gz: 76f1871c0edb9671ec0a45fec272afed10ae05bb9ebab4b92ecc3f7960bb1a7625b9267eba032fb6335fac1e8cc32116047e87dab109fb8745ce37e212399768
6
+ metadata.gz: 5589f427186e871ca4b0fbaba47ac450962ef2a91f72c33209b2b9f67d1c354e84c9f407cb47b686ef9867a82cbfdbc6360c1e312ba41021bc16fa08fa5e7e0c
7
+ data.tar.gz: 6f2f77e8fe631dee53dd3e9476868d76063d8f1c4fb4b2533c332ca88ab16af0b587901258fe4ab7558bf9fce942263b5717c7ef2717a7c0ea428de266a36991
@@ -46,9 +46,11 @@ class Checks::CheckHotfixInstalled < ForemanMaintain::Check
46
46
  def installed_packages
47
47
  packages = []
48
48
  repoquery_cmd = execute!('which repoquery')
49
- IO.popen([repoquery_cmd, '-a', '--installed', '--qf', '%{ui_from_repo} %{nvra}']) do |io|
49
+ query_format = '%{ui_from_repo} %{name}-%{evr}.%{arch}'
50
+ IO.popen([repoquery_cmd, '-a', '--installed', '--qf', query_format]) do |io|
50
51
  io.each do |line|
51
52
  repo, pkg = line.chomp.split
53
+ next if repo.nil? || pkg.nil?
52
54
  packages << pkg if /satellite|rhscl/ =~ repo[1..-1].downcase
53
55
  end
54
56
  end
@@ -6,12 +6,12 @@ module Checks::ForemanProxy
6
6
  tags :default
7
7
  confine do
8
8
  feature(:satellite) && feature(:foreman_proxy) &&
9
- feature(:foreman_proxy).features.include?('tftp') && non_zero_token_duration?
9
+ feature(:foreman_proxy).features.include?('tftp')
10
10
  end
11
11
  end
12
12
 
13
13
  def run
14
- if Dir.exist?(tftp_boot_directory)
14
+ if non_zero_token_duration? && Dir.exist?(tftp_boot_directory)
15
15
  files = old_files_from_tftp_boot
16
16
  assert(files.empty?,
17
17
  'There are old initrd and vmlinuz files present in tftp',
@@ -29,7 +29,7 @@ module Checks::ForemanProxy
29
29
  end.compact
30
30
  end
31
31
 
32
- def self.non_zero_token_duration?
32
+ def non_zero_token_duration?
33
33
  lookup_token_duration != 0
34
34
  end
35
35
 
@@ -38,13 +38,15 @@ module Checks::ForemanProxy
38
38
  end
39
39
 
40
40
  def token_duration
41
- @token_duration ||= self.class.lookup_token_duration
41
+ @token_duration ||= lookup_token_duration
42
42
  end
43
43
 
44
- def self.lookup_token_duration
44
+ def lookup_token_duration
45
45
  data = feature(:foreman_database). \
46
46
  query("select s.value, s.default from settings s \
47
- where category = 'Setting::Provisioning' and name = 'token_duration'")
47
+ where category IN ('Setting::Provisioning','Setting') \
48
+ and name = 'token_duration'")
49
+
48
50
  YAML.load(data[0]['value'] || data[0]['default'])
49
51
  end
50
52
  end
@@ -0,0 +1,18 @@
1
+ module Checks
2
+ module Pulpcore
3
+ class GroupOwnershipCheck < ForemanMaintain::Check
4
+ metadata do
5
+ description 'Check the group owner of /var/lib/pulp/content directory'
6
+ label :group_ownership_check_of_pulp_content
7
+ manual_detection
8
+ end
9
+
10
+ def run
11
+ group_id = File.stat('/var/lib/pulp/content/').gid
12
+ if Etc.getgrgid(group_id).name != 'pulp'
13
+ fail! "Please run 'foreman-maintain prep-6.10-upgrade' prior to upgrading."
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -11,13 +11,18 @@ module Checks::Repositories
11
11
 
12
12
  def run
13
13
  with_spinner('Checking repositories enabled on the system') do
14
- assert(!epel_enabled?, 'System is subscribed to non Red Hat repositories')
14
+ assert(epel_not_enabled?, 'System is subscribed to non Red Hat repositories')
15
15
  end
16
16
  end
17
17
 
18
- def epel_enabled?
19
- system_repos = execute("yum repolist enabled -d 6 -e 0| grep -E 'Repo-baseurl|Repo-id'")
20
- system_repos.to_s.match(/\bepel\b/i)
18
+ def epel_not_enabled?
19
+ system_repos = repository_manager.enabled_repos
20
+ system_repos.each do |repoid, repourl|
21
+ unless repoid.match(/\bepel\b/i).nil? || repourl.match(/\bepel\b/i).nil?
22
+ return false
23
+ end
24
+ end
25
+ true
21
26
  end
22
27
  end
23
28
  end
@@ -14,10 +14,10 @@ class Checks::CheckUpstreamRepository < ForemanMaintain::Check
14
14
 
15
15
  def run
16
16
  with_spinner('Checking for presence of upstream repositories') do
17
- enabled_upstream_repos = feature(:system_repos).upstream_repos_ids
18
- assert(enabled_upstream_repos.empty?,
19
- "System has upstream #{enabled_upstream_repos.join(',')} repositories enabled",
20
- :next_steps => Procedures::Repositories::Disable.new(:repos => enabled_upstream_repos))
17
+ enabled_repo_ids = feature(:upstream_repositories).repoids_and_urls.keys
18
+ assert(enabled_repo_ids.empty?,
19
+ "System has upstream #{enabled_repo_ids.join(',')} repositories enabled",
20
+ :next_steps => Procedures::Repositories::Disable.new(:repos => enabled_repo_ids))
21
21
  end
22
22
  end
23
23
  end
@@ -0,0 +1,23 @@
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
@@ -86,6 +86,8 @@ module Procedures::Pulp
86
86
  drop_migrations
87
87
 
88
88
  delete_pulp_data(rm_cmds) if rm_cmds.any?
89
+
90
+ restart_pulpcore_services
89
91
  end
90
92
 
91
93
  def remove_pulp
@@ -168,5 +170,15 @@ module Procedures::Pulp
168
170
  spinner.update('Done deleting pulp2 data directories')
169
171
  end
170
172
  end
173
+
174
+ def restart_pulpcore_services
175
+ with_spinner('Restarting pulpcore services') do |spinner|
176
+ pulp_services = feature(:pulpcore).services
177
+
178
+ feature(:service).handle_services(spinner, 'stop', :only => pulp_services)
179
+ feature(:service).handle_services(spinner, 'start', :only => pulp_services)
180
+ spinner.update('Done restarting pulpcore services')
181
+ end
182
+ end
171
183
  end
172
184
  end
@@ -10,15 +10,23 @@ module Procedures::Puppet
10
10
  end
11
11
 
12
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?
13
+ stop_applicable_services
14
+ if server_with_puppet? && feature(:foreman_server)
15
+ execute!('foreman-rake db:migrate VERSION=0 SCOPE=foreman_puppet')
16
+ end
16
17
  feature(:installer).run(installer_arguments_disabling_puppet.join(' '), :interactive => false)
17
18
  packages_action(:remove, packages_to_remove, :assumeyes => true)
18
19
  end
19
20
 
20
21
  private
21
22
 
23
+ def stop_applicable_services
24
+ services = []
25
+ services = feature(:foreman_server).services if feature(:foreman_server)
26
+ services << feature(:dynflow_sidekiq).services if feature(:dynflow_sidekiq)
27
+ Procedures::Service::Stop.new(:only => services) unless services.empty?
28
+ end
29
+
22
30
  def server_with_puppet?
23
31
  find_package(foreman_plugin_name('foreman_puppet'))
24
32
  end
@@ -5,7 +5,9 @@ module Procedures::Puppet
5
5
  end
6
6
 
7
7
  def run
8
- execute!('foreman-rake purge:puppet')
8
+ if feature(:foreman_server)
9
+ execute!('foreman-rake purge:puppet')
10
+ end
9
11
  execute!('rm -r ' + files_to_purge.join(' '))
10
12
  end
11
13
 
@@ -6,7 +6,7 @@ module Procedures::Repositories
6
6
  end
7
7
 
8
8
  def run
9
- enabled_repos_ids = feature(:system_repos).enabled_repos_ids
9
+ enabled_repos_ids = repository_manager.enabled_repos.keys
10
10
  unless enabled_repos_ids.empty?
11
11
  backup_dir = File.expand_path(ForemanMaintain.config.backup_dir)
12
12
  File.write(File.join(backup_dir, 'enabled_repos.yml'), enabled_repos_ids.to_yaml)
@@ -1,12 +1,12 @@
1
1
  module Procedures::Repositories
2
2
  class Disable < ForemanMaintain::Procedure
3
3
  metadata do
4
- param :repos, 'List of repositories to disable'
4
+ param :repos, 'Array of repositories to disable'
5
5
  description 'Disable repositories'
6
6
  end
7
7
  def run
8
8
  with_spinner('Disabling repositories') do
9
- feature(:system_repos).disable_repos(@repos)
9
+ repository_manager.disable_repos(@repos)
10
10
  end
11
11
  end
12
12
  end
@@ -1,12 +1,12 @@
1
1
  module Procedures::Repositories
2
2
  class Enable < ForemanMaintain::Procedure
3
3
  metadata do
4
- param :repos, 'List of repositories to enable'
4
+ param :repos, 'Array of repositories to enable'
5
5
  description 'Enable repositories'
6
6
  end
7
7
  def run
8
8
  with_spinner('Enabling repositories') do
9
- feature(:system_repos).enable_repos(@repos)
9
+ repository_manager.enable_repos(@repos)
10
10
  end
11
11
  end
12
12
  end
@@ -14,6 +14,7 @@ module ForemanMaintain::Scenarios
14
14
  add_step(Checks::CheckPuppetCapsules) if server?
15
15
  add_step(Procedures::Puppet::RemovePuppet)
16
16
  add_step(Procedures::Puppet::RemovePuppetData) if context.get(:remove_data)
17
+ add_step(Procedures::Service::Restart)
17
18
  end
18
19
  end
19
20
  end
@@ -1,7 +1,7 @@
1
1
  module ForemanMaintain::Scenarios
2
2
  class SelfUpgradeBase < ForemanMaintain::Scenario
3
3
  def enabled_system_repos_id
4
- feature(:system_repos).enabled_repos_ids
4
+ repository_manager.enabled_repos.keys
5
5
  end
6
6
 
7
7
  def enable_repos(repo_ids = stored_enabled_repos_ids)
@@ -0,0 +1,89 @@
1
+ module Scenarios::Capsule_7_0
2
+ class Abstract < ForemanMaintain::Scenario
3
+ def self.upgrade_metadata(&block)
4
+ metadata do
5
+ tags :upgrade_scenario
6
+ confine do
7
+ feature(:capsule) &&
8
+ (feature(:capsule).current_minor_version == '6.10' || \
9
+ ForemanMaintain.upgrade_in_progress == '7.0')
10
+ end
11
+ instance_eval(&block)
12
+ end
13
+ end
14
+
15
+ def target_version
16
+ '7.0'
17
+ end
18
+ end
19
+
20
+ class PreUpgradeCheck < Abstract
21
+ upgrade_metadata do
22
+ description 'Checks before upgrading to Capsule 7.0'
23
+ tags :pre_upgrade_checks
24
+ run_strategy :fail_slow
25
+ end
26
+
27
+ def compose
28
+ add_steps(find_checks(:default))
29
+ add_steps(find_checks(:pre_upgrade))
30
+ add_step(Checks::Repositories::Validate.new(:version => '7.0'))
31
+ end
32
+ end
33
+
34
+ class PreMigrations < Abstract
35
+ upgrade_metadata do
36
+ description 'Procedures before migrating to Capsule 7.0'
37
+ tags :pre_migrations
38
+ end
39
+
40
+ def compose
41
+ add_steps(find_procedures(:pre_migrations))
42
+ add_step(Procedures::Service::Stop.new)
43
+ end
44
+ end
45
+
46
+ class Migrations < Abstract
47
+ upgrade_metadata do
48
+ description 'Migration scripts to Capsule 7.0'
49
+ tags :migrations
50
+ end
51
+
52
+ def set_context_mapping
53
+ context.map(:assumeyes, Procedures::Installer::Upgrade => :assumeyes)
54
+ end
55
+
56
+ def compose
57
+ add_step(Procedures::Repositories::Setup.new(:version => '7.0'))
58
+ add_step(Procedures::Packages::UnlockVersions.new)
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 'Procedures after migrating to Capsule 7.0'
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 Capsule 7.0'
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,89 @@
1
+ module Scenarios::Capsule_7_0_z
2
+ class Abstract < ForemanMaintain::Scenario
3
+ def self.upgrade_metadata(&block)
4
+ metadata do
5
+ tags :upgrade_scenario
6
+ confine do
7
+ feature(:capsule) &&
8
+ (feature(:capsule).current_minor_version == '7.0' || \
9
+ ForemanMaintain.upgrade_in_progress == '7.0.z')
10
+ end
11
+ instance_eval(&block)
12
+ end
13
+ end
14
+
15
+ def target_version
16
+ '7.0.z'
17
+ end
18
+ end
19
+
20
+ class PreUpgradeCheck < Abstract
21
+ upgrade_metadata do
22
+ description 'Checks before upgrading to Capsule 7.0.z'
23
+ tags :pre_upgrade_checks
24
+ run_strategy :fail_slow
25
+ end
26
+
27
+ def compose
28
+ add_steps(find_checks(:default))
29
+ add_steps(find_checks(:pre_upgrade))
30
+ add_step(Checks::Repositories::Validate.new(:version => '7.0'))
31
+ end
32
+ end
33
+
34
+ class PreMigrations < Abstract
35
+ upgrade_metadata do
36
+ description 'Procedures before migrating to Capsule 7.0.z'
37
+ tags :pre_migrations
38
+ end
39
+
40
+ def compose
41
+ add_steps(find_procedures(:pre_migrations))
42
+ add_step(Procedures::Service::Stop.new)
43
+ end
44
+ end
45
+
46
+ class Migrations < Abstract
47
+ upgrade_metadata do
48
+ description 'Migration scripts to Capsule 7.0.z'
49
+ tags :migrations
50
+ end
51
+
52
+ def set_context_mapping
53
+ context.map(:assumeyes, Procedures::Installer::Upgrade => :assumeyes)
54
+ end
55
+
56
+ def compose
57
+ add_step(Procedures::Repositories::Setup.new(:version => '7.0'))
58
+ add_step(Procedures::Packages::UnlockVersions.new)
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 'Procedures after migrating to Capsule 7.0.z'
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 Capsule 7.0.z'
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
@@ -25,6 +25,7 @@ module Scenarios::Satellite_6_10
25
25
  end
26
26
 
27
27
  def compose
28
+ add_step(Checks::Pulpcore::GroupOwnershipCheck)
28
29
  add_step(Checks::Puppet::WarnAboutPuppetRemoval)
29
30
  add_step(Checks::CheckForNewerPackages.new(:packages => [foreman_plugin_name('katello'),
30
31
  'python3-pulp-2to3-migration'],
@@ -61,13 +62,6 @@ module Scenarios::Satellite_6_10
61
62
  context.map(:assumeyes, Procedures::Installer::Upgrade => :assumeyes)
62
63
  end
63
64
 
64
- def check_var_lib_pulp
65
- group_id = File.stat('/var/lib/pulp/').gid
66
- if Etc.getgrgid(group_id).name != 'pulp'
67
- raise "Please run 'foreman-maintain prep-6.10-upgrade' prior to upgrading."
68
- end
69
- end
70
-
71
65
  def pulp3_switchover_steps
72
66
  add_step(Procedures::Service::Enable.
73
67
  new(:only => Features::Pulpcore.pulpcore_migration_services))
@@ -79,7 +73,6 @@ module Scenarios::Satellite_6_10
79
73
  end
80
74
 
81
75
  def compose
82
- check_var_lib_pulp
83
76
  unless check_min_version(foreman_plugin_name('katello'), '4.0')
84
77
  pulp3_switchover_steps
85
78
  end
@@ -0,0 +1,93 @@
1
+ module Scenarios::Satellite_7_0
2
+ class Abstract < ForemanMaintain::Scenario
3
+ def self.upgrade_metadata(&block)
4
+ metadata do
5
+ tags :upgrade_scenario
6
+ confine do
7
+ feature(:satellite) &&
8
+ (feature(:satellite).current_minor_version == '6.10' || \
9
+ ForemanMaintain.upgrade_in_progress == '7.0')
10
+ end
11
+ instance_eval(&block)
12
+ end
13
+ end
14
+
15
+ def target_version
16
+ '7.0'
17
+ end
18
+ end
19
+
20
+ class PreUpgradeCheck < Abstract
21
+ upgrade_metadata do
22
+ description 'Checks before upgrading to Satellite 7.0'
23
+ tags :pre_upgrade_checks
24
+ run_strategy :fail_slow
25
+ end
26
+
27
+ def compose
28
+ add_steps(find_checks(:default))
29
+ add_steps(find_checks(:pre_upgrade))
30
+
31
+ add_step(Checks::Foreman::CheckpointSegments)
32
+ add_step(Checks::Repositories::Validate.new(:version => '7.0'))
33
+ end
34
+ end
35
+
36
+ class PreMigrations < Abstract
37
+ upgrade_metadata do
38
+ description 'Procedures before migrating to Satellite 7.0'
39
+ tags :pre_migrations
40
+ end
41
+
42
+ def compose
43
+ add_steps(find_procedures(:pre_migrations))
44
+ add_step(Procedures::Service::Stop.new)
45
+ end
46
+ end
47
+
48
+ class Migrations < Abstract
49
+ upgrade_metadata do
50
+ description 'Migration scripts to Satellite 7.0'
51
+ tags :migrations
52
+ run_strategy :fail_fast
53
+ end
54
+
55
+ def set_context_mapping
56
+ context.map(:assumeyes, Procedures::Installer::Upgrade => :assumeyes)
57
+ end
58
+
59
+ def compose
60
+ add_step(Procedures::Repositories::Setup.new(:version => '7.0'))
61
+ add_step(Procedures::Packages::UnlockVersions.new)
62
+ add_step(Procedures::Packages::Update.new(:assumeyes => true))
63
+ add_step_with_context(Procedures::Installer::Upgrade)
64
+ add_step(Procedures::Installer::UpgradeRakeTask)
65
+ end
66
+ end
67
+
68
+ class PostMigrations < Abstract
69
+ upgrade_metadata do
70
+ description 'Procedures after migrating to Satellite 7.0'
71
+ tags :post_migrations
72
+ end
73
+
74
+ def compose
75
+ add_step(Procedures::RefreshFeatures)
76
+ add_step(Procedures::Service::Start.new)
77
+ add_steps(find_procedures(:post_migrations))
78
+ end
79
+ end
80
+
81
+ class PostUpgradeChecks < Abstract
82
+ upgrade_metadata do
83
+ description 'Checks after upgrading to Satellite 7.0'
84
+ tags :post_upgrade_checks
85
+ run_strategy :fail_slow
86
+ end
87
+
88
+ def compose
89
+ add_steps(find_checks(:default))
90
+ add_steps(find_checks(:post_upgrade))
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,90 @@
1
+ module Scenarios::Satellite_7_0_z
2
+ class Abstract < ForemanMaintain::Scenario
3
+ def self.upgrade_metadata(&block)
4
+ metadata do
5
+ tags :upgrade_scenario
6
+ confine do
7
+ feature(:satellite) &&
8
+ (feature(:satellite).current_minor_version == '7.0' || \
9
+ ForemanMaintain.upgrade_in_progress == '7.0.z')
10
+ end
11
+ instance_eval(&block)
12
+ end
13
+ end
14
+
15
+ def target_version
16
+ '7.0.z'
17
+ end
18
+ end
19
+
20
+ class PreUpgradeCheck < Abstract
21
+ upgrade_metadata do
22
+ description 'Checks before upgrading to Satellite 7.0.z'
23
+ tags :pre_upgrade_checks
24
+ run_strategy :fail_slow
25
+ end
26
+
27
+ def compose
28
+ add_steps(find_checks(:default))
29
+ add_steps(find_checks(:pre_upgrade))
30
+ add_step(Checks::Repositories::Validate.new(:version => '7.0'))
31
+ end
32
+ end
33
+
34
+ class PreMigrations < Abstract
35
+ upgrade_metadata do
36
+ description 'Procedures before migrating to Satellite 7.0.z'
37
+ tags :pre_migrations
38
+ end
39
+
40
+ def compose
41
+ add_steps(find_procedures(:pre_migrations))
42
+ add_step(Procedures::Service::Stop.new)
43
+ end
44
+ end
45
+
46
+ class Migrations < Abstract
47
+ upgrade_metadata do
48
+ description 'Migration scripts to Satellite 7.0.z'
49
+ tags :migrations
50
+ end
51
+
52
+ def set_context_mapping
53
+ context.map(:assumeyes, Procedures::Installer::Upgrade => :assumeyes)
54
+ end
55
+
56
+ def compose
57
+ add_step(Procedures::Repositories::Setup.new(:version => '7.0'))
58
+ add_step(Procedures::Packages::UnlockVersions.new)
59
+ add_step(Procedures::Packages::Update.new(:assumeyes => true))
60
+ add_step_with_context(Procedures::Installer::Upgrade)
61
+ add_step(Procedures::Installer::UpgradeRakeTask)
62
+ end
63
+ end
64
+
65
+ class PostMigrations < Abstract
66
+ upgrade_metadata do
67
+ description 'Procedures after migrating to Satellite 7.0.z'
68
+ tags :post_migrations
69
+ end
70
+
71
+ def compose
72
+ add_step(Procedures::RefreshFeatures)
73
+ add_step(Procedures::Service::Start.new)
74
+ add_steps(find_procedures(:post_migrations))
75
+ end
76
+ end
77
+
78
+ class PostUpgradeChecks < Abstract
79
+ upgrade_metadata do
80
+ description 'Checks after upgrading to Satellite 7.0.z'
81
+ tags :post_upgrade_checks
82
+ run_strategy :fail_slow
83
+ end
84
+
85
+ def compose
86
+ add_steps(find_checks(:default))
87
+ add_steps(find_checks(:post_upgrade))
88
+ end
89
+ end
90
+ end
@@ -17,6 +17,10 @@ module ForemanMaintain
17
17
  current_version.to_s[/^\d+\.\d+/]
18
18
  end
19
19
 
20
+ def repository_manager
21
+ ForemanMaintain.repository_manager
22
+ end
23
+
20
24
  # TODO: Modify activation_key changes as per server
21
25
  def setup_repositories(version)
22
26
  activation_key = ENV['EXTERNAL_SAT_ACTIVATION_KEY']
@@ -26,18 +30,14 @@ module ForemanMaintain
26
30
  execute!(%(subscription-manager register #{org_options}\
27
31
  --activationkey #{shellescape(activation_key)} --force))
28
32
  else
29
- execute!(%(subscription-manager repos --disable '*'))
30
- enable_options = rh_repos(version).map { |r| "--enable=#{r}" }.join(' ')
31
- execute!(%(subscription-manager repos #{enable_options}))
33
+ repository_manager.rhsm_disable_repos(['*'])
34
+ repository_manager.rhsm_enable_repos(rh_repos(version))
32
35
  end
33
36
  end
34
37
 
35
38
  def absent_repos(version)
36
- all_repo_lines = execute(%(LANG=en_US.utf-8 subscription-manager repos --list 2>&1 | ) +
37
- %(grep '^Repo ID:')).split("\n")
38
- all_repos = all_repo_lines.map { |line| line.split(/\s+/).last }
39
39
  repos_required = rh_repos(version)
40
- repos_found = repos_required & all_repos
40
+ repos_found = repos_required & repository_manager.rhsm_list_repos.keys
41
41
  repos_required - repos_found
42
42
  end
43
43
 
@@ -74,21 +74,36 @@ module ForemanMaintain
74
74
 
75
75
  def ansible_repo(server_version)
76
76
  if server_version >= version('6.8')
77
- "rhel-#{el_major_version}-server-ansible-2.9-rpms"
77
+ ansible_version = '2.9'
78
78
  elsif server_version >= version('6.6')
79
- "rhel-#{el_major_version}-server-ansible-2.8-rpms"
79
+ ansible_version = '2.8'
80
80
  elsif server_version >= version('6.4')
81
- "rhel-#{el_major_version}-server-ansible-2.6-rpms"
81
+ ansible_version = '2.6'
82
+ end
83
+
84
+ if el7?
85
+ "rhel-#{el_major_version}-server-ansible-#{ansible_version}-rpms"
86
+ else
87
+ "ansible-#{ansible_version}-for-rhel-#{el_major_version}-x86_64-rpms"
82
88
  end
83
89
  end
84
90
 
91
+ def use_beta_repos?
92
+ ENV['FOREMAN_MAINTAIN_USE_BETA'] == '1'
93
+ end
94
+
85
95
  def product_specific_repos(full_version)
86
- repos = []
87
- repos << if ENV['FOREMAN_MAINTAIN_USE_BETA'] == '1'
88
- "rhel-server-#{el_major_version}-#{package_name}-6-beta-rpms"
89
- else
90
- "rhel-#{el_major_version}-server-#{package_name}-#{full_version}-rpms"
91
- end
96
+ maj_version = full_version[0]
97
+ repos = if el7? && use_beta_repos?
98
+ ["rhel-server-#{el_major_version}-#{package_name}-#{maj_version}-beta-rpms"]
99
+ elsif el7?
100
+ ["rhel-#{el_major_version}-server-#{package_name}-#{full_version}-rpms"]
101
+ elsif use_beta_repos?
102
+ ["#{package_name}-#{maj_version}-beta-for-rhel-#{el_major_version}-x86_64-rpms"]
103
+ else
104
+ ["#{package_name}-#{full_version}-for-rhel-#{el_major_version}-x86_64-rpms"]
105
+ end
106
+
92
107
  repos << puppet4_repo(full_version) unless puppet4_repo(full_version).nil?
93
108
  repos.concat(common_repos(full_version))
94
109
  end
@@ -101,22 +116,35 @@ module ForemanMaintain
101
116
  end
102
117
 
103
118
  def common_repos(full_version)
104
- repos_arrary = if ENV['FOREMAN_MAINTAIN_USE_BETA'] == '1'
105
- ["rhel-#{el_major_version}-server-satellite-maintenance-6-beta-rpms",
106
- "rhel-#{el_major_version}-server-satellite-tools-6-beta-rpms"]
107
- else
108
- ["rhel-#{el_major_version}-server-satellite-maintenance-6-rpms",
109
- "rhel-#{el_major_version}-server-satellite-tools-#{full_version}-rpms"]
110
- end
111
-
112
- return repos_arrary.first(1) if feature(:satellite)
113
-
114
- repos_arrary
119
+ sat_maint_version = if version(full_version) >= version('7.0') && !use_beta_repos?
120
+ full_version
121
+ else
122
+ full_version[0]
123
+ end
124
+
125
+ # rubocop:disable Metrics/LineLength
126
+ repos = if el7? && use_beta_repos?
127
+ ["rhel-#{el_major_version}-server-satellite-maintenance-#{sat_maint_version}-beta-rpms"]
128
+ elsif el7?
129
+ ["rhel-#{el_major_version}-server-satellite-maintenance-#{sat_maint_version}-rpms"]
130
+ elsif use_beta_repos?
131
+ ["satellite-maintenance-#{sat_maint_version}-beta-for-rhel-#{el_major_version}-x86_64-rpms"]
132
+ else
133
+ ["satellite-maintenance-#{sat_maint_version}-for-rhel-#{el_major_version}-x86_64-rpms"]
134
+ end
135
+ # rubocop:enable Metrics/LineLength
136
+
137
+ repos
115
138
  end
116
139
 
117
140
  def main_rh_repos
118
- ["rhel-#{el_major_version}-server-rpms",
119
- "rhel-server-rhscl-#{el_major_version}-rpms"]
141
+ if el7?
142
+ ["rhel-#{el_major_version}-server-rpms",
143
+ "rhel-server-rhscl-#{el_major_version}-rpms"]
144
+ else
145
+ ["rhel-#{el_major_version}-for-x86_64-baseos-rpms",
146
+ "rhel-#{el_major_version}-for-x86_64-appstream-rpms"]
147
+ end
120
148
  end
121
149
 
122
150
  def version_from_source
@@ -185,6 +185,10 @@ module ForemanMaintain
185
185
  ForemanMaintain.package_manager
186
186
  end
187
187
 
188
+ def repository_manager
189
+ ForemanMaintain.repository_manager
190
+ end
191
+
188
192
  def ruby_prefix(scl = true)
189
193
  if debian?
190
194
  'ruby-'
@@ -0,0 +1,85 @@
1
+ module ForemanMaintain::RepositoryManager
2
+ class El
3
+ include ForemanMaintain::Concerns::OsFacts
4
+ include ForemanMaintain::Concerns::SystemHelpers
5
+
6
+ def disable_repos(repo_ids)
7
+ if el7?
8
+ execute!("yum-config-manager #{config_manager_options(repo_ids, 'disable')}")
9
+ else
10
+ execute!("dnf config-manager #{config_manager_options(repo_ids, 'set-disabled')}")
11
+ end
12
+ end
13
+
14
+ def rhsm_disable_repos(repo_ids)
15
+ if rhsm_available?
16
+ execute!(%(subscription-manager repos #{rhsm_options(repo_ids, 'disable')}))
17
+ else
18
+ logger.info("subscription-manager is not available.\
19
+ Using #{pkg_manager} config manager instead.")
20
+ disable_repos(repo_ids)
21
+ end
22
+ end
23
+
24
+ def enable_repos(repo_ids)
25
+ if el7?
26
+ execute!("yum-config-manager #{config_manager_options(repo_ids, 'enable')}")
27
+ else
28
+ execute!("dnf config-manager #{config_manager_options(repo_ids, 'enable')}")
29
+ end
30
+ end
31
+
32
+ def rhsm_enable_repos(repo_ids)
33
+ if rhsm_available?
34
+ execute!(%(subscription-manager repos #{rhsm_options(repo_ids, 'enable')}))
35
+ else
36
+ logger.info("subscription-manager is not available.\
37
+ Using #{pkg_manager} config manager instead.")
38
+ enable_repos(repo_ids)
39
+ end
40
+ end
41
+
42
+ def rhsm_options(repo_ids, options)
43
+ repo_ids.map { |r| "--#{options}=#{r}" }.join(' ')
44
+ end
45
+
46
+ def config_manager_options(repo_ids, options)
47
+ repo_ids_string = if repo_ids.is_a?(Array)
48
+ repo_ids.join(',')
49
+ else
50
+ repo_ids
51
+ end
52
+ format_shell_args("--#{options}" => repo_ids_string)
53
+ end
54
+
55
+ def rhsm_available?
56
+ @rhsm_available ||= find_package('subscription-manager')
57
+ end
58
+
59
+ def rhsm_list_repos(list_option = '--list')
60
+ repos = execute(%(LANG=en_US.utf-8 subscription-manager repos #{list_option} 2>&1))
61
+ return {} if repos.empty?
62
+
63
+ hash_of_repoids_urls(repos, /Repo ID|Repo URL/)
64
+ end
65
+
66
+ def pkg_manager
67
+ package_manager.class.name.split('::').last.downcase
68
+ end
69
+
70
+ def enabled_repos
71
+ cmd = "#{pkg_manager} repolist enabled -d 6 -e 0 2> /dev/null"
72
+ repos = execute(cmd)
73
+ return {} if repos.empty?
74
+
75
+ hash_of_repoids_urls(repos, /Repo-id|Repo-baseurl/)
76
+ end
77
+
78
+ def hash_of_repoids_urls(repos, regex)
79
+ Hash[*repos.split("\n").grep(regex).map do |entry|
80
+ entry.split(':', 2).last.strip
81
+ end
82
+ ]
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,13 @@
1
+ require 'foreman_maintain/repository_manager/el'
2
+ include ForemanMaintain::Concerns::OsFacts
3
+ module ForemanMaintain
4
+ def self.repository_manager
5
+ @repository_manager ||= if el?
6
+ ForemanMaintain::RepositoryManager::El.new
7
+ elsif debian?
8
+ raise 'Not implemented!'
9
+ else
10
+ raise 'No supported repository manager was found'
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '0.9.3'.freeze
2
+ VERSION = '1.0.3'.freeze
3
3
  end
@@ -40,6 +40,7 @@ module ForemanMaintain
40
40
  require 'foreman_maintain/upgrade_runner'
41
41
  require 'foreman_maintain/reporter'
42
42
  require 'foreman_maintain/package_manager'
43
+ require 'foreman_maintain/repository_manager'
43
44
  require 'foreman_maintain/utils'
44
45
  require 'foreman_maintain/error'
45
46
 
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.9.3
4
+ version: 1.0.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-11-24 00:00:00.000000000 Z
11
+ date: 2022-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -169,6 +169,7 @@ files:
169
169
  - definitions/checks/original_assets.rb
170
170
  - definitions/checks/package_manager/yum/validate_yum_config.rb
171
171
  - definitions/checks/pulpcore/db_up.rb
172
+ - definitions/checks/pulpcore/group_ownership_check.rb
172
173
  - definitions/checks/puppet/provide_upgrade_guide.rb
173
174
  - definitions/checks/puppet/verify_no_empty_cacert_requests.rb
174
175
  - definitions/checks/puppet/warn_about_puppet_removal.rb
@@ -213,9 +214,9 @@ files:
213
214
  - definitions/features/satellite.rb
214
215
  - definitions/features/service.rb
215
216
  - definitions/features/sync_plans.rb
216
- - definitions/features/system_repos.rb
217
217
  - definitions/features/tar.rb
218
218
  - definitions/features/upstream.rb
219
+ - definitions/features/upstream_repositories.rb
219
220
  - definitions/procedures/backup/accessibility_confirmation.rb
220
221
  - definitions/procedures/backup/clean.rb
221
222
  - definitions/procedures/backup/compress_data.rb
@@ -335,6 +336,8 @@ files:
335
336
  - definitions/scenarios/upgrade_to_capsule_6_8_z.rb
336
337
  - definitions/scenarios/upgrade_to_capsule_6_9.rb
337
338
  - definitions/scenarios/upgrade_to_capsule_6_9_z.rb
339
+ - definitions/scenarios/upgrade_to_capsule_7_0.rb
340
+ - definitions/scenarios/upgrade_to_capsule_7_0_z.rb
338
341
  - definitions/scenarios/upgrade_to_satellite_6_10.rb
339
342
  - definitions/scenarios/upgrade_to_satellite_6_10_z.rb
340
343
  - definitions/scenarios/upgrade_to_satellite_6_2.rb
@@ -353,6 +356,8 @@ files:
353
356
  - definitions/scenarios/upgrade_to_satellite_6_8_z.rb
354
357
  - definitions/scenarios/upgrade_to_satellite_6_9.rb
355
358
  - definitions/scenarios/upgrade_to_satellite_6_9_z.rb
359
+ - definitions/scenarios/upgrade_to_satellite_7_0.rb
360
+ - definitions/scenarios/upgrade_to_satellite_7_0_z.rb
356
361
  - extras/foreman-maintain.sh
357
362
  - extras/foreman_protector/foreman-protector.conf
358
363
  - extras/foreman_protector/foreman-protector.py
@@ -411,6 +416,8 @@ files:
411
416
  - lib/foreman_maintain/procedure.rb
412
417
  - lib/foreman_maintain/reporter.rb
413
418
  - lib/foreman_maintain/reporter/cli_reporter.rb
419
+ - lib/foreman_maintain/repository_manager.rb
420
+ - lib/foreman_maintain/repository_manager/el.rb
414
421
  - lib/foreman_maintain/runner.rb
415
422
  - lib/foreman_maintain/runner/execution.rb
416
423
  - lib/foreman_maintain/runner/stored_execution.rb
@@ -1,58 +0,0 @@
1
- class Features::SystemRepos < ForemanMaintain::Feature
2
- metadata do
3
- label :system_repos
4
- description 'Feature for operations on yum repositories of system'
5
- end
6
-
7
- def upstream_repos
8
- repositories = {}
9
- enabled_repos_hash.each do |repo, url|
10
- upstream_repo_urls.each do |regex|
11
- repositories[repo] = url if url =~ regex
12
- end
13
- end
14
- repositories
15
- end
16
-
17
- def enabled_repos_hash
18
- repos = execute("yum repolist enabled -d 6 -e 0 2> /dev/null | grep -E 'Repo-id|Repo-baseurl'")
19
- return {} if repos.empty?
20
-
21
- Hash[*repos.delete!(' ').split("\n")]
22
- end
23
-
24
- def enabled_repos_ids
25
- trim_repoids(enabled_repos_hash.keys)
26
- end
27
-
28
- def upstream_repos_ids
29
- trim_repoids(upstream_repos.keys)
30
- end
31
-
32
- def disable_repos(repo_ids)
33
- execute!("yum-config-manager --disable #{repo_ids.join(',')}")
34
- end
35
-
36
- def enable_repos(repo_ids)
37
- execute!("yum-config-manager --enable #{repo_ids.join(',')}")
38
- end
39
-
40
- private
41
-
42
- def trim_repoids(repos)
43
- repos.map { |r| r.gsub(%r{Repo-id:|\/+\w*}, '') }
44
- end
45
-
46
- def upstream_repo_urls
47
- repo_urls = { :Foreman => %r{yum.theforeman.org\/},
48
- :Katello => %r{fedorapeople.org\/groups\/katello\/releases\/yum\/[\/|\w|.]*} }
49
- [/#{repo_urls[:Foreman]}+releases/,
50
- /#{repo_urls[:Foreman]}+plugins/,
51
- /#{repo_urls[:Katello]}+katello/,
52
- /#{repo_urls[:Katello]}+client/,
53
- /#{repo_urls[:Katello]}+candlepin/,
54
- /#{repo_urls[:Katello]}+pulp/,
55
- %r{yum.puppetlabs.com\/el\/[\w|\/|\.]*\/x86_64},
56
- %r{repos.fedorapeople.org\/repos\/pulp\/[\/|\w|.]*\/x86_64}]
57
- end
58
- end