Skip to content

Commit

Permalink
Add option to download package updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Apr 12, 2024
1 parent 237bc69 commit 2c63362
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
36 changes: 29 additions & 7 deletions definitions/scenarios/packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,47 @@ class Update < ForemanMaintain::Scenario
description 'update packages in unlocked session'
param :packages, 'List of packages to Update', :array => true
param :assumeyes, 'Do not ask for confirmation'
param :downloadonly, 'Download and cache packages'
manual_detection
end

# rubocop:disable Metrics/MethodLength
def compose
if Packages.skip_installer_run?(context.get(:packages))
add_step_with_context(Procedures::Packages::Update,
:force => true, :warn_on_errors => true)
else
add_steps_with_context(
Procedures::Packages::UpdateAllConfirmation,
Procedures::Packages::InstallerConfirmation
)
unless context.get(:downloadonly)
add_steps_with_context(
Procedures::Packages::UpdateAllConfirmation,
Procedures::Packages::InstallerConfirmation
)
end

add_step_with_context(Procedures::Packages::UnlockVersions)
add_step_with_context(Procedures::Packages::Update,
:force => true, :warn_on_errors => true)
add_step_with_context(Procedures::Installer::Run)

if context.get(:downloadonly)
add_step_with_context(
Procedures::Packages::Update,
:force => true,
:warn_on_errors => true,
:dnf_options => ['--downloadonly']
)
add_step_with_context(Procedures::Packages::LockVersions)
else
add_step_with_context(
Procedures::Packages::Update,
:force => true,
:warn_on_errors => true
)

add_step_with_context(Procedures::Installer::Run)
end

add_step(Procedures::Packages::LockingStatus)
end
end
# rubocop:enable Metrics/MethodLength

def set_context_mapping
context.map(:packages,
Expand Down
5 changes: 4 additions & 1 deletion lib/foreman_maintain/cli/packages_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ def execute
subcommand 'update', 'Update packages in an unlocked session' do
interactive_option(['assumeyes'])
parameter '[PACKAGES] ...', 'packages to update', :attribute_name => :packages
option '--downloadonly', :flag, 'Downloads and caches package updates only',
:default => false

def execute
run_scenarios_and_exit(
Scenarios::Packages::Update.new(
:packages => packages,
:assumeyes => assumeyes?
:assumeyes => assumeyes?,
:downloadonly => @downloadonly
)
)
end
Expand Down

0 comments on commit 2c63362

Please sign in to comment.