diff --git a/lib/foreman_maintain/update_runner.rb b/lib/foreman_maintain/update_runner.rb index 5ac7cef11..59de164dc 100644 --- a/lib/foreman_maintain/update_runner.rb +++ b/lib/foreman_maintain/update_runner.rb @@ -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? @@ -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? } if rollback_needed @quit = false # prevent the unnecessary confirmation questions @@ -110,7 +124,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 @@ -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)