From d454a7214b2738acd9a00e1f29737927a4a4d5d7 Mon Sep 17 00:00:00 2001 From: tyler-ball Date: Wed, 26 Nov 2014 14:12:03 -0800 Subject: Failing an audit example will now raise an error and make chef exit with a non-zero code --- lib/chef/audit/audit_reporter.rb | 2 ++ lib/chef/audit/runner.rb | 4 ++++ lib/chef/client.rb | 3 ++- lib/chef/exceptions.rb | 5 +++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/chef/audit/audit_reporter.rb b/lib/chef/audit/audit_reporter.rb index d022ac0c47..00af9984b2 100644 --- a/lib/chef/audit/audit_reporter.rb +++ b/lib/chef/audit/audit_reporter.rb @@ -55,6 +55,8 @@ class Chef # If the audit phase failed, its because there was some kind of error in the framework # that runs tests - normal errors are interpreted as EXAMPLE failures and captured. + # We still want to send available audit information to the server so we process the + # known control groups. def audit_phase_failed(error) # The stacktrace information has already been logged elsewhere Chef::Log.debug("Audit Reporter failed.") diff --git a/lib/chef/audit/runner.rb b/lib/chef/audit/runner.rb index 2fd33ac0de..b3df70f705 100644 --- a/lib/chef/audit/runner.rb +++ b/lib/chef/audit/runner.rb @@ -35,6 +35,10 @@ class Chef do_run end + def failed_examples? + RSpec.world.reporter.failed_examples.size > 0 + end + private # Prepare to run audits: # - Require files diff --git a/lib/chef/client.rb b/lib/chef/client.rb index aa0d6722fe..5d46794745 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -358,9 +358,10 @@ class Chef Chef::Log.info("Starting audit phase") auditor = Chef::Audit::Runner.new(run_context) auditor.run + raise Chef::Exceptions::AuditsFailed if auditor.failed_examples? @events.audit_phase_complete rescue Exception => e - Chef::Log.error("Audit phase failed with error message #{e.message}") + Chef::Log.error("Audit phase failed with error message: #{e.message}") @events.audit_phase_failed(e) audit_exception = e end diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb index 9fae1d566f..2cf8766585 100644 --- a/lib/chef/exceptions.rb +++ b/lib/chef/exceptions.rb @@ -396,6 +396,11 @@ class Chef super "You must provide a block with audits" end end + class AuditsFailed < RuntimeError + def initialize + super "There were audit example failures. Results were still sent to the server." + end + end # If a converge or audit fails, we want to wrap the output from those errors into 1 error so we can # see both issues in the output. It is possible that nil will be provided. You must call `fill_backtrace` -- cgit v1.2.1