Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

satellite maintain metadata #936

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
48 changes: 48 additions & 0 deletions test/definitions/scenarios/satellite_upgrade_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,54 @@

before(:each) do
assume_satellite_present
mock_satellite_maintain_config
end

describe Scenarios::Satellite::Abstract do
let(:expected_scenarios) do
[Scenarios::Satellite::Migrations, Scenarios::Satellite::PostMigrations,
Scenarios::Satellite::PostUpgradeChecks, Scenarios::Satellite::PreMigrations,
Scenarios::Satellite::PreUpgradeCheck]
end

it 'is present when running 6.15' do
Features::Satellite.any_instance.stubs(:current_version).returns('6.15')

scenarios = find_scenarios({ :tags => [:upgrade_scenario] })

expected_scenarios.each do |exp|
assert scenarios.find { |s| s.is_a? exp }, "Expected #{exp} to be present"
end
end

it 'is not present when already on 6.16' do
Features::Satellite.any_instance.stubs(:current_version).returns('6.16')

scenarios = find_scenarios({ :tags => [:upgrade_scenario] })

assert_empty scenarios
end

it 'is present when 6.16 upgrade in progress' do
Features::Satellite.any_instance.stubs(:current_version).returns('6.16')
ForemanMaintain.stubs(:upgrade_in_progress).returns('6.16')

scenarios = find_scenarios({ :tags => [:upgrade_scenario] })

expected_scenarios.each do |exp|
assert scenarios.find { |s| s.is_a? exp }, "Expected #{exp} to be present"
end
end

it 'sets target_version to 6.16' do
Features::Satellite.any_instance.stubs(:current_version).returns('6.15')

scenarios = find_scenarios({ :tags => [:upgrade_scenario] })

scenarios.each do |scenario|
assert_equal '6.16', scenario.target_version
end
end
end

describe Scenarios::Satellite::PreUpgradeCheck 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',
}
evgeni marked this conversation as resolved.
Show resolved Hide resolved
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
Loading