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, #git_bin_dir, #git_windows_bin_dir, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_chefdk_location, #omnibus_embedded_bin_dir, #omnibus_env, #omnibus_install?, #stderr, #stdout, #system_command, #usr_bin_path, #usr_bin_prefix

Methods inherited from Base

#check_license_acceptance, #needs_help?, #needs_version?, #run_with_default_options

Constructor Details

#initializeVerify

Returns a new instance of Verify.



441
442
443
444
445
446
# File 'lib/chef-dk/command/verify.rb', line 441

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

Instance Attribute Details

#verification_resultsObject (readonly)

Returns the value of attribute verification_results.



438
439
440
# File 'lib/chef-dk/command/verify.rb', line 438

def verification_results
  @verification_results
end

#verification_statusObject (readonly)

Returns the value of attribute verification_status.



439
440
441
# File 'lib/chef-dk/command/verify.rb', line 439

def verification_status
  @verification_status
end

#verification_threadsObject (readonly)

Returns the value of attribute verification_threads.



437
438
439
# File 'lib/chef-dk/command/verify.rb', line 437

def verification_threads
  @verification_threads
end

Class Method Details

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

Yields:



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

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



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

def component(name)
  component_map[name]
end

.component_mapObject



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

def component_map
  @component_map ||= {}
end

.componentsObject



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

def components
  component_map.values
end

Instance Method Details

#componentsObject



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

def components
  self.class.components
end

#components_to_testObject



471
472
473
474
475
476
477
478
479
# File 'lib/chef-dk/command/verify.rb', line 471

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



481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/chef-dk/command/verify.rb', line 481

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



460
461
462
# File 'lib/chef-dk/command/verify.rb', line 460

def omnibus_root
  config[:omnibus_dir] || super
end

#report_resultsObject



536
537
538
539
540
541
542
543
# File 'lib/chef-dk/command/verify.rb', line 536

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



448
449
450
451
452
453
454
455
456
457
458
# File 'lib/chef-dk/command/verify.rb', line 448

def run(params = [ ])
  err("[WARN] This is an internal command used by the ChefDK development team. If you are a ChefDK user, please do not run it.")
  @components_filter = parse_options(params)

  validate_components!
  invoke_tests
  wait_for_tests
  report_results

  verification_status
end

#validate_components!Object



464
465
466
467
468
469
# File 'lib/chef-dk/command/verify.rb', line 464

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

#wait_for_testsObject



516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
# File 'lib/chef-dk/command/verify.rb', line 516

def wait_for_tests
  until 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