-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #33620 - Command for upgrading foreman-maintain to major version
- Loading branch information
1 parent
49163fd
commit 894e362
Showing
7 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
definitions/procedures/repositories/backup_enabled_repos.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Procedures::Repositories | ||
class BackupEnabledRepos < ForemanMaintain::Procedure | ||
metadata do | ||
label :backup_enabled_repos | ||
description 'Stores enabled repositories in yaml file' | ||
end | ||
|
||
def run | ||
enabled_repos_ids = feature(:system_repos).enabled_repos_ids | ||
unless enabled_repos_ids.empty? | ||
backup_dir = File.expand_path(ForemanMaintain.config.backup_dir) | ||
File.write(File.join(backup_dir, 'enabled_repos.yml'), enabled_repos_ids.to_yaml) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Procedures::Repositories | ||
class Enable < ForemanMaintain::Procedure | ||
metadata do | ||
param :repos, 'List of repositories to enable' | ||
description 'Enable repositories' | ||
end | ||
def run | ||
with_spinner('Enabling repositories') do | ||
feature(:system_repos).enable_repos(@repos) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
module ForemanMaintain::Scenarios | ||
class SelfUpgradeBase < ForemanMaintain::Scenario | ||
def enabled_system_repos_id | ||
feature(:system_repos).enabled_repos_ids | ||
end | ||
|
||
def enable_repos(repo_ids = stored_enabled_repos_ids) | ||
add_step(Procedures::Repositories::Enable.new(repos: repo_ids)) | ||
end | ||
|
||
def disable_repos(repo_ids = stored_enabled_repos_ids) | ||
add_step(Procedures::Repositories::Disable.new(repos: repo_ids)) | ||
end | ||
|
||
def target_version | ||
@target_version ||= context.get(:target_version) | ||
end | ||
|
||
def current_version | ||
feature(:instance).downstream.current_minor_version | ||
end | ||
|
||
def maintenance_repo_id(version) | ||
if (repo = ENV['maintenance_repo']) | ||
return repo unless repo.empty? | ||
end | ||
|
||
maintenance_repo(version) | ||
end | ||
|
||
def maintenance_repo(version) | ||
if el7? | ||
"rhel-#{el_major_version}-server-satellite-maintenance-#{version}-rpms" | ||
else | ||
"satellite-maintenance-#{version}-for-rhel-#{el_major_version}-x86_64-rpms" | ||
end | ||
end | ||
|
||
def maintenance_repo_version | ||
return '6' if current_version == '6.10' | ||
|
||
current_version | ||
end | ||
|
||
def stored_enabled_repos_ids | ||
@stored_enabled_repos_ids ||= begin | ||
path = File.expand_path('enabled_repos.yml', ForemanMaintain.config.backup_dir) | ||
@stored_enabled_repos_ids = File.file?(path) ? YAML.load(File.read(path)) : [] | ||
end | ||
end | ||
|
||
def all_maintenance_repos | ||
repo_regex = if el7? | ||
/rhel-\d-server-satellite-maintenance-\d.\d-rpms/ | ||
else | ||
/satellite-maintenance-\d.\d-for-rhel-\d-x86_64-rpms/ | ||
end | ||
stored_enabled_repos_ids.select { |id| !id.match(repo_regex).nil? } | ||
end | ||
|
||
def repos_ids_to_reenable | ||
repos_ids_to_reenable = stored_enabled_repos_ids - all_maintenance_repos | ||
repos_ids_to_reenable << maintenance_repo(maintenance_repo_version) | ||
end | ||
end | ||
|
||
class SelfUpgrade < SelfUpgradeBase | ||
metadata do | ||
label :self_upgrade_foreman_maintain | ||
description "Enables the specified version's maintenance repository and, "\ | ||
'updates the foreman-maintain packages' | ||
manual_detection | ||
end | ||
|
||
def compose | ||
if check_min_version('foreman', '2.5') || check_min_version('foreman-proxy', '2.5') | ||
pkgs_to_update = %w[satellite-maintain rubygem-foreman_maintain] | ||
add_step(Procedures::Repositories::BackupEnabledRepos.new) | ||
disable_repos | ||
add_step(Procedures::Repositories::Enable.new(repos: [maintenance_repo_id(target_version)])) | ||
add_step(Procedures::Packages::Update.new(packages: pkgs_to_update, assumeyes: true)) | ||
enable_repos(repos_ids_to_reenable) | ||
end | ||
end | ||
end | ||
|
||
class SelfUpgradeRescue < SelfUpgradeBase | ||
metadata do | ||
label :rescue_self_upgrade | ||
description 'Disables all version specific maintenance repos and,'\ | ||
' enables the repositories which were configured prior to self upgrade' | ||
manual_detection | ||
run_strategy :fail_slow | ||
end | ||
|
||
def compose | ||
if check_min_version('foreman', '2.5') || check_min_version('foreman-proxy', '2.5') | ||
enable_repos(repos_ids_to_reenable) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module ForemanMaintain | ||
module Cli | ||
class SelfUpgradeCommand < Base | ||
option ['--target-version'], 'TARGET_VERSION',\ | ||
'Major version of the Satellite or Capsule'\ | ||
', e.g 7.0', :required => true | ||
def execute | ||
allow_major_version_upgrade_only | ||
run_scenario(upgrade_scenario, upgrade_rescue_scenario) | ||
end | ||
|
||
def upgrade_scenario | ||
Scenarios::SelfUpgrade.new(target_version: target_version) | ||
end | ||
|
||
def upgrade_rescue_scenario | ||
Scenarios::SelfUpgradeRescue.new(target_version: target_version) | ||
end | ||
|
||
def current_downstream_version | ||
ForemanMaintain.detector.feature(:instance).downstream.current_version | ||
end | ||
|
||
def allow_major_version_upgrade_only | ||
begin | ||
next_version = Gem::Version.new(target_version) | ||
rescue ArgumentError => err | ||
raise Error::UsageError, "Invalid version! #{err}" | ||
end | ||
if current_downstream_version >= next_version | ||
message = "The target-version #{target_version} should be "\ | ||
"greater than existing version #{current_downstream_version}!" | ||
raise Error::UsageError, message | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters