class ChefCLI::Command::Verify
def add_component(name, _delete_me = nil)
def add_component(name, _delete_me = nil) component = ComponentTest.new(name) yield component if block_given? # delete this conditional component_map[name] = component end
def component(name)
def component(name) component_map[name] end
def component_map
def component_map @component_map ||= {} end
def components
def components component_map.values end
def components
def components self.class.components end
def components_to_test
def components_to_test if @components_filter.empty? components else components.select do |component| @components_filter.include?(component.name.to_s) end end end
def initialize
def initialize super @verification_threads = [ ] @verification_results = [ ] @verification_status = 0 end
def invoke_tests
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
def omnibus_root
def omnibus_root config[:omnibus_dir] || super end
def report_results
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
def run(params = [ ])
def run(params = [ ]) err("[WARN] This is an internal command used by the ChefCLI development team. If you are a ChefCLI user, please do not run it.") @components_filter = parse_options(params) validate_components! invoke_tests wait_for_tests report_results verification_status end
def validate_components!
def validate_components! components.each do |component| component.omnibus_root = omnibus_root component.assert_present! end end
def wait_for_tests
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