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

Allow skipping of update phases when they were already executed #931

Merged
merged 2 commits into from
Sep 26, 2024
Merged
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
25 changes: 22 additions & 3 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
Comment on lines +39 to +43
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to 3a2fa00 there is currently no way to re-run a skipped phase tho :(

end

finish_update unless quit?
Expand Down Expand Up @@ -90,12 +94,22 @@ 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.
MESSAGE
@reporter.after_scenario_finishes(scenario)
end
end

private

def rollback_pre_migrations
raise "Unexpected phase #{phase}, expecting pre_migrations" unless phase == :pre_migrations

rollback_needed = scenario(:pre_migrations).steps.any? { |s| s.executed? && s.success? }
rollback_needed = find_scenario(:pre_migrations).steps.any? { |s| s.executed? && s.success? }
Comment on lines -98 to +112
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am amazed this was not noticed

if rollback_needed
@quit = false
# prevent the unnecessary confirmation questions
Expand All @@ -110,7 +124,7 @@ def rollback_pre_migrations
end

def with_non_empty_scenario(phase)
next_scenario = scenario(phase)
next_scenario = find_scenario(phase)
Comment on lines 126 to +127
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was unused, so nobody noticed

unless next_scenario.nil? || next_scenario.steps.empty?
yield next_scenario
end
Expand Down Expand Up @@ -153,6 +167,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
Loading