Skip to content

Commit

Permalink
Combine Foreman and Katello upgrade scenarios into one
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Apr 30, 2024
1 parent 3eaaeab commit 14ef45b
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 189 deletions.
2 changes: 1 addition & 1 deletion definitions/features/foreman_install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Features::ForemanInstall < ForemanMaintain::Feature
label :foreman_install

confine do
!feature(:instance).downstream && !feature(:katello) && feature(:foreman_server)
!feature(:instance).downstream && feature(:foreman_server)
end
end
end
145 changes: 145 additions & 0 deletions definitions/scenarios/foreman_upgrade.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
module Scenarios::ForemanUpgrade
class Abstract < ForemanMaintain::Scenario
def self.upgrade_metadata(&block)
metadata do
tags :upgrade_scenario
confine do
feature(:foreman_install)
end
instance_eval(&block)
end
end

def target_version
'nightly'
end
end

class PreUpgradeCheck < Abstract
upgrade_metadata do
description 'Checks before upgrading'
tags :pre_upgrade_checks
run_strategy :fail_slow
end

# rubocop:disable Metrics/MethodLength
def compose
add_steps(
Checks::Foreman::FactsNames, # if Foreman database present
Checks::ForemanProxy::CheckTftpStorage, # if Satellite with foreman-proxy+tftp
Checks::ForemanProxy::VerifyDhcpConfigSyntax, # if foreman-proxy+dhcp-isc
Checks::ForemanTasks::NotPaused, # if foreman-tasks present
Checks::Puppet::VerifyNoEmptyCacertRequests, # if puppetserver
Checks::ServerPing,
Checks::ServicesUp,
Checks::SystemRegistration,
Checks::CheckHotfixInstalled,
Checks::CheckTmout,
Checks::CheckUpstreamRepository,
Checks::Disk::AvailableSpace,
Checks::Disk::AvailableSpaceCandlepin, # if candlepin
Checks::Foreman::ValidateExternalDbVersion, # if external database
Checks::Foreman::CheckCorruptedRoles,
Checks::Foreman::CheckDuplicatePermissions,
Checks::Foreman::TuningRequirements, # if katello present
Checks::ForemanOpenscap::InvalidReportAssociations, # if foreman-openscap
Checks::ForemanTasks::Invalid::CheckOld, # if foreman-tasks
Checks::ForemanTasks::Invalid::CheckPendingState, # if foreman-tasks
Checks::ForemanTasks::Invalid::CheckPlanningState, # if foreman-tasks
Checks::ForemanTasks::NotRunning, # if foreman-tasks
Checks::NonRhPackages,
Checks::PackageManager::Dnf::ValidateDnfConfig,
Checks::Repositories::CheckNonRhRepository,
Checks::Repositories::Validate
)
end
# rubocop:enable Metrics/MethodLength
end

class PreMigrations < Abstract
upgrade_metadata do
description 'Procedures before upgrading'
tags :pre_migrations
end

def compose
add_steps(
Procedures::Packages::Update.new(
:assumeyes => true,
:dnf_options => ['--downloadonly']
),
Procedures::MaintenanceMode::EnableMaintenanceMode,
Procedures::Crond::Stop,
Procedures::SyncPlans::Disable
)
end
end

class Migrations < Abstract
upgrade_metadata do
description 'Upgrade steps'
tags :migrations
run_strategy :fail_fast
end

def set_context_mapping
context.map(:assumeyes, Procedures::Installer::Run => :assumeyes)
end

def compose
add_step(Procedures::Repositories::Setup.new(:version => 'nightly'))
if el8?
modules_to_switch = ['postgresql:13']
add_step(Procedures::Packages::SwitchModules.new(:module_names => modules_to_switch))
end

add_step(Procedures::Packages::Update.new(
:assumeyes => true,
:download_only => true
))
add_step(Procedures::Service::Stop.new)
add_step(Procedures::Packages::Update.new(:assumeyes => true, :clean_cache => false))

add_step_with_context(Procedures::Installer::Run)
end
end

class PostMigrations < Abstract
upgrade_metadata do
description 'Post upgrade procedures'
tags :post_migrations
end

def compose
add_steps(
Procedures::RefreshFeatures,
Procedures::Service::Start,
Procedures::Crond::Start,
Procedures::SyncPlans::Enable,
Procedures::MaintenanceMode::DisableMaintenanceMode
)
end
end

class PostUpgradeChecks < Abstract
upgrade_metadata do
description 'Checks after upgrading'
tags :post_upgrade_checks
run_strategy :fail_slow
end

def compose
add_steps(
Checks::Foreman::FactsNames, # if Foreman database present
Checks::ForemanProxy::CheckTftpStorage, # if Satellite with foreman-proxy+tftp
Checks::ForemanProxy::VerifyDhcpConfigSyntax, # if foreman-proxy+dhcp-isc
Checks::ForemanTasks::NotPaused, # if foreman-tasks present
Checks::Puppet::VerifyNoEmptyCacertRequests, # if puppetserver
Checks::ServerPing,
Checks::ServicesUp,
Checks::SystemRegistration,
Procedures::Packages::CheckForReboot
)
end
end
end
91 changes: 0 additions & 91 deletions definitions/scenarios/upgrade_to_foreman_nightly.rb

This file was deleted.

96 changes: 0 additions & 96 deletions definitions/scenarios/upgrade_to_katello_nightly.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/foreman_maintain/package_manager/dnf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def dnf_action(action, packages, with_status: false, assumeyes: false, dnf_optio
packages = [packages].flatten(1)

dnf_options << '-y' if assumeyes
dnf_topions << '--downloadonly' if download_only
dnf_options << '--downloadonly' if download_only
dnf_options << '--disableplugin=foreman-protector'

command = ['dnf', dnf_options.join(' '), action]
Expand Down

0 comments on commit 14ef45b

Please sign in to comment.