foreman_maintain 0.8.22 → 0.8.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 197a1b9603612e47c37ae3a24fec9362d70eb50447144ea599b612571565ea3b
4
- data.tar.gz: d100893294ab1e960e3e7f93cdca402ffbfc5f64c0f51d19f7aa074ee0b18b1a
3
+ metadata.gz: 99acc882c19945554772facce2ff0e3089de68ebcd0f7dab47ef4847ac849ea6
4
+ data.tar.gz: 972b0f7a083e94a313bad7d702fbe599e3d5f68d235f464a3307c83c011f052e
5
5
  SHA512:
6
- metadata.gz: 72d0e0a9f785ea86cb69e7ef2b12c26d7e9ae3777347ec29780395bd32539e08e8c8344242a3c6974518a5ed4df03585b6817b0e08d9491aa8d0f87076ceb8aa
7
- data.tar.gz: d7bcef48c7493525577c010f40079d33b3bcd834d370bbba2e298592562eff57acc79e8c0bb6eb80925bd15a28d13c39e827195fc1cd1a8a08a4f28c7d02a6df
6
+ metadata.gz: 82314efa29ff8fabade9eecaf0e5dc6d9502287056b4d13a84109b11bbd5f351a4706de88c07840301e877db05cda9a69a4d7fc17ec7a806deed7a64cf34e5a9
7
+ data.tar.gz: d011a14d5660a90ecc00598bec5a42c9741f6c1fad3091316e1232cd9ea0fe635c026319d2cb5df2adb5f1f5d5cc02d2e71e5d047ce6bca79b0097e2184c28ce
@@ -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)
@@ -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
@@ -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
+ "\nupdates the satellite-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 repositories and,'\
91
+ "\nenables 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,39 @@
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
+ "\nand self-upgrade should be used for major version upgrades only!"
34
+ raise Error::UsageError, message
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -11,6 +11,7 @@ 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/self_upgrade_command'
14
15
 
15
16
  module ForemanMaintain
16
17
  module Cli
@@ -25,6 +26,7 @@ module ForemanMaintain
25
26
  subcommand 'packages', 'Lock/Unlock package protection, install, update', PackagesCommand
26
27
  subcommand 'advanced', 'Advanced tools for server maintenance', AdvancedCommand
27
28
  subcommand 'content', 'Content related commands', ContentCommand
29
+ subcommand 'self-upgrade', 'Perform major version self upgrade', SelfUpgradeCommand
28
30
  subcommand 'maintenance-mode', 'Control maintenance-mode for application',
29
31
  MaintenanceModeCommand
30
32
  if ForemanMaintain.detector.feature(:satellite) &&
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '0.8.22'.freeze
2
+ VERSION = '0.8.23'.freeze
3
3
  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: 0.8.22
4
+ version: 0.8.23
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-12-20 00:00:00.000000000 Z
11
+ date: 2022-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -274,7 +274,9 @@ files:
274
274
  - definitions/procedures/puppet/delete_empty_ca_cert_request_files.rb
275
275
  - definitions/procedures/refresh_features.rb
276
276
  - definitions/procedures/remote_execution/remove_existing_settingsd.rb
277
+ - definitions/procedures/repositories/backup_enabled_repos.rb
277
278
  - definitions/procedures/repositories/disable.rb
279
+ - definitions/procedures/repositories/enable.rb
278
280
  - definitions/procedures/repositories/setup.rb
279
281
  - definitions/procedures/restore/candlepin_dump.rb
280
282
  - definitions/procedures/restore/configs.rb
@@ -307,6 +309,7 @@ files:
307
309
  - definitions/scenarios/packages.rb
308
310
  - definitions/scenarios/prep_6_10_upgrade.rb
309
311
  - definitions/scenarios/restore.rb
312
+ - definitions/scenarios/self_upgrade.rb
310
313
  - definitions/scenarios/services.rb
311
314
  - definitions/scenarios/upgrade_to_capsule_6_10.rb
312
315
  - definitions/scenarios/upgrade_to_capsule_6_10_z.rb
@@ -354,6 +357,7 @@ files:
354
357
  - lib/foreman_maintain/cli/maintenance_mode_command.rb
355
358
  - lib/foreman_maintain/cli/packages_command.rb
356
359
  - lib/foreman_maintain/cli/restore_command.rb
360
+ - lib/foreman_maintain/cli/self_upgrade_command.rb
357
361
  - lib/foreman_maintain/cli/service_command.rb
358
362
  - lib/foreman_maintain/cli/transform_clamp_options.rb
359
363
  - lib/foreman_maintain/cli/upgrade_command.rb