Skip to content

Commit

Permalink
Allow skipping of update phases when they were already executed
Browse files Browse the repository at this point in the history
Fixes: 5c59f9c
  • Loading branch information
evgeni committed Sep 26, 2024
1 parent 423be1e commit 330b2fb
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/foreman_maintain/update_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ def run
PHASES.each do |phase|
return run_rollback if quit?

run_phase(phase)
if skip?(phase)
skip_phase(phase)
else
run_phase(phase)
end
end

finish_update unless quit?
Expand Down Expand Up @@ -90,6 +94,17 @@ def run_phase(phase)
@ask_to_confirm_update = phase == :pre_update_checks
end

def skip_phase(skipped_phase)
with_non_empty_scenario(skipped_phase) do |scenario|
@reporter.before_scenario_starts(scenario)
@reporter.puts <<~MESSAGE
Skipping #{skipped_phase} phase as it was already run before.
To enforce to run the phase, use `upgrade run --phase #{skipped_phase}`
MESSAGE
@reporter.after_scenario_finishes(scenario)
end
end

private

def rollback_pre_migrations
Expand All @@ -110,7 +125,7 @@ def rollback_pre_migrations
end

def with_non_empty_scenario(phase)
next_scenario = scenario(phase)
next_scenario = find_scenario(phase)
unless next_scenario.nil? || next_scenario.steps.empty?
yield next_scenario
end
Expand Down Expand Up @@ -153,6 +168,11 @@ def confirm_scenario(scenario)
@ask_to_confirm_update = false
end

def skip?(next_phase)
# the next_phase was run before the current phase
PHASES.index(next_phase) < PHASES.index(phase)
end

def phase=(phase)
raise "Unknown phase #{phase}" unless PHASES.include?(phase)

Expand Down

0 comments on commit 330b2fb

Please sign in to comment.