Class: ChefDK::Command::Verify

Inherits:
Base
  • Object
show all
Includes:
Helpers
Defined in:
lib/chef-dk/command/verify.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#chefdk_home, #err, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_chefdk_location, #omnibus_embedded_bin_dir, #omnibus_install?, #stderr, #stdout, #system_command

Methods inherited from Base

#needs_help?, #needs_version?, #run_with_default_options

Constructor Details

#initializeVerify

Returns a new instance of Verify.



304
305
306
307
308
309
# File 'lib/chef-dk/command/verify.rb', line 304

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

Instance Attribute Details

#verification_resultsObject (readonly)

Returns the value of attribute verification_results.



301
302
303
# File 'lib/chef-dk/command/verify.rb', line 301

def verification_results
  @verification_results
end

#verification_statusObject (readonly)

Returns the value of attribute verification_status.



302
303
304
# File 'lib/chef-dk/command/verify.rb', line 302

def verification_status
  @verification_status
end

#verification_threadsObject (readonly)

Returns the value of attribute verification_threads.



300
301
302
# File 'lib/chef-dk/command/verify.rb', line 300

def verification_threads
  @verification_threads
end

Class Method Details

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

Yields:



47
48
49
50
51
# File 'lib/chef-dk/command/verify.rb', line 47

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



53
54
55
# File 'lib/chef-dk/command/verify.rb', line 53

def component(name)
  component_map[name]
end

.component_mapObject



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

def component_map
  @component_map ||= {}
end

.componentsObject



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

def components
  component_map.values
end

Instance Method Details

#componentsObject



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

def components
  self.class.components
end

#components_to_testObject



333
334
335
336
337
338
339
340
341
# File 'lib/chef-dk/command/verify.rb', line 333

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



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/chef-dk/command/verify.rb', line 343

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



322
323
324
# File 'lib/chef-dk/command/verify.rb', line 322

def omnibus_root
  config[:omnibus_dir] || super
end

#report_resultsObject



398
399
400
401
402
403
404
405
# File 'lib/chef-dk/command/verify.rb', line 398

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



311
312
313
314
315
316
317
318
319
320
# File 'lib/chef-dk/command/verify.rb', line 311

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

  validate_components!
  invoke_tests
  wait_for_tests
  report_results

  verification_status
end

#validate_components!Object



326
327
328
329
330
331
# File 'lib/chef-dk/command/verify.rb', line 326

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

#wait_for_testsObject



378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/chef-dk/command/verify.rb', line 378

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