Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timing to each step #720

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 11 additions & 4 deletions lib/foreman_maintain/reporter/cli_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

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
Loading