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
Instance Attribute Summary collapse
Instance Method Summary
collapse
#logger
Constructor Details
#initialize(reporter, scenarios, options = {}) ⇒ Runner
Returns a new instance of Runner.
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/foreman_maintain/runner.rb', line 9
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
@last_scenario = nil
@exit_code = 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
79
80
81
82
83
84
85
|
# File 'lib/foreman_maintain/runner.rb', line 79
def add_steps(*steps)
steps.reverse.each do |step|
@steps_to_run.unshift(step)
end
end
|
#ask_to_quit(exit_code = 1) ⇒ Object
74
75
76
77
|
# File 'lib/foreman_maintain/runner.rb', line 74
def ask_to_quit(exit_code = 1)
@quit = true
@exit_code = exit_code
end
|
#assumeyes? ⇒ Boolean
26
27
28
|
# File 'lib/foreman_maintain/runner.rb', line 26
def assumeyes?
@assumeyes
end
|
#confirm_scenario(scenario) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/foreman_maintain/runner.rb', line 61
def confirm_scenario(scenario)
return unless @last_scenario
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?
reporter.ask_decision("Continue with [#{scenario.description}]")
end
ask_to_quit if [:quit, :no].include?(decision)
decision
end
|
#quit? ⇒ Boolean
22
23
24
|
# File 'lib/foreman_maintain/runner.rb', line 22
def quit?
@quit
end
|
#run ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/foreman_maintain/runner.rb', line 30
def run
@scenarios.each do |scenario|
run_scenario(scenario)
next unless @quit
if @rescue_scenario
logger.debug('=== Rescue scenario found. Executing ===')
execute_scenario_steps(@rescue_scenario, true)
end
break
end
end
|
#run_scenario(scenario, confirm = true) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/foreman_maintain/runner.rb', line 42
def run_scenario(scenario, confirm = true)
return if scenario.steps.empty?
raise 'The runner is already in quit state' if quit?
if confirm
confirm_scenario(scenario)
return if quit?
end
execute_scenario_steps(scenario)
ensure
@last_scenario = scenario unless scenario.steps.empty?
@exit_code = 1 if scenario.failed?
end
|
#whitelisted_step?(step) ⇒ Boolean
57
58
59
|
# File 'lib/foreman_maintain/runner.rb', line 57
def whitelisted_step?(step)
@whitelist.include?(step.label_dashed.to_s)
end
|