Skip to content

Commit

Permalink
Refs #33620 - limit self-upgrade target version upto N+1
Browse files Browse the repository at this point in the history
(cherry picked from commit 8f1ee8d)
  • Loading branch information
upadhyeammit committed Apr 6, 2022
1 parent d755faf commit afa0d09
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
3 changes: 2 additions & 1 deletion definitions/scenarios/self_upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def disable_repos(repo_ids = stored_enabled_repos_ids)
end

def target_version
@target_version ||= context.get(:target_version)
current_full_version = feature(:instance).downstream.current_version
@target_version ||= current_full_version.bump
end

def current_version
Expand Down
33 changes: 6 additions & 27 deletions lib/foreman_maintain/cli/self_upgrade_command.rb
Original file line number Diff line number Diff line change
@@ -1,44 +1,23 @@
module ForemanMaintain
module Cli
class SelfUpgradeCommand < Base
option ['--target-version'], 'TARGET_VERSION',\
'Major version of the Satellite or Capsule'\
', e.g 6.11', :required => true
option ['--maintenance-repo-label'], 'REPOSITORY_LABEL',\
'Repository label from which packages should be updated.'\
'This can be used when standard CDN repositories are unavailable.'

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,
maintenance_repo_label: maintenance_repo_label)
Scenarios::SelfUpgrade.new(
maintenance_repo_label: maintenance_repo_label
)
end

def upgrade_rescue_scenario
Scenarios::SelfUpgradeRescue.new(target_version: target_version,
maintenance_repo_label: maintenance_repo_label)
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},"\
"\nand self-upgrade should be used for major version upgrades only!"
raise Error::UsageError, message
end
Scenarios::SelfUpgradeRescue.new(
maintenance_repo_label: maintenance_repo_label
)
end
end
end
Expand Down

0 comments on commit afa0d09

Please sign in to comment.