Class: ForemanMaintain::Scenario
Defined Under Namespace
Classes: FilteredScenario, PreparationScenario
Constant Summary
Concerns::OsFacts::FALLBACK_OS_RELEASE_FILE, Concerns::OsFacts::OS_RELEASE_FILE
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
#at_least_version?, #current_minor_version, #less_than_version?
included, #run_strategy
#check_max_version, #check_min_version, #command_present?, #directory_empty?, #execute, #execute!, #execute?, #execute_runner, #execute_with_status, #file_exists?, #file_nonzero?, #find_dir_containing_file, #find_package, #find_symlinks, #foreman_plugin_name, #format_shell_args, #hammer_package, #hammer_plugin_name, #hostname, included, #package_manager, #package_version, #packages_action, #parse_csv, #parse_json, #proxy_plugin_name, #repository_manager, #ruby_prefix, #server?, #shellescape, #systemd_installed?, #version
#centos?, #cpu_cores, #deb_major_version, #debian?, #debian_or_ubuntu?, #el8?, #el?, #el_major_version, #el_short_name, #facts, #memory, #os_id, #os_id_like_list, #os_name, #os_release_file, #os_version, #os_version_codename, #os_version_id, #rhel?, #ubuntu?, #ubuntu_major_version
#logger
Constructor Details
#initialize(context_data = {}) ⇒ Scenario
Returns a new instance of Scenario.
83
84
85
86
87
88
|
# File 'lib/foreman_maintain/scenario.rb', line 83
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.
10
11
12
|
# File 'lib/foreman_maintain/scenario.rb', line 10
def context
@context
end
|
#steps ⇒ Object
Returns the value of attribute steps.
10
11
12
|
# File 'lib/foreman_maintain/scenario.rb', line 10
def steps
@steps
end
|
Class Method Details
.inspect ⇒ Object
186
187
188
|
# File 'lib/foreman_maintain/scenario.rb', line 186
def self.inspect
"Scenario Class #{metadata[:description]}<#{name}>"
end
|
.new_from_hash(hash) ⇒ Object
199
200
201
202
203
204
205
206
207
|
# File 'lib/foreman_maintain/scenario.rb', line 199
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
172
173
174
|
# File 'lib/foreman_maintain/scenario.rb', line 172
def add_step(step)
add_steps([step]) unless step.nil?
end
|
#add_step_with_context(definition, extra_params = {}) ⇒ Object
176
177
178
179
180
|
# File 'lib/foreman_maintain/scenario.rb', line 176
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
166
167
168
169
170
|
# File 'lib/foreman_maintain/scenario.rb', line 166
def add_steps(steps)
steps.each do |step|
self.steps << step.ensure_instance
end
end
|
#add_steps_with_context(*definitions) ⇒ Object
182
183
184
|
# File 'lib/foreman_maintain/scenario.rb', line 182
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
159
160
161
162
163
164
|
# File 'lib/foreman_maintain/scenario.rb', line 159
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
91
92
|
# File 'lib/foreman_maintain/scenario.rb', line 91
def compose
end
|
#executed_steps ⇒ Object
106
107
108
|
# File 'lib/foreman_maintain/scenario.rb', line 106
def executed_steps
steps.find_all(&:executed?)
end
|
#failed? ⇒ Boolean
154
155
156
|
# File 'lib/foreman_maintain/scenario.rb', line 154
def failed?
!passed?
end
|
#filter_whitelisted(steps, options) ⇒ Object
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/foreman_maintain/scenario.rb', line 130
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
|
#info_warning? ⇒ Boolean
150
151
152
|
# File 'lib/foreman_maintain/scenario.rb', line 150
def info_warning?
!steps_with_info_warning(:whitelisted => false).empty?
end
|
#inspect ⇒ Object
190
191
192
|
# File 'lib/foreman_maintain/scenario.rb', line 190
def inspect
"#{self.class.metadata[:description]}<#{self.class.name}>"
end
|
#load_step_states(steps_hash) ⇒ Object
209
210
211
212
213
214
215
216
217
218
219
220
|
# File 'lib/foreman_maintain/scenario.rb', line 209
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
141
142
143
144
|
# File 'lib/foreman_maintain/scenario.rb', line 141
def passed?
(steps_with_abort(:whitelisted => false) +
steps_with_error(:whitelisted => false)).empty?
end
|
#preparation_steps ⇒ Object
98
99
100
101
102
103
104
|
# File 'lib/foreman_maintain/scenario.rb', line 98
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
95
96
|
# File 'lib/foreman_maintain/scenario.rb', line 95
def set_context_mapping
end
|
#steps_with_abort(options = {}) ⇒ Object
114
115
116
|
# File 'lib/foreman_maintain/scenario.rb', line 114
def steps_with_abort(options = {})
filter_whitelisted(executed_steps.find_all(&:aborted?), options)
end
|
#steps_with_error(options = {}) ⇒ Object
110
111
112
|
# File 'lib/foreman_maintain/scenario.rb', line 110
def steps_with_error(options = {})
filter_whitelisted(executed_steps.find_all(&:fail?), options)
end
|
#steps_with_info_warning(options = {}) ⇒ Object
122
123
124
|
# File 'lib/foreman_maintain/scenario.rb', line 122
def steps_with_info_warning(options = {})
filter_whitelisted(executed_steps.find_all(&:info_warning?), options)
end
|
#steps_with_skipped(options = {}) ⇒ Object
126
127
128
|
# File 'lib/foreman_maintain/scenario.rb', line 126
def steps_with_skipped(options = {})
filter_whitelisted(executed_steps.find_all(&:skipped?), options)
end
|
#steps_with_warning(options = {}) ⇒ Object
118
119
120
|
# File 'lib/foreman_maintain/scenario.rb', line 118
def steps_with_warning(options = {})
filter_whitelisted(executed_steps.find_all(&:warning?), options)
end
|
#to_hash ⇒ Object
194
195
196
197
|
# File 'lib/foreman_maintain/scenario.rb', line 194
def to_hash
{ :label => label,
:steps => steps.map(&:to_hash) }
end
|
#warning? ⇒ Boolean
146
147
148
|
# File 'lib/foreman_maintain/scenario.rb', line 146
def warning?
!steps_with_warning(:whitelisted => false).empty?
end
|