summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortyler-ball <tyleraball@gmail.com>2014-11-26 14:12:03 -0800
committertyler-ball <tyleraball@gmail.com>2014-12-08 14:56:47 -0800
commitf6fee128f81acde3e1782ebb2533f14a56c2d0c0 (patch)
tree7cdd2b78225db6388731f4f778ad6540b81f697e
parent98937205d71839e372a09da2739e2e46e75475c6 (diff)
downloadchef-f6fee128f81acde3e1782ebb2533f14a56c2d0c0.tar.gz
Failing an audit example will now raise an error and make chef exit with a non-zero code
-rw-r--r--lib/chef/audit/audit_reporter.rb2
-rw-r--r--lib/chef/audit/runner.rb4
-rw-r--r--lib/chef/client.rb3
-rw-r--r--lib/chef/exceptions.rb5
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 51c007d1d0..11b1cc7d38 100644
--- a/lib/chef/audit/runner.rb
+++ b/lib/chef/audit/runner.rb
@@ -33,6 +33,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 c270f709c9..0aae8d9484 100644
--- a/lib/chef/exceptions.rb
+++ b/lib/chef/exceptions.rb
@@ -390,6 +390,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`