Class: ForemanMaintain::UpdateRunner
- Includes:
- Concerns::Finders
- Defined in:
- lib/foreman_maintain/update_runner.rb
Constant Summary collapse
- PHASES =
[ :pre_update_checks, :pre_migrations, :migrations, :post_migrations, :post_update_checks, ].freeze
Constants inherited from Runner
Runner::FAILURE_EXIT_CODE, Runner::WARNING_EXIT_CODE
Instance Attribute Summary collapse
-
#phase ⇒ Object
readonly
Returns the value of attribute phase.
Attributes inherited from Runner
Instance Method Summary collapse
- #available? ⇒ Boolean
- #find_scenario(phase) ⇒ Object
- #finish_update ⇒ Object
-
#initialize(reporter, options = {}) ⇒ UpdateRunner
constructor
A new instance of UpdateRunner.
-
#load ⇒ Object
deserializes the state of the run from the storage.
- #run ⇒ Object
- #run_phase(phase) ⇒ Object
- #run_rollback ⇒ Object
-
#save ⇒ Object
serializes the state of the run to storage.
- #storage ⇒ Object
Methods included from Concerns::Finders
#check, #detector, #feature, #find_all_scenarios, #find_procedures, #find_scenarios, #procedure
Methods inherited from Runner
#add_steps, #ask_to_quit, #assumeyes?, #quit?, #rescue?, #run_scenario, #whitelisted_step?
Methods included from Concerns::Logger
Constructor Details
#initialize(reporter, options = {}) ⇒ UpdateRunner
Returns a new instance of UpdateRunner.
15 16 17 18 19 |
# File 'lib/foreman_maintain/update_runner.rb', line 15 def initialize(reporter, = {}) super(reporter, [], ) @scenario_cache = {} self.phase = :pre_update_checks end |
Instance Attribute Details
#phase ⇒ Object
Returns the value of attribute phase.
13 14 15 |
# File 'lib/foreman_maintain/update_runner.rb', line 13 def phase @phase end |
Instance Method Details
#available? ⇒ Boolean
21 22 23 24 25 |
# File 'lib/foreman_maintain/update_runner.rb', line 21 def available? condition = { :tags => [:update_scenario, :pre_update_checks] } matching_scenarios = find_scenarios(condition) !matching_scenarios.empty? end |
#find_scenario(phase) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/foreman_maintain/update_runner.rb', line 27 def find_scenario(phase) return @scenario_cache[phase] if @scenario_cache.key?(phase) condition = { :tags => [:update_scenario, phase] } matching_scenarios = find_scenarios(condition) @scenario_cache[phase] = matching_scenarios.first end |
#finish_update ⇒ Object
52 53 54 55 56 |
# File 'lib/foreman_maintain/update_runner.rb', line 52 def finish_update @finished = true @reporter.hline @reporter.puts("Update finished.\n") end |
#load ⇒ Object
deserializes the state of the run from the storage
73 74 75 76 77 |
# File 'lib/foreman_maintain/update_runner.rb', line 73 def load return unless storage[:serialized] load_from_hash(storage[:serialized]) end |
#run ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/foreman_maintain/update_runner.rb', line 35 def run PHASES.each do |phase| return run_rollback if quit? run_phase(phase) end finish_update unless quit? end |
#run_phase(phase) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/foreman_maintain/update_runner.rb', line 79 def run_phase(phase) scenario = find_scenario(phase) return if scenario.nil? || scenario.steps.empty? confirm_scenario(scenario) return if quit? self.phase = phase run_scenario(scenario) # if we started from the :pre_update_checks, ensure to ask before # continuing with the rest of the update @ask_to_confirm_update = phase == :pre_update_checks end |
#run_rollback ⇒ Object
45 46 47 48 49 50 |
# File 'lib/foreman_maintain/update_runner.rb', line 45 def run_rollback # we only are able to rollback from pre_migrations phase if phase == :pre_migrations rollback_pre_migrations end end |
#save ⇒ Object
serializes the state of the run to storage
63 64 65 66 67 68 69 70 |
# File 'lib/foreman_maintain/update_runner.rb', line 63 def save if @finished storage.delete(:serialized) else storage[:serialized] = to_hash end storage.save end |
#storage ⇒ Object
58 59 60 |
# File 'lib/foreman_maintain/update_runner.rb', line 58 def storage ForemanMaintain.storage("update") end |