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
21
|
# 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
@last_scenario_continuation_confirmed = false
@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
84
85
86
87
88
89
90
|
# File 'lib/foreman_maintain/runner.rb', line 84
def add_steps(*steps)
steps.reverse.each do |step|
@steps_to_run.unshift(step)
end
end
|
#ask_to_quit(exit_code = 1) ⇒ Object
79
80
81
82
|
# File 'lib/foreman_maintain/runner.rb', line 79
def ask_to_quit(exit_code = 1)
@quit = true
@exit_code = exit_code
end
|
#assumeyes? ⇒ Boolean
27
28
29
|
# File 'lib/foreman_maintain/runner.rb', line 27
def assumeyes?
@assumeyes
end
|
#confirm_scenario(scenario) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/foreman_maintain/runner.rb', line 64
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}]")
end
ask_to_quit if [:quit, :no].include?(decision)
decision
end
|
#quit? ⇒ Boolean
23
24
25
|
# File 'lib/foreman_maintain/runner.rb', line 23
def quit?
@quit
end
|
#run ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/foreman_maintain/runner.rb', line 31
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) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/foreman_maintain/runner.rb', line 44
def run_scenario(scenario)
return if scenario.steps.empty?
raise 'The runner is already in quit state' if quit?
confirm_scenario(scenario)
return if quit?
execute_scenario_steps(scenario)
ensure
unless scenario.steps.empty?
@last_scenario = scenario
@last_scenario_continuation_confirmed = false
end
@exit_code = 1 if scenario.failed?
end
|
#whitelisted_step?(step) ⇒ Boolean
60
61
62
|
# File 'lib/foreman_maintain/runner.rb', line 60
def whitelisted_step?(step)
@whitelist.include?(step.label_dashed.to_s)
end
|