Class: ChefDK::Command::Verify

Inherits:
Base
  • Object
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

#initializeVerify

Returns a new instance of Verify.



149
150
151
152
153
154
# File 'lib/chef-dk/command/verify.rb', line 149

def initialize
  super
  @verification_threads = [ ]
  @verification_results = [ ]
  @verification_status = 0
end

Instance Attribute Details

#verification_resultsObject (readonly)

Returns the value of attribute verification_results.



146
147
148
# File 'lib/chef-dk/command/verify.rb', line 146

def verification_results
  @verification_results
end

#verification_statusObject (readonly)

Returns the value of attribute verification_status.



147
148
149
# File 'lib/chef-dk/command/verify.rb', line 147

def verification_status
  @verification_status
end

#verification_threadsObject (readonly)

Returns the value of attribute verification_threads.



145
146
147
# File 'lib/chef-dk/command/verify.rb', line 145

def verification_threads
  @verification_threads
end

Class Method Details

.add_component(name, _delete_me = nil) {|component| ... } ⇒ Object

Yields:



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? #delete this conditional
  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_mapObject



60
61
62
# File 'lib/chef-dk/command/verify.rb', line 60

def component_map
  @component_map ||= {}
end

.componentsObject



56
57
58
# File 'lib/chef-dk/command/verify.rb', line 56

def components
  component_map.values
end

Instance Method Details

#componentsObject



65
66
67
# File 'lib/chef-dk/command/verify.rb', line 65

def components
  self.class.components
end

#components_to_testObject



178
179
180
181
182
183
184
185
186
# File 'lib/chef-dk/command/verify.rb', line 178

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_testsObject



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/chef-dk/command/verify.rb', line 188

def invoke_tests
  components_to_test.each do |component|
    # Run the component specs in parallel
    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_rootObject



167
168
169
# File 'lib/chef-dk/command/verify.rb', line 167

def omnibus_root
  config[:omnibus_dir] || super
end

#report_resultsObject



243
244
245
246
247
248
249
250
# File 'lib/chef-dk/command/verify.rb', line 243

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



156
157
158
159
160
161
162
163
164
165
# File 'lib/chef-dk/command/verify.rb', line 156

def run(params = [ ])
  @components_filter = parse_options(params)

  validate_components!
  invoke_tests
  wait_for_tests
  report_results

  verification_status
end

#validate_components!Object



171
172
173
174
175
176
# File 'lib/chef-dk/command/verify.rb', line 171

def validate_components!
  components.each do |component|
    component.omnibus_root = omnibus_root
    component.assert_present!
  end
end

#wait_for_testsObject



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# File 'lib/chef-dk/command/verify.rb', line 223

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