Class: ForemanMaintain::Scenario
Defined Under Namespace
Classes: FilteredScenario, PreparationScenario
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
check, detector, feature, find_all_scenarios, find_checks, find_procedures, find_scenarios, procedure
included, #run_strategy
#check_max_version, #check_min_version, #command_present?, #create_lv_snapshot, #directory_empty?, #execute, #execute!, #execute?, #execute_runner, #execute_with_status, #file_exists?, #file_nonzero?, #find_dir_containing_file, #find_package, #find_symlinks, #format_shell_args, #get_lv_info, #get_lv_path, #hostname, included, #package_manager, #package_version, #packages_action, #parse_csv, #parse_json, #rpm_version, #server?, #shellescape, #systemd_installed?, #version
#logger
Constructor Details
#initialize(context_data = {}) ⇒ Scenario
Returns a new instance of Scenario.
82
83
84
85
86
87
|
# File 'lib/foreman_maintain/scenario.rb', line 82
def initialize(context_data = {})
@steps = []
@context = Context.new(context_data)
set_context_mapping
compose
end
|
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
9
10
11
|
# File 'lib/foreman_maintain/scenario.rb', line 9
def context
@context
end
|
#steps ⇒ Object
Returns the value of attribute steps.
9
10
11
|
# File 'lib/foreman_maintain/scenario.rb', line 9
def steps
@steps
end
|
Class Method Details
.inspect ⇒ Object
175
176
177
|
# File 'lib/foreman_maintain/scenario.rb', line 175
def self.inspect
"Scenario Class #{metadata[:description]}<#{name}>"
end
|
.new_from_hash(hash) ⇒ Object
188
189
190
191
192
193
194
195
196
|
# File 'lib/foreman_maintain/scenario.rb', line 188
def self.new_from_hash(hash)
scenarios = find_all_scenarios(:label => hash[:label])
unless scenarios.size == 1
raise "Could not find scenario #{hash[:label]}, found #{scenarios.size} scenarios"
end
scenario = scenarios.first
scenario.load_step_states(hash[:steps])
scenario
end
|
Instance Method Details
#add_step(step) ⇒ Object
161
162
163
|
# File 'lib/foreman_maintain/scenario.rb', line 161
def add_step(step)
add_steps([step]) unless step.nil?
end
|
#add_step_with_context(definition, extra_params = {}) ⇒ Object
165
166
167
168
169
|
# File 'lib/foreman_maintain/scenario.rb', line 165
def add_step_with_context(definition, = {})
if definition.present?
add_step(definition.send(:new, context.params_for(definition).merge()))
end
end
|
#add_steps(steps) ⇒ Object
155
156
157
158
159
|
# File 'lib/foreman_maintain/scenario.rb', line 155
def add_steps(steps)
steps.each do |step|
self.steps << step.ensure_instance
end
end
|
#add_steps_with_context(*definitions) ⇒ Object
171
172
173
|
# File 'lib/foreman_maintain/scenario.rb', line 171
def add_steps_with_context(*definitions)
definitions.flatten.each { |definition| add_step_with_context(definition) }
end
|
#before_scenarios ⇒ Object
scenarios to be run before this scenario
148
149
150
151
152
153
|
# File 'lib/foreman_maintain/scenario.rb', line 148
def before_scenarios
scenarios = []
preparation_scenario = PreparationScenario.new(self)
scenarios << [preparation_scenario] unless preparation_scenario.steps.empty?
scenarios
end
|
#compose ⇒ Object
Override to compose steps for the scenario
90
|
# File 'lib/foreman_maintain/scenario.rb', line 90
def compose; end
|
#executed_steps ⇒ Object
103
104
105
|
# File 'lib/foreman_maintain/scenario.rb', line 103
def executed_steps
steps.find_all(&:executed?)
end
|
#failed? ⇒ Boolean
143
144
145
|
# File 'lib/foreman_maintain/scenario.rb', line 143
def failed?
!passed?
end
|
#filter_whitelisted(steps, options) ⇒ Object
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/foreman_maintain/scenario.rb', line 123
def filter_whitelisted(steps, options)
options.validate_options!(:whitelisted)
if options.key?(:whitelisted)
steps.select do |step|
options[:whitelisted] ? step.whitelisted? : !step.whitelisted?
end
else
steps
end
end
|
#inspect ⇒ Object
179
180
181
|
# File 'lib/foreman_maintain/scenario.rb', line 179
def inspect
"#{self.class.metadata[:description]}<#{self.class.name}>"
end
|
#load_step_states(steps_hash) ⇒ Object
198
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/foreman_maintain/scenario.rb', line 198
def load_step_states(steps_hash)
steps = self.steps.dup
steps_hash.each do |step_hash|
until steps.empty?
step = steps.shift
if step.matches_hash?(step_hash)
step.update_from_hash(step_hash)
break
end
end
end
end
|
#passed? ⇒ Boolean
134
135
136
137
|
# File 'lib/foreman_maintain/scenario.rb', line 134
def passed?
(steps_with_abort(:whitelisted => false) +
steps_with_error(:whitelisted => false)).empty?
end
|
#preparation_steps ⇒ Object
95
96
97
98
99
100
101
|
# File 'lib/foreman_maintain/scenario.rb', line 95
def preparation_steps
steps.inject(super.dup) do |results, step|
results.concat(step.preparation_steps)
end.uniq
end
|
#set_context_mapping ⇒ Object
Override to map context for the scenario
93
|
# File 'lib/foreman_maintain/scenario.rb', line 93
def set_context_mapping; end
|
#steps_with_abort(options = {}) ⇒ Object
111
112
113
|
# File 'lib/foreman_maintain/scenario.rb', line 111
def steps_with_abort(options = {})
filter_whitelisted(executed_steps.find_all(&:aborted?), options)
end
|
#steps_with_error(options = {}) ⇒ Object
107
108
109
|
# File 'lib/foreman_maintain/scenario.rb', line 107
def steps_with_error(options = {})
filter_whitelisted(executed_steps.find_all(&:fail?), options)
end
|
#steps_with_skipped(options = {}) ⇒ Object
119
120
121
|
# File 'lib/foreman_maintain/scenario.rb', line 119
def steps_with_skipped(options = {})
filter_whitelisted(executed_steps.find_all(&:skipped?), options)
end
|
#steps_with_warning(options = {}) ⇒ Object
115
116
117
|
# File 'lib/foreman_maintain/scenario.rb', line 115
def steps_with_warning(options = {})
filter_whitelisted(executed_steps.find_all(&:warning?), options)
end
|
#to_hash ⇒ Object
183
184
185
186
|
# File 'lib/foreman_maintain/scenario.rb', line 183
def to_hash
{ :label => label,
:steps => steps.map(&:to_hash) }
end
|
#warning? ⇒ Boolean
139
140
141
|
# File 'lib/foreman_maintain/scenario.rb', line 139
def warning?
!steps_with_warning(:whitelisted => false).empty?
end
|