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 Jun 28, 2024
1 parent 941ed76 commit a5b4464
Show file tree
Hide file tree
Showing 14 changed files with 396 additions and 21 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/foreman/check_corrupted_roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Foreman
class CheckCorruptedRoles < ForemanMaintain::Check
metadata do
label :corrupted_roles
for_feature :foreman_database
for_feature :foreman_server
description 'Check for roles that have filters with multiple resources attached'
tags :pre_upgrade
end
Expand Down
2 changes: 1 addition & 1 deletion definitions/checks/foreman/check_duplicate_permission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Foreman
class CheckDuplicatePermissions < ForemanMaintain::Check
metadata do
label :duplicate_permissions
for_feature :foreman_database
for_feature :foreman_server
description 'Check for duplicate permissions from database'
tags :pre_upgrade
end
Expand Down
2 changes: 1 addition & 1 deletion definitions/checks/foreman/validate_external_db_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ValidateExternalDbVersion < ForemanMaintain::Check
tags :pre_upgrade
label :validate_external_db_version
confine do
feature(:foreman_database) && !feature(:foreman_database).local?
feature(:foreman_server) && !feature(:foreman_database).local?
end
end

Expand Down
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
4 changes: 3 additions & 1 deletion definitions/features/foreman_database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Features::ForemanDatabase < ForemanMaintain::Feature
label :foreman_database

confine do
file_nonzero?(FOREMAN_DB_CONFIG)
feature(:foreman_server)
end
end

Expand Down Expand Up @@ -35,6 +35,8 @@ def services
private

def load_configuration
return {} unless File.exist?(FOREMAN_DB_CONFIG)

config = YAML.load(File.read(FOREMAN_DB_CONFIG))
@configuration = config['production']
@configuration['host'] ||= 'localhost'
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']) || config.empty?
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
4 changes: 4 additions & 0 deletions test/definitions/assume_feature_dependencies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ module AssumeFeatureDependenciesHelper
def assume_satellite_present(&block)
PackageManagerTestHelper.assume_package_exist('satellite')
assume_feature_present(:satellite) unless block_given?
assume_feature_present(:foreman_server) unless block_given?
assume_feature_present(:katello) unless block_given?
assume_feature_present(:candlepin) unless block_given?
assume_feature_present(:foreman_tasks) unless block_given?
assume_feature_present(:satellite, &block)
end
end
1 change: 1 addition & 0 deletions test/definitions/checks/disk_performance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
let(:check_disk_performance) { described_class.new }

before do
ForemanMaintain.stubs(:el?).returns(true)
assume_feature_present(:pulpcore)
check_disk_performance.stubs(:default_dirs).returns(:pulpcore => '/var/lib/pulp')
end
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
168 changes: 168 additions & 0 deletions test/definitions/scenarios/capsule_upgrade_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
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
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)
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 a5b4464

Please sign in to comment.