Class: ChefDK::Command::Verify
- Inherits:
-
Base
- Object
- Base
- ChefDK::Command::Verify
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
#needs_help?, #needs_version?, #run_with_default_options
Constructor Details
#initialize ⇒ Verify
Returns a new instance of Verify.
540
541
542
543
544
545
|
# File 'lib/chef-dk/command/verify.rb', line 540
def initialize
super
@verification_threads = [ ]
@verification_results = [ ]
@verification_status = 0
end
|
Instance Attribute Details
#verification_results ⇒ Object
Returns the value of attribute verification_results.
537
538
539
|
# File 'lib/chef-dk/command/verify.rb', line 537
def verification_results
@verification_results
end
|
#verification_status ⇒ Object
Returns the value of attribute verification_status.
538
539
540
|
# File 'lib/chef-dk/command/verify.rb', line 538
def verification_status
@verification_status
end
|
#verification_threads ⇒ Object
Returns the value of attribute verification_threads.
536
537
538
|
# File 'lib/chef-dk/command/verify.rb', line 536
def verification_threads
@verification_threads
end
|
Class Method Details
.add_component(name, _delete_me = nil) {|component| ... } ⇒ Object
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?
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_map ⇒ Object
61
62
63
|
# File 'lib/chef-dk/command/verify.rb', line 61
def component_map
@component_map ||= {}
end
|
.components ⇒ Object
57
58
59
|
# File 'lib/chef-dk/command/verify.rb', line 57
def components
component_map.values
end
|
Instance Method Details
#components ⇒ Object
66
67
68
|
# File 'lib/chef-dk/command/verify.rb', line 66
def components
self.class.components
end
|
#components_to_test ⇒ Object
569
570
571
572
573
574
575
576
577
|
# File 'lib/chef-dk/command/verify.rb', line 569
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
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
|
# File 'lib/chef-dk/command/verify.rb', line 579
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
558
559
560
|
# File 'lib/chef-dk/command/verify.rb', line 558
def omnibus_root
config[:omnibus_dir] || super
end
|
#report_results ⇒ Object
634
635
636
637
638
639
640
641
|
# File 'lib/chef-dk/command/verify.rb', line 634
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
547
548
549
550
551
552
553
554
555
556
|
# File 'lib/chef-dk/command/verify.rb', line 547
def run(params = [ ])
@components_filter = parse_options(params)
validate_components!
invoke_tests
wait_for_tests
report_results
verification_status
end
|
#validate_components! ⇒ Object
562
563
564
565
566
567
|
# File 'lib/chef-dk/command/verify.rb', line 562
def validate_components!
components.each do |component|
component.omnibus_root = omnibus_root
component.assert_present!
end
end
|
#wait_for_tests ⇒ Object
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
|
# File 'lib/chef-dk/command/verify.rb', line 614
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
|