Skip to content

Commit

Permalink
Issue warning if reboot needed but exit with success
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ehelms committed Dec 14, 2023
1 parent b88004a commit acb2719
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion definitions/procedures/packages/check_for_reboot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/foreman_maintain/executable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/foreman_maintain/reporter/cli_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions lib/foreman_maintain/runner/execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions lib/foreman_maintain/scenario.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit acb2719

Please sign in to comment.