Class: ChefDK::Command::Verify
- Inherits:
-
Base
- Object
- Base
- ChefDK::Command::Verify
show all
- Defined in:
- lib/chef-dk/command/verify.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#needs_help?, #needs_version?, #run_with_default_options
Methods included from Helpers
#err, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_embedded_bin_dir, #stderr, #stdout, #system_command
Constructor Details
#initialize ⇒ Verify
Returns a new instance of Verify.
121
122
123
124
125
126
|
# File 'lib/chef-dk/command/verify.rb', line 121
def initialize
super
@verification_threads = [ ]
@verification_results = [ ]
@verification_status = 0
end
|
Instance Attribute Details
#verification_results ⇒ Object
Returns the value of attribute verification_results.
118
119
120
|
# File 'lib/chef-dk/command/verify.rb', line 118
def verification_results
@verification_results
end
|
#verification_status ⇒ Object
Returns the value of attribute verification_status.
119
120
121
|
# File 'lib/chef-dk/command/verify.rb', line 119
def verification_status
@verification_status
end
|
#verification_threads ⇒ Object
Returns the value of attribute verification_threads.
117
118
119
|
# File 'lib/chef-dk/command/verify.rb', line 117
def verification_threads
@verification_threads
end
|
Class Method Details
.add_component(name, _delete_me = nil) {|component| ... } ⇒ Object
46
47
48
49
50
|
# File 'lib/chef-dk/command/verify.rb', line 46
def add_component(name, _delete_me=nil)
component = ComponentTest.new(name)
yield component if block_given? component_map[name] = component
end
|
.component(name) ⇒ Object
52
53
54
|
# File 'lib/chef-dk/command/verify.rb', line 52
def component(name)
component_map[name]
end
|
.component_map ⇒ Object
60
61
62
|
# File 'lib/chef-dk/command/verify.rb', line 60
def component_map
@component_map ||= {}
end
|
.components ⇒ Object
56
57
58
|
# File 'lib/chef-dk/command/verify.rb', line 56
def components
component_map.values
end
|
Instance Method Details
#components ⇒ Object
65
66
67
|
# File 'lib/chef-dk/command/verify.rb', line 65
def components
self.class.components
end
|
#components_to_test ⇒ Object
150
151
152
153
154
155
156
157
158
|
# File 'lib/chef-dk/command/verify.rb', line 150
def components_to_test
if @components_filter.empty?
components
else
components.select do |component|
@components_filter.include?(component.name.to_s)
end
end
end
|
#invoke_tests ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/chef-dk/command/verify.rb', line 160
def invoke_tests
components_to_test.each do |component|
verification_threads << Thread.new do
results = []
results << component.run_smoke_test
if config[:unit]
results << component.run_unit_test
end
if config[:integration]
results << component.run_integration_test
end
if results.any? {|r| r.exitstatus != 0 }
component_status = 1
@verification_status = 1
else
component_status = 0
end
{
:component => component,
:results => results,
:component_status => component_status
}
end
msg("Running verification for component '#{component.name}'")
end
end
|
#omnibus_root ⇒ Object
139
140
141
|
# File 'lib/chef-dk/command/verify.rb', line 139
def omnibus_root
config[:omnibus_dir] || super
end
|
#report_results ⇒ Object
215
216
217
218
219
220
221
222
|
# File 'lib/chef-dk/command/verify.rb', line 215
def report_results
msg("")
msg("---------------------------------------------")
verification_results.each do |result|
message = result[:component_status] == 0 ? "succeeded" : "failed"
msg("Verification of component '#{result[:component].name}' #{message}.")
end
end
|
#run(params = [ ]) ⇒ Object
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/chef-dk/command/verify.rb', line 128
def run(params = [ ])
@components_filter = parse_options(params)
validate_components!
invoke_tests
wait_for_tests
report_results
verification_status
end
|
#validate_components! ⇒ Object
143
144
145
146
147
148
|
# File 'lib/chef-dk/command/verify.rb', line 143
def validate_components!
components.each do |component|
component.omnibus_root = omnibus_root
component.assert_present!
end
end
|
#wait_for_tests ⇒ Object
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'lib/chef-dk/command/verify.rb', line 195
def wait_for_tests
while !verification_threads.empty?
verification_threads.each do |t|
if t.join(1)
verification_threads.delete t
verification_results << t.value
t.value[:results].each do |result|
if config[:verbose] || t.value[:component_status] != 0
msg("")
msg(result.stdout)
msg(result.stderr) if result.stderr
end
end
else
$stdout.write "."
end
end
end
end
|