Skip to content

Commit

Permalink
Add tests for upgrade scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Jul 1, 2024
1 parent 62503da commit 7a257d5
Show file tree
Hide file tree
Showing 14 changed files with 820 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,6 @@ Style/StderrPuts:

Metrics/ParameterLists:
Max: 6

Style/TrailingCommaInArguments:
Enabled: false
2 changes: 1 addition & 1 deletion definitions/checks/system_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Checks::SystemRegistration < ForemanMaintain::Check
tags :default

confine do
file_exists?('/etc/rhsm/rhsm.conf') && feature(:instance).downstream
feature(:instance).downstream
end
end

Expand Down
7 changes: 6 additions & 1 deletion definitions/features/foreman_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ def services
private

def load_configuration
config = YAML.load(File.read(FOREMAN_DB_CONFIG))
config = if File.exist?('/etc/foreman/database.yml')
YAML.load(File.read(FOREMAN_DB_CONFIG))
else
{ 'production' => {} }
end

@configuration = config['production']
@configuration['host'] ||= 'localhost'
@configuration
Expand Down
4 changes: 3 additions & 1 deletion definitions/scenarios/foreman_upgrade.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Scenarios::ForemanUpgrade
module Scenarios::Foreman
class Abstract < ForemanMaintain::Scenario
def self.upgrade_metadata(&block)
metadata do
Expand Down Expand Up @@ -38,6 +38,7 @@ def compose
Checks::CheckUpstreamRepository,
Checks::Disk::AvailableSpace,
Checks::Disk::AvailableSpaceCandlepin, # if candlepin
Checks::Disk::AvailableSpacePostgresql13,
Checks::Foreman::ValidateExternalDbVersion, # if external database
Checks::Foreman::CheckCorruptedRoles,
Checks::Foreman::CheckDuplicatePermissions,
Expand All @@ -50,6 +51,7 @@ def compose
Checks::NonRhPackages,
Checks::PackageManager::Dnf::ValidateDnfConfig,
Checks::Repositories::CheckNonRhRepository,
Checks::CheckOrganizationContentAccessMode,
Checks::Repositories::Validate
)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/foreman_maintain/concerns/base_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def configuration
end

def local?(config = configuration)
['localhost', '127.0.0.1', `hostname`.strip].include? config['host']
['localhost', '127.0.0.1', `hostname`.strip].include?(config['host'])
end

def query(sql, config = configuration)
Expand Down
1 change: 1 addition & 0 deletions lib/foreman_maintain/detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def refresh
@all_features_scanned = false
@available_checks = nil
@available_scenarios = nil
@available_procedures = nil
@scenarios ||= Scenario.all_sub_classes.select(&:autodetect?)
end

Expand Down
25 changes: 24 additions & 1 deletion test/definitions/assume_feature_dependencies_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
module AssumeFeatureDependenciesHelper
def assume_satellite_present(&block)
PackageManagerTestHelper.assume_package_exist('satellite')
assume_feature_present(:satellite) unless block_given?
unless block_given?
assume_feature_present(:satellite)
assume_feature_present(:foreman_server)
assume_feature_present(:katello)
assume_feature_present(:candlepin)
assume_feature_present(:foreman_tasks)
assume_feature_present(:foreman_database)
end
assume_feature_present(:satellite, &block)
end

def assume_foreman_present
PackageManagerTestHelper.assume_package_exist('foreman')
assume_feature_present(:foreman_install)
assume_feature_present(:foreman_server)
assume_feature_present(:foreman_database)
end

def assume_katello_present
PackageManagerTestHelper.assume_package_exist('katello')
assume_feature_present(:foreman_server)
assume_feature_present(:katello)
assume_feature_present(:candlepin)
assume_feature_present(:foreman_tasks)
assume_feature_present(:foreman_database)
end
end
4 changes: 2 additions & 2 deletions test/definitions/checks/disk_performance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
end

it 'executes successfully for disk with minimal speed' do
assume_satellite_present
assume_feature_present(:satellite)

check_disk_performance.stubs(:check_only_single_device?).returns(true)

Expand All @@ -37,7 +37,7 @@
end

it 'print warning if disk speed does not meet minimal requirement' do
assume_satellite_present
assume_feature_present(:satellite)

slow_speed = 59
err_msg = 'Slow disk'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
before do
assume_feature_present(:instance, :postgresql_local? => true)
assume_feature_present(:foreman_database, :configuration => {})
Features::Service.any_instance.expects(:handle_services)
end

it 'reindexes all DBs if DB is local' do
Expand Down
189 changes: 189 additions & 0 deletions test/definitions/scenarios/capsule_upgrade_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
require 'test_helper'

describe "capsule upgrade scenarios" do
include DefinitionsTestHelper

before(:each) do
assume_feature_present(:capsule)
ForemanMaintain.config.stubs(:manage_crond).returns(true)
end

describe Scenarios::Satellite::PreUpgradeCheck do
let(:scenario) do
Scenarios::Satellite::PreUpgradeCheck.new
end

it 'composes all steps for Satellite on EL8' do
Scenarios::Satellite::PreUpgradeCheck.any_instance.stubs(:el_major_version).returns(8)

