diff options
author | tyler-ball <tyleraball@gmail.com> | 2014-11-26 14:12:03 -0800 |
---|---|---|
committer | tyler-ball <tyleraball@gmail.com> | 2014-12-17 18:52:21 -0800 |
commit | d454a7214b2738acd9a00e1f29737927a4a4d5d7 (patch) | |
tree | e96081d9922af763215d6ab44ac4b54041c45b96 /lib/chef | |
parent | b079e015f4ebb8c5db600bd49641699cbbacdb10 (diff) | |
download | chef-d454a7214b2738acd9a00e1f29737927a4a4d5d7.tar.gz |
Failing an audit example will now raise an error and make chef exit with a non-zero code
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/audit/audit_reporter.rb | 2 | ||||
-rw-r--r-- | lib/chef/audit/runner.rb | 4 | ||||
-rw-r--r-- | lib/chef/client.rb | 3 | ||||
-rw-r--r-- | lib/chef/exceptions.rb | 5 |
4 files changed, 13 insertions, 1 deletions
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` |