Skip to content

Commit

Permalink
Fix #37114: Download packages during upgrade before maintenance mode
Browse files Browse the repository at this point in the history
Only clean package cache when downloading packages
Only clean metadata when cleaning dnf cache
  • Loading branch information
ehelms committed Jan 28, 2024
1 parent fa2e3cb commit 1a26b9e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 24 deletions.
8 changes: 6 additions & 2 deletions definitions/procedures/packages/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Update < ForemanMaintain::Procedure

def run
assumeyes_val = @assumeyes.nil? ? assumeyes? : @assumeyes
package_manager.clean_cache(:assumeyes => assumeyes_val)
package_manager.clean_cache(:assumeyes => assumeyes_val) if download_only?
opts = { :assumeyes => assumeyes_val, :dnf_options => @dnf_options }
packages_action(:update, @packages, opts)
rescue ForemanMaintain::Error::ExecutionError => e
Expand All @@ -27,11 +27,15 @@ def necessary?
end

def description
if @dnf_options.include?('--downloadonly')
if download_only?
"Download package(s) #{@packages.join(', ')}"
else
"Update package(s) #{@packages.join(', ')}"
end
end

def download_only?
@dnf_options.include?('--downloadonly')
end
end
end
11 changes: 6 additions & 5 deletions definitions/scenarios/upgrade_to_capsule_6_16.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class PreMigrations < Abstract
end

def compose
add_step(Procedures::Repositories::Setup.new(:version => '6.16'))
modules_to_enable = ["satellite-capsule:#{el_short_name}"]
add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable))
add_step(Procedures::Packages::Update.new(:assumeyes => true,
:dnf_options => ['--downloadonly']))

add_steps(find_procedures(:pre_migrations))
end
end
Expand All @@ -53,11 +59,6 @@ def set_context_mapping
end

def compose
add_step(Procedures::Repositories::Setup.new(:version => '6.16'))
modules_to_enable = ["satellite-capsule:#{el_short_name}"]
add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable))
add_step(Procedures::Packages::Update.new(:assumeyes => true,
:dnf_options => ['--downloadonly']))
add_step(Procedures::Service::Stop.new)
add_step(Procedures::Packages::Update.new(:assumeyes => true))
add_step_with_context(Procedures::Installer::Upgrade)
Expand Down
10 changes: 5 additions & 5 deletions definitions/scenarios/upgrade_to_capsule_6_16_z.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class PreMigrations < Abstract
end

def compose
add_step(Procedures::Repositories::Setup.new(:version => '6.16'))
modules_to_enable = ["satellite-capsule:#{el_short_name}"]
add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable))
add_step(Procedures::Packages::Update.new(:assumeyes => true,
:dnf_options => ['--downloadonly']))
add_steps(find_procedures(:pre_migrations))
end
end
Expand All @@ -53,11 +58,6 @@ def set_context_mapping
end

def compose
add_step(Procedures::Repositories::Setup.new(:version => '6.16'))
modules_to_enable = ["satellite-capsule:#{el_short_name}"]
add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable))
add_step(Procedures::Packages::Update.new(:assumeyes => true,
:dnf_options => ['--downloadonly']))
add_step(Procedures::Service::Stop.new)
add_step(Procedures::Packages::Update.new(:assumeyes => true))
add_step_with_context(Procedures::Installer::Upgrade)
Expand Down
10 changes: 5 additions & 5 deletions definitions/scenarios/upgrade_to_satellite_6_16.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class PreMigrations < Abstract
end

def compose
add_step(Procedures::Repositories::Setup.new(:version => '6.16'))
modules_to_enable = ["satellite:#{el_short_name}"]
add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable))
add_step(Procedures::Packages::Update.new(:assumeyes => true,
:dnf_options => ['--downloadonly']))
add_steps(find_procedures(:pre_migrations))
end
end
Expand All @@ -54,11 +59,6 @@ def set_context_mapping
end

def compose
add_step(Procedures::Repositories::Setup.new(:version => '6.16'))
modules_to_enable = ["satellite:#{el_short_name}"]
add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable))
add_step(Procedures::Packages::Update.new(:assumeyes => true,
:dnf_options => ['--downloadonly']))
add_step(Procedures::Service::Stop.new)
add_step(Procedures::Packages::Update.new(:assumeyes => true))
add_step_with_context(Procedures::Installer::Upgrade)
Expand Down
10 changes: 5 additions & 5 deletions definitions/scenarios/upgrade_to_satellite_6_16_z.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class PreMigrations < Abstract
end

def compose
add_step(Procedures::Repositories::Setup.new(:version => '6.16'))
modules_to_enable = ["satellite:#{el_short_name}"]
add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable))
add_step(Procedures::Packages::Update.new(:assumeyes => true,
:dnf_options => ['--downloadonly']))
add_steps(find_procedures(:pre_migrations))
end
end
Expand All @@ -53,11 +58,6 @@ def set_context_mapping
end

def compose
add_step(Procedures::Repositories::Setup.new(:version => '6.16'))
modules_to_enable = ["satellite:#{el_short_name}"]
add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable))
add_step(Procedures::Packages::Update.new(:assumeyes => true,
:dnf_options => ['--downloadonly']))
add_step(Procedures::Service::Stop.new)
add_step(Procedures::Packages::Update.new(:assumeyes => true))
add_step_with_context(Procedures::Installer::Upgrade)
Expand Down
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 @@ -92,7 +92,7 @@ def list_installed_packages(queryformat = '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}
end

def clean_cache(assumeyes: false)
dnf_action('clean', 'all', :assumeyes => assumeyes)
dnf_action('clean', 'metadata', :assumeyes => assumeyes)
end

def module_enabled?(name)
Expand Down
2 changes: 1 addition & 1 deletion test/lib/package_manager/dnf_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def with_lock_config(protector_enabled: false)
describe 'clean_cache' do
it 'invokes dnf to clean cache' do
expect_execute!(
'dnf -y --disableplugin=foreman-protector clean all',
'dnf -y --disableplugin=foreman-protector clean metadata',
:interactive => false
)
subject.clean_cache(:assumeyes => true)
Expand Down

0 comments on commit 1a26b9e

Please sign in to comment.