assert_scenario_has_steps(
scenario,
Checks::ServerPing,
Checks::ServicesUp,
Checks::SystemRegistration,
Checks::CheckHotfixInstalled,
Checks::CheckTmout,
Checks::CheckUpstreamRepository,
Checks::Disk::AvailableSpace,
Checks::NonRhPackages,
Checks::PackageManager::Dnf::ValidateDnfConfig,
Checks::Repositories::CheckNonRhRepository,
Checks::CheckIpv6Disable,
Checks::Disk::AvailableSpacePostgresql13,
Checks::CheckOrganizationContentAccessMode,
Checks::Repositories::Validate,
)
end

it 'composes all steps for Satellite on EL9' do
Scenarios::Satellite::PreUpgradeCheck.any_instance.stubs(:el_major_version).returns(9)

assert_scenario_has_steps(
scenario,
Checks::ServerPing,
Checks::ServicesUp,
Checks::SystemRegistration,
Checks::CheckHotfixInstalled,
Checks::CheckTmout,
Checks::CheckUpstreamRepository,
Checks::Disk::AvailableSpace,
Checks::NonRhPackages,
Checks::PackageManager::Dnf::ValidateDnfConfig,
Checks::Repositories::CheckNonRhRepository,
Checks::CheckIpv6Disable,
Checks::Disk::AvailableSpacePostgresql13,
Checks::CheckOrganizationContentAccessMode,
Checks::Repositories::Validate,
)
end
end

describe Scenarios::Satellite::PreMigrations do
let(:scenario) do
Scenarios::Satellite::PreMigrations.new
end

it 'composes all steps for Satellite on EL8' do
Scenarios::Satellite::PreMigrations.any_instance.stubs(:el_major_version).returns(8)

assert_scenario_has_steps(
scenario,
Procedures::MaintenanceMode::EnableMaintenanceMode,
Procedures::Crond::Stop,
)
end

it 'composes all steps for Satellite on EL9' do
Scenarios::Satellite::PreMigrations.any_instance.stubs(:el_major_version).returns(9)

assert_scenario_has_steps(
scenario,
Procedures::MaintenanceMode::EnableMaintenanceMode,
Procedures::Crond::Stop,
)
end
end

describe Scenarios::Satellite::Migrations do
let(:scenario) do
Scenarios::Satellite::Migrations.new
end

it 'composes all steps for Capsule on EL8' do
Scenarios::Satellite::Migrations.any_instance.stubs(:el_major_version).returns(8)
assert_scenario_has_step(scenario, Procedures::Packages::EnableModules) do |step|
assert_equal(['satellite-capsule:el8'], step.options['module_names'])
end

assert_scenario_has_steps(
scenario,
Procedures::Repositories::Setup,
Procedures::Packages::SwitchModules,
Procedures::Packages::EnableModules,
Procedures::Packages::Update,
Procedures::Service::Stop,
Procedures::Packages::Update,
Procedures::Installer::Run,
)
end

it 'composes all steps for Capsule on EL9' do
Scenarios::Satellite::Migrations.any_instance.stubs(:el_major_version).returns(9)
refute_scenario_has_step(scenario, Procedures::Packages::EnableModules)
refute_scenario_has_step(scenario, Procedures::Packages::SwitchModules)

assert_scenario_has_steps(
scenario,
Procedures::Repositories::Setup,
Procedures::Packages::Update,
Procedures::Service::Stop,
Procedures::Packages::Update,
Procedures::Installer::Run,
)
end
end

describe Scenarios::Satellite::PostMigrations do
let(:scenario) do
Scenarios::Satellite::PostMigrations.new
end

it 'composes all steps for Satellite on EL8' do
Scenarios::Satellite::PostMigrations.any_instance.stubs(:el_major_version).returns(8)

assert_scenario_has_steps(
scenario,
Procedures::RefreshFeatures,
Procedures::Service::Start,
Procedures::Crond::Start,
Procedures::MaintenanceMode::DisableMaintenanceMode,
)
end

it 'composes all steps for Satellite on EL9' do
Scenarios::Satellite::PostMigrations.any_instance.stubs(:el_major_version).returns(9)

assert_scenario_has_steps(
scenario,
Procedures::RefreshFeatures,
Procedures::Service::Start,
Procedures::Crond::Start,
Procedures::MaintenanceMode::DisableMaintenanceMode,
)
end
end

describe Scenarios::Satellite::PostUpgradeChecks do
let(:scenario) do
Scenarios::Satellite::PostUpgradeChecks.new
end

it 'composes all steps for Satellite on EL8' do
Scenarios::Satellite::PostUpgradeChecks.any_instance.stubs(:el_major_version).returns(8)

assert_scenario_has_steps(
scenario,
Checks::ServerPing,
Checks::ServicesUp,
Checks::SystemRegistration,
Procedures::Packages::CheckForReboot,
Procedures::Pulpcore::ContainerHandleImageMetadata,
Procedures::Repositories::IndexKatelloRepositoriesContainerMetatdata,
)
end

it 'composes all steps for Satellite on EL9' do
Scenarios::Satellite::PostUpgradeChecks.any_instance.stubs(:el_major_version).returns(9)

assert_scenario_has_steps(
scenario,
Checks::ServerPing,
Checks::ServicesUp,
Checks::SystemRegistration,
Procedures::Packages::CheckForReboot,
Procedures::Pulpcore::ContainerHandleImageMetadata,
Procedures::Repositories::IndexKatelloRepositoriesContainerMetatdata,
)
end
end
end
Loading

0 comments on commit 7a257d5

Please sign in to comment.