Skip to content

Commit 5f03685

Browse files
committed
add a check that sub-man release is not set or set to a major version
1 parent 416a170 commit 5f03685

File tree

7 files changed

+95
-0
lines changed

7 files changed

+95
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
class Checks::CheckSubscriptionManagerRelease < ForemanMaintain::Check
2+
metadata do
3+
label :check_subscription_manager_release
4+
description 'Check if subscription-manager release is not set to a minor version'
5+
6+
confine do
7+
feature(:instance).downstream
8+
end
9+
end
10+
11+
def run
12+
status, output = execute_with_status('LC_ALL=C subscription-manager release --show')
13+
14+
# If command fails (subscription-manager not installed or system not registered), pass the check
15+
return if status != 0
16+
17+
assert(valid_release?(output), error_message(output))
18+
end
19+
20+
private
21+
22+
def valid_release?(output)
23+
# Valid formats: "Release not set" or "Release: X" where X is a major version without dots
24+
return true if output == 'Release not set'
25+
return true if /^Release:\s+\d+$/.match?(output)
26+
27+
false
28+
end
29+
30+
def extract_release(output)
31+
match = output.match(/^Release:\s+(.+)$/)
32+
match ? match[1] : output
33+
end
34+
35+
def error_message(output)
36+
subman_release = extract_release(output)
37+
"Your system is configured to use RHEL #{subman_release}, but Satellite is only "\
38+
"supported on the latest RHEL. Please unset the release in subscription-manager by "\
39+
"calling `subscription-manager release --unset`."
40+
end
41+
end

definitions/scenarios/satellite_upgrade.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def compose
3535
Checks::SystemRegistration,
3636
Checks::CheckHotfixInstalled,
3737
Checks::CheckTmout,
38+
Checks::CheckSubscriptionManagerRelease,
3839
Checks::CheckUpstreamRepository,
3940
Checks::Container::PodmanLogin, # if downstream, connected, containers used
4041
Checks::Disk::AvailableSpace,

definitions/scenarios/update.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def compose
3333
Checks::SystemRegistration,
3434
Checks::CheckHotfixInstalled,
3535
Checks::CheckTmout,
36+
Checks::CheckSubscriptionManagerRelease,
3637
Checks::CheckIpv6Disable,
3738
Checks::CheckUpstreamRepository,
3839
Checks::Container::PodmanLogin, # if downstream, connected, containers used
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
require 'test_helper'
2+
3+
describe Checks::CheckSubscriptionManagerRelease do
4+
include DefinitionsTestHelper
5+
6+
subject { Checks::CheckSubscriptionManagerRelease.new }
7+
8+
before do
9+
assume_feature_present(:satellite)
10+
end
11+
12+
it 'succeeds when release is not set' do
13+
subject.expects(:execute_with_status).with('LC_ALL=C subscription-manager release --show').
14+
returns([
15+
0, 'Release not set'
16+
])
17+
result = run_step(subject)
18+
19+
assert result.success?
20+
end
21+
22+
it 'succeeds when release is set to a major version' do
23+
subject.expects(:execute_with_status).with('LC_ALL=C subscription-manager release --show').
24+
returns([0, 'Release: 9'])
25+
result = run_step(subject)
26+
27+
assert result.success?
28+
end
29+
30+
it 'fails when release is set to a minor version' do
31+
subject.expects(:execute_with_status).with('LC_ALL=C subscription-manager release --show').
32+
returns([0, 'Release: 9.5'])
33+
result = run_step(subject)
34+
35+
assert result.fail?
36+
assert_match(/Your system is configured to use RHEL 9\.5/, result.output)
37+
assert_match(/subscription-manager release --unset/, result.output)
38+
end
39+
40+
it 'succeeds when subscription-manager is not installed or system is not registered' do
41+
subject.expects(:execute_with_status).with('LC_ALL=C subscription-manager release --show').
42+
returns([1, 'This system is not yet registered.'])
43+
result = run_step(subject)
44+
45+
assert result.success?
46+
end
47+
end

test/definitions/scenarios/capsule_upgrade_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
Checks::SystemRegistration,
2424
Checks::CheckHotfixInstalled,
2525
Checks::CheckTmout,
26+
Checks::CheckSubscriptionManagerRelease,
2627
Checks::CheckUpstreamRepository,
2728
Checks::Disk::AvailableSpace,
2829
Checks::NonRhPackages,

test/definitions/scenarios/satellite_upgrade_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
Checks::SystemRegistration,
7373
Checks::CheckHotfixInstalled,
7474
Checks::CheckTmout,
75+
Checks::CheckSubscriptionManagerRelease,
7576
Checks::CheckUpstreamRepository,
7677
Checks::Disk::AvailableSpace,
7778
Checks::Disk::AvailableSpaceCandlepin,

test/definitions/scenarios/update_test.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
Checks::SystemRegistration,
4545
Checks::CheckHotfixInstalled,
4646
Checks::CheckTmout,
47+
Checks::CheckSubscriptionManagerRelease,
4748
Checks::CheckUpstreamRepository,
4849
Checks::Disk::AvailableSpace,
4950
Checks::Disk::AvailableSpaceCandlepin,
@@ -165,6 +166,7 @@
165166
Checks::SystemRegistration,
166167
Checks::CheckHotfixInstalled,
167168
Checks::CheckTmout,
169+
Checks::CheckSubscriptionManagerRelease,
168170
Checks::CheckUpstreamRepository,
169171
Checks::Disk::AvailableSpace,
170172
Checks::Disk::AvailableSpaceCandlepin,
@@ -286,6 +288,7 @@
286288
Checks::SystemRegistration,
287289
Checks::CheckHotfixInstalled,
288290
Checks::CheckTmout,
291+
Checks::CheckSubscriptionManagerRelease,
289292
Checks::CheckUpstreamRepository,
290293
Checks::Disk::AvailableSpace,
291294
Checks::Disk::AvailableSpaceCandlepin,

0 commit comments

Comments
 (0)