Skip to content

Commit

Permalink
move the logic which versions are supported into the downstream concern
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Oct 10, 2024
1 parent 0a34801 commit 91be6bb
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion definitions/features/satellite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Features::Satellite < ForemanMaintain::Feature
end

def target_version
'6.16'
satellite_maintain_target_version
end

def current_version
Expand Down
5 changes: 2 additions & 3 deletions definitions/scenarios/satellite_upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ def self.upgrade_metadata(&block)
metadata do
tags :upgrade_scenario
confine do
(feature(:instance).downstream&.current_minor_version == '6.15' || \
ForemanMaintain.upgrade_in_progress == '6.16')
feature(:instance).downstream&.satellite_upgrade_allowed?
end
instance_eval(&block)
end
end

def target_version
'6.16'
feature(:instance).downstream&.satellite_maintain_target_version
end
end

Expand Down
19 changes: 19 additions & 0 deletions lib/foreman_maintain/concerns/downstream.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module ForemanMaintain
module Concerns
module Downstream
SATELLITE_MAINTAIN_CONFIG = '/usr/share/satellite-maintain/config.yml'.freeze

def current_version
raise NotImplementedError
end
Expand Down Expand Up @@ -46,8 +48,25 @@ def fm_pkg_and_cmd_name
%w[satellite-maintain satellite-maintain]
end

def satellite_maintain_target_version
satellite_maintain_config['current_satellite_version']
end

def satellite_upgrade_allowed?
current_minor_version == satellite_maintain_config['previous_satellite_version'] ||
ForemanMaintain.upgrade_in_progress == satellite_maintain_target_version
end

private

def satellite_maintain_config
if File.exist?(SATELLITE_MAINTAIN_CONFIG)
YAML.load_file(SATELLITE_MAINTAIN_CONFIG)
else
raise "Could not load satellite-maintain configuration file #{SATELLITE_MAINTAIN_CONFIG}."
end
end

def rh_repos(server_version)
server_version = version(server_version)
rh_repos = main_rh_repos
Expand Down
1 change: 1 addition & 0 deletions test/definitions/scenarios/capsule_upgrade_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

before(:each) do
assume_feature_present(:capsule)
mock_satellite_maintain_config
end

describe Scenarios::Satellite::PreUpgradeCheck do
Expand Down
1 change: 1 addition & 0 deletions test/definitions/scenarios/satellite_upgrade_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

before(:each) do
assume_satellite_present
mock_satellite_maintain_config
end

describe Scenarios::Satellite::Abstract do
Expand Down
2 changes: 2 additions & 0 deletions test/definitions/scenarios/self_upgrade_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

before do
File.stubs(:exist?).with('/etc/redhat-release').returns(true)
mock_satellite_maintain_config
end

let(:scenario) do
Expand Down Expand Up @@ -59,6 +60,7 @@

before do
File.stubs(:exist?).with('/etc/redhat-release').returns(true)
mock_satellite_maintain_config
end

it 'runs successfully for downstream Satellite' do
Expand Down
4 changes: 4 additions & 0 deletions test/definitions/scenarios/update_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
describe "update scenarios" do
include DefinitionsTestHelper

before(:each) do
mock_satellite_maintain_config
end

it 'runs if versions match' do
assume_satellite_present
Features::Instance.any_instance.expects(:current_version).returns('6.16')
Expand Down
9 changes: 9 additions & 0 deletions test/definitions/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ def assume_service_missing(name, priority = 30)
yield service if block_given?
end
end

def mock_satellite_maintain_config
config = {
'current_satellite_version' => '6.16',
'previous_satellite_version' => '6.15',
}
Features::Satellite.any_instance.stubs(:satellite_maintain_config).returns(config)
Features::Capsule.any_instance.stubs(:satellite_maintain_config).returns(config)
end
end

TEST_DIR = File.dirname(__FILE__)
Expand Down

0 comments on commit 91be6bb

Please sign in to comment.