diff --git a/definitions/procedures/packages/update.rb b/definitions/procedures/packages/update.rb index 8e7531507..0f0c4ec32 100644 --- a/definitions/procedures/packages/update.rb +++ b/definitions/procedures/packages/update.rb @@ -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 @@ -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 diff --git a/definitions/scenarios/upgrade_to_capsule_6_16.rb b/definitions/scenarios/upgrade_to_capsule_6_16.rb index 1aaa13aff..b204f3311 100644 --- a/definitions/scenarios/upgrade_to_capsule_6_16.rb +++ b/definitions/scenarios/upgrade_to_capsule_6_16.rb @@ -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 @@ -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) diff --git a/definitions/scenarios/upgrade_to_capsule_6_16_z.rb b/definitions/scenarios/upgrade_to_capsule_6_16_z.rb index 292b15bb6..4cc0ec319 100644 --- a/definitions/scenarios/upgrade_to_capsule_6_16_z.rb +++ b/definitions/scenarios/upgrade_to_capsule_6_16_z.rb @@ -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 @@ -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) diff --git a/definitions/scenarios/upgrade_to_satellite_6_16.rb b/definitions/scenarios/upgrade_to_satellite_6_16.rb index f247d9859..e034aa5ba 100644 --- a/definitions/scenarios/upgrade_to_satellite_6_16.rb +++ b/definitions/scenarios/upgrade_to_satellite_6_16.rb @@ -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 @@ -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) diff --git a/definitions/scenarios/upgrade_to_satellite_6_16_z.rb b/definitions/scenarios/upgrade_to_satellite_6_16_z.rb index a972c1617..c3c033123 100644 --- a/definitions/scenarios/upgrade_to_satellite_6_16_z.rb +++ b/definitions/scenarios/upgrade_to_satellite_6_16_z.rb @@ -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 @@ -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) diff --git a/lib/foreman_maintain/package_manager/dnf.rb b/lib/foreman_maintain/package_manager/dnf.rb index 889a5841a..8695f06fc 100644 --- a/lib/foreman_maintain/package_manager/dnf.rb +++ b/lib/foreman_maintain/package_manager/dnf.rb @@ -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) diff --git a/lib/foreman_maintain/reporter/cli_reporter.rb b/lib/foreman_maintain/reporter/cli_reporter.rb index 681fc730a..01e2acf33 100644 --- a/lib/foreman_maintain/reporter/cli_reporter.rb +++ b/lib/foreman_maintain/reporter/cli_reporter.rb @@ -150,7 +150,12 @@ def with_spinner(message) end def after_execution_finishes(execution) - puts_status(execution.status) + if execution.started_at + puts_status(execution.status, execution.ended_at - execution.started_at) + else + puts_status(execution.status) + end + puts(execution.output) unless execution.output.empty? puts(already_run_msg) if execution.status == :already_run hline @@ -258,14 +263,16 @@ def execution_info(execution, text) "#{prefix} #{text}" end - def puts_status(status) - label_offset = 10 + def puts_status(status, runtime = nil) + label_offset = 12 padding = @max_length - @last_line.to_s.size - label_offset if padding < 0 new_line_if_needed padding = @max_length - label_offset end - @stdout.print(' ' * padding + status_label(status)) + output = ' ' * padding + status_label(status) + output += runtime ? " [#{runtime.truncate(2).to_s}]" : '' + @stdout.print(output) @new_line_next_time = true end diff --git a/test/lib/package_manager/dnf_test.rb b/test/lib/package_manager/dnf_test.rb index d2b5cb068..425ce2001 100644 --- a/test/lib/package_manager/dnf_test.rb +++ b/test/lib/package_manager/dnf_test.rb @@ -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)