From b42032f7a63355cade1330c98a762cfa763ad8da Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Thu, 26 Sep 2024 10:57:38 +0200 Subject: [PATCH 1/2] Allow skipping of update phases when they were already executed Fixes: 5c59f9cdd2b7c21174a531fffe8bbdd863029928 --- lib/foreman_maintain/update_runner.rb | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/foreman_maintain/update_runner.rb b/lib/foreman_maintain/update_runner.rb index 5ac7cef11..477ab84be 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,6 +94,16 @@ 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 @@ -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) From 93ae9d803aba382d7fdf8b777dceb6f39dded992 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Thu, 26 Sep 2024 11:19:08 +0200 Subject: [PATCH 2/2] use correct find_scenario method in rollback_pre_migrations Fixes: 5c59f9cdd2b7c21174a531fffe8bbdd863029928 --- lib/foreman_maintain/update_runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/foreman_maintain/update_runner.rb b/lib/foreman_maintain/update_runner.rb index 477ab84be..59de164dc 100644 --- a/lib/foreman_maintain/update_runner.rb +++ b/lib/foreman_maintain/update_runner.rb @@ -109,7 +109,7 @@ def skip_phase(skipped_phase) 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