Class: ForemanMaintain::Runner
- Inherits:
-
Object
- Object
- ForemanMaintain::Runner
show all
- Includes:
- Concerns::Logger
- Defined in:
- lib/foreman_maintain/runner.rb,
lib/foreman_maintain/runner/execution.rb,
lib/foreman_maintain/runner/stored_execution.rb
Overview
Class responsible for running the scenario
Defined Under Namespace
Classes: Execution, StoredExecution
Constant Summary
collapse
- WARNING_EXIT_CODE =
78
- FAILURE_EXIT_CODE =
1
Instance Attribute Summary collapse
Instance Method Summary
collapse
#logger
Constructor Details
#initialize(reporter, scenarios, options = {}) ⇒ Runner
Returns a new instance of Runner.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/foreman_maintain/runner.rb', line 12
def initialize(reporter, scenarios, options = {})
options.validate_options!(:assumeyes, :whitelist, :force, :rescue_scenario)
@assumeyes = options.fetch(:assumeyes, false)
@whitelist = options.fetch(:whitelist, [])
@force = options.fetch(:force, false)
@rescue_scenario = options.fetch(:rescue_scenario, nil)
@reporter = reporter
@scenarios = Array(scenarios)
@quit = false
@rescue = false
@last_scenario = nil
@last_scenario_continuation_confirmed = false
@exit_code = 0
@procedure_step_counter = 0
end
|
Instance Attribute Details
#exit_code ⇒ Object
Returns the value of attribute exit_code.
5
6
7
|
# File 'lib/foreman_maintain/runner.rb', line 5
def exit_code
@exit_code
end
|
#reporter ⇒ Object
Returns the value of attribute reporter.
5
6
7
|
# File 'lib/foreman_maintain/runner.rb', line 5
def reporter
@reporter
end
|
Instance Method Details
#add_steps(*steps) ⇒ Object
96
97
98
99
100
101
102
|
# File 'lib/foreman_maintain/runner.rb', line 96
def add_steps(*steps)
steps.reverse_each do |step|
@steps_to_run.unshift(step)
end
end
|
#ask_to_quit(exit_code = 1) ⇒ Object
91
92
93
94
|
# File 'lib/foreman_maintain/runner.rb', line 91
def ask_to_quit(exit_code = 1)
@quit = true
@exit_code = exit_code
end
|
#assumeyes? ⇒ Boolean
32
33
34
|
# File 'lib/foreman_maintain/runner.rb', line 32
def assumeyes?
@assumeyes
end
|
#confirm_scenario(scenario) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/foreman_maintain/runner.rb', line 75
def confirm_scenario(scenario)
return if @last_scenario.nil? || @last_scenario_continuation_confirmed
decision = if @last_scenario.steps_with_error(:whitelisted => false).any? ||
@last_scenario.steps_with_abort(:whitelisted => false).any?
:quit
elsif @last_scenario.steps_with_warning(:whitelisted => false).any?
@last_scenario_continuation_confirmed = true
reporter.ask_decision("Continue with [#{scenario.description}]",
run_strategy: scenario.run_strategy)
end
ask_to_quit if [:quit, :no].include?(decision)
decision
end
|
#quit? ⇒ Boolean
28
29
30
|
# File 'lib/foreman_maintain/runner.rb', line 28
def quit?
@quit
end
|
#rescue? ⇒ Boolean
36
37
38
|
# File 'lib/foreman_maintain/runner.rb', line 36
def rescue?
@rescue
end
|
#run ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/foreman_maintain/runner.rb', line 40
def run
@scenarios.each do |scenario|
run_scenario(scenario)
next unless @quit
if @rescue_scenario
@rescue = true
logger.debug('=== Rescue scenario found. Executing ===')
execute_scenario_steps(@rescue_scenario, true)
end
break
end
end
|
#run_scenario(scenario) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/foreman_maintain/runner.rb', line 54
def run_scenario(scenario)
return if scenario.steps.empty?
raise 'The runner is already in quit state' if quit? && !rescue?
confirm_scenario(scenario)
return if quit? && !rescue?
execute_scenario_steps(scenario)
ensure
unless scenario.steps.empty?
@last_scenario = scenario
@last_scenario_continuation_confirmed = false
end
@exit_code = WARNING_EXIT_CODE if scenario.warning?
@exit_code = FAILURE_EXIT_CODE if scenario.failed?
end
|
#storage ⇒ Object
104
105
106
|
# File 'lib/foreman_maintain/runner.rb', line 104
def storage
ForemanMaintain.storage(:default)
end
|
#whitelisted_step?(step) ⇒ Boolean
71
72
73
|
# File 'lib/foreman_maintain/runner.rb', line 71
def whitelisted_step?(step)
@whitelist.include?(step.label_dashed.to_s)
end
|