From acb2719cadcadbe3a56e75d1ab8a967e3662f8ec Mon Sep 17 00:00:00 2001 From: "Eric D. Helms" Date: Fri, 8 Dec 2023 08:56:21 -0500 Subject: [PATCH] Issue warning if reboot needed but exit with success When a reboot is required we want to bring attention to it via a warning but we do not want to fail the upgrade. This introduces a new option to issue a informational warning that still exits 0. --- definitions/procedures/packages/check_for_reboot.rb | 2 +- lib/foreman_maintain/executable.rb | 6 +++++- lib/foreman_maintain/reporter/cli_reporter.rb | 3 ++- lib/foreman_maintain/runner/execution.rb | 4 ++++ lib/foreman_maintain/scenario.rb | 8 ++++++++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/definitions/procedures/packages/check_for_reboot.rb b/definitions/procedures/packages/check_for_reboot.rb index 22f133358..abff203b4 100644 --- a/definitions/procedures/packages/check_for_reboot.rb +++ b/definitions/procedures/packages/check_for_reboot.rb @@ -7,7 +7,7 @@ class CheckForReboot < ForemanMaintain::Procedure def run status, output = execute_with_status('dnf needs-restarting --reboothint') if status == 1 - set_status(:warning, output) + set_info_warn(output) else set_status(:success, output) end diff --git a/lib/foreman_maintain/executable.rb b/lib/foreman_maintain/executable.rb index e26b9a77f..181fcc082 100644 --- a/lib/foreman_maintain/executable.rb +++ b/lib/foreman_maintain/executable.rb @@ -5,7 +5,7 @@ class Executable attr_reader :options def_delegators :execution, - :success?, :skipped?, :fail?, :aborted?, :warning?, :output, + :success?, :skipped?, :fail?, :aborted?, :warning?, :info_warning?, :output, :assumeyes?, :whitelisted?, :ask_decision, :execution, :puts, :print, :with_spinner, :ask, :storage @@ -91,6 +91,10 @@ def set_warn(message) set_status(:warning, message) end + def set_info_warn(message) + set_status(:info_warning, message) + end + def set_skip(message) set_status(:skipped, message) end diff --git a/lib/foreman_maintain/reporter/cli_reporter.rb b/lib/foreman_maintain/reporter/cli_reporter.rb index de5efdec8..681fc730a 100644 --- a/lib/foreman_maintain/reporter/cli_reporter.rb +++ b/lib/foreman_maintain/reporter/cli_reporter.rb @@ -276,7 +276,8 @@ def status_label(status) :running => { :label => '[RUNNING]', :color => :blue }, :skipped => { :label => '[SKIPPED]', :color => :yellow }, :already_run => { :label => '[ALREADY RUN]', :color => :yellow }, - :warning => { :label => '[WARNING]', :color => :yellow } } + :warning => { :label => '[WARNING]', :color => :yellow }, + :info_warning => { :label => '[WARNING]', :color => :yellow } } properties = mapping[status] if @plaintext properties[:label] diff --git a/lib/foreman_maintain/runner/execution.rb b/lib/foreman_maintain/runner/execution.rb index a1993fce9..fbccaebeb 100644 --- a/lib/foreman_maintain/runner/execution.rb +++ b/lib/foreman_maintain/runner/execution.rb @@ -63,6 +63,10 @@ def warning? @status == :warning end + def info_warning? + @status == :info_warning + end + # yaml storage to preserve key/value pairs between runs. def storage @storage || ForemanMaintain.storage(:default) diff --git a/lib/foreman_maintain/scenario.rb b/lib/foreman_maintain/scenario.rb index 5336a03ee..89501fd27 100644 --- a/lib/foreman_maintain/scenario.rb +++ b/lib/foreman_maintain/scenario.rb @@ -119,6 +119,10 @@ def steps_with_warning(options = {}) filter_whitelisted(executed_steps.find_all(&:warning?), options) end + def steps_with_info_warning(options = {}) + filter_whitelisted(executed_steps.find_all(&:info_warning?), options) + end + def steps_with_skipped(options = {}) filter_whitelisted(executed_steps.find_all(&:skipped?), options) end @@ -143,6 +147,10 @@ def warning? !steps_with_warning(:whitelisted => false).empty? end + def info_warning? + !steps_with_info_warning(:whitelisted => false).empty? + end + def failed? !passed? end