Class: ForemanMaintain::UpdateRunner
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
Attributes inherited from Runner
#exit_code, #reporter
Instance Method Summary
collapse
#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?
#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, options = {})
super(reporter, [], options)
@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
56
57
58
59
60
|
# File 'lib/foreman_maintain/update_runner.rb', line 56
def finish_update
@finished = true
@reporter.hline
@reporter.puts("Update finished.\n")
end
|
#load ⇒ Object
deserializes the state of the run from the storage
77
78
79
80
81
|
# File 'lib/foreman_maintain/update_runner.rb', line 77
def load
return unless storage[:serialized]
load_from_hash(storage[:serialized])
end
|
#run ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/foreman_maintain/update_runner.rb', line 35
def run
PHASES.each do |phase|
return run_rollback if quit?
if skip?(phase)
skip_phase(phase)
else
run_phase(phase)
end
end
finish_update unless quit?
end
|
#run_phase(phase) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/foreman_maintain/update_runner.rb', line 83
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)
@ask_to_confirm_update = phase == :pre_update_checks
end
|
#run_rollback ⇒ Object
49
50
51
52
53
54
|
# File 'lib/foreman_maintain/update_runner.rb', line 49
def run_rollback
if phase == :pre_migrations
rollback_pre_migrations
end
end
|
#save ⇒ Object
serializes the state of the run to storage
67
68
69
70
71
72
73
74
|
# File 'lib/foreman_maintain/update_runner.rb', line 67
def save
if @finished
storage.delete(:serialized)
else
storage[:serialized] = to_hash
end
storage.save
end
|
#skip_phase(skipped_phase) ⇒ Object
97
98
99
100
101
102
103
104
105
|
# File 'lib/foreman_maintain/update_runner.rb', line 97
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
|
#storage ⇒ Object
62
63
64
|
# File 'lib/foreman_maintain/update_runner.rb', line 62
def storage
ForemanMaintain.storage("update")
end
|