Skip to content
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
41 changes: 41 additions & 0 deletions definitions/checks/check_subscription_manager_release.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Checks::CheckSubscriptionManagerRelease < ForemanMaintain::Check
metadata do
label :check_subscription_manager_release
description 'Check if subscription-manager release is not set to a minor version'

confine do
feature(:instance).downstream
end
end

def run
status, output = execute_with_status('LC_ALL=C subscription-manager release --show')

# If command fails (subscription-manager not installed or system not registered), pass the check
return if status != 0

assert(valid_release?(output), error_message(output))
end

private

def valid_release?(output)
# Valid formats: "Release not set" or "Release: X" where X is a major version without dots
return true if output == 'Release not set'
return true if /^Release:\s+\d+$/.match?(output)

false
end

def extract_release(output)
match = output.match(/^Release:\s+(.+)$/)
match ? match[1] : output
end

def error_message(output)
subman_release = extract_release(output)
"Your system is configured to use RHEL #{subman_release}, but Satellite is only "\
"supported on the latest RHEL. Please unset the release in subscription-manager by "\
"calling `subscription-manager release --unset`."
end
end
1 change: 1 addition & 0 deletions definitions/scenarios/satellite_upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def compose
Checks::SystemRegistration,
Checks::CheckHotfixInstalled,
Checks::CheckTmout,
Checks::CheckSubscriptionManagerRelease,
Checks::CheckUpstreamRepository,
Checks::Container::PodmanLogin, # if downstream, connected, containers used
Checks::Disk::AvailableSpace,
Expand Down
1 change: 1 addition & 0 deletions definitions/scenarios/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def compose
Checks::SystemRegistration,
Checks::CheckHotfixInstalled,
Checks::CheckTmout,
Checks::CheckSubscriptionManagerRelease,
Checks::CheckIpv6Disable,
Checks::CheckUpstreamRepository,
Checks::Container::PodmanLogin, # if downstream, connected, containers used
Expand Down
47 changes: 47 additions & 0 deletions test/definitions/checks/check_subscription_manager_release_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require 'test_helper'

describe Checks::CheckSubscriptionManagerRelease do
include DefinitionsTestHelper

subject { Checks::CheckSubscriptionManagerRelease.new }

before do
assume_feature_present(:satellite)
end

it 'succeeds when release is not set' do
subject.expects(:execute_with_status).with('LC_ALL=C subscription-manager release --show').
returns([
0, 'Release not set'
])
result = run_step(subject)

assert result.success?
end

it 'succeeds when release is set to a major version' do
subject.expects(:execute_with_status).with('LC_ALL=C subscription-manager release --show').
returns([0, 'Release: 9'])
result = run_step(subject)

assert result.success?
end

it 'fails when release is set to a minor version' do
subject.expects(:execute_with_status).with('LC_ALL=C subscription-manager release --show').
returns([0, 'Release: 9.5'])
result = run_step(subject)

assert result.fail?
assert_match(/Your system is configured to use RHEL 9\.5/, result.output)
assert_match(/subscription-manager release --unset/, result.output)
end

it 'succeeds when subscription-manager is not installed or system is not registered' do
subject.expects(:execute_with_status).with('LC_ALL=C subscription-manager release --show').
returns([1, 'This system is not yet registered.'])
result = run_step(subject)

assert result.success?
end
end
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 @@ -23,6 +23,7 @@
Checks::SystemRegistration,
Checks::CheckHotfixInstalled,
Checks::CheckTmout,
Checks::CheckSubscriptionManagerRelease,
Checks::CheckUpstreamRepository,
Checks::Disk::AvailableSpace,
Checks::NonRhPackages,
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 @@ -72,6 +72,7 @@
Checks::SystemRegistration,
Checks::CheckHotfixInstalled,
Checks::CheckTmout,
Checks::CheckSubscriptionManagerRelease,
Checks::CheckUpstreamRepository,
Checks::Disk::AvailableSpace,
Checks::Disk::AvailableSpaceCandlepin,
Expand Down
3 changes: 3 additions & 0 deletions test/definitions/scenarios/update_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
Checks::SystemRegistration,
Checks::CheckHotfixInstalled,
Checks::CheckTmout,
Checks::CheckSubscriptionManagerRelease,
Checks::CheckUpstreamRepository,
Checks::Disk::AvailableSpace,
Checks::Disk::AvailableSpaceCandlepin,
Expand Down Expand Up @@ -165,6 +166,7 @@
Checks::SystemRegistration,
Checks::CheckHotfixInstalled,
Checks::CheckTmout,
Checks::CheckSubscriptionManagerRelease,
Checks::CheckUpstreamRepository,
Checks::Disk::AvailableSpace,
Checks::Disk::AvailableSpaceCandlepin,
Expand Down Expand Up @@ -286,6 +288,7 @@
Checks::SystemRegistration,
Checks::CheckHotfixInstalled,
Checks::CheckTmout,
Checks::CheckSubscriptionManagerRelease,
Checks::CheckUpstreamRepository,
Checks::Disk::AvailableSpace,
Checks::Disk::AvailableSpaceCandlepin,
Expand Down