summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2015-06-02 16:33:59 +0100
committerThom May <thom@may.lt>2015-06-02 16:33:59 +0100
commit93f7b74349362d0c698a1080177b94e64248dac6 (patch)
tree02c29cb9ef8602d56a2a8b921928fd356c55a113 /lib
parent22da6b42a02fcfd7e9d03f5f09828b7ddc569bb9 (diff)
parent3ed66239de9c65e1e6515332b187de6988725ec2 (diff)
downloadchef-93f7b74349362d0c698a1080177b94e64248dac6.tar.gz
Merge pull request #3412 from chef/sd/CI-31
Make sure the audit mode output is reflected both in the logs and in the formatter output.
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/audit/audit_reporter.rb4
-rw-r--r--lib/chef/audit/logger.rb36
-rw-r--r--lib/chef/audit/runner.rb6
-rw-r--r--lib/chef/client.rb6
-rw-r--r--lib/chef/event_dispatch/base.rb4
-rw-r--r--lib/chef/formatters/doc.rb6
6 files changed, 51 insertions, 11 deletions
diff --git a/lib/chef/audit/audit_reporter.rb b/lib/chef/audit/audit_reporter.rb
index b74bf07b8b..d952d8a249 100644
--- a/lib/chef/audit/audit_reporter.rb
+++ b/lib/chef/audit/audit_reporter.rb
@@ -47,7 +47,7 @@ class Chef
@run_status = run_status
end
- def audit_phase_complete
+ def audit_phase_complete(audit_output)
Chef::Log.debug("Audit Reporter completed successfully without errors.")
ordered_control_groups.each do |name, control_group|
audit_data.add_control_group(control_group)
@@ -58,7 +58,7 @@ class Chef
# 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)
+ def audit_phase_failed(error, audit_output)
# The stacktrace information has already been logged elsewhere
@audit_phase_error = error
Chef::Log.debug("Audit Reporter failed.")
diff --git a/lib/chef/audit/logger.rb b/lib/chef/audit/logger.rb
new file mode 100644
index 0000000000..e46f54e582
--- /dev/null
+++ b/lib/chef/audit/logger.rb
@@ -0,0 +1,36 @@
+#
+# Copyright:: Copyright (c) 2014 Chef Software, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'stringio'
+
+class Chef
+ class Audit
+ class Logger
+ def self.puts(message="")
+ @buffer ||= StringIO.new
+ @buffer.puts(message)
+
+ Chef::Log.info(message)
+ end
+
+ def self.read_buffer
+ return "" if @buffer.nil?
+ @buffer.string
+ end
+ end
+ end
+end
diff --git a/lib/chef/audit/runner.rb b/lib/chef/audit/runner.rb
index 801bf5ee58..234d83ab8f 100644
--- a/lib/chef/audit/runner.rb
+++ b/lib/chef/audit/runner.rb
@@ -16,6 +16,8 @@
# limitations under the License.
#
+require 'chef/audit/logger'
+
class Chef
class Audit
class Runner
@@ -115,8 +117,8 @@ class Chef
# the output stream to be changed for a formatter once the formatter has
# been added.
def set_streams
- RSpec.configuration.output_stream = Chef::Config[:log_location]
- RSpec.configuration.error_stream = Chef::Config[:log_location]
+ RSpec.configuration.output_stream = Chef::Audit::Logger
+ RSpec.configuration.error_stream = Chef::Audit::Logger
end
# Add formatters which we use to
diff --git a/lib/chef/client.rb b/lib/chef/client.rb
index 51e78e60a9..141827e65b 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -723,13 +723,13 @@ class Chef
auditor.run
if auditor.failed?
audit_exception = Chef::Exceptions::AuditsFailed.new(auditor.num_failed, auditor.num_total)
- events.audit_phase_failed(audit_exception)
+ @events.audit_phase_failed(audit_exception, Chef::Audit::Logger.read_buffer)
else
- events.audit_phase_complete
+ @events.audit_phase_complete(Chef::Audit::Logger.read_buffer)
end
rescue Exception => e
Chef::Log.error("Audit phase failed with error message: #{e.message}")
- events.audit_phase_failed(e)
+ @events.audit_phase_failed(e, Chef::Audit::Logger.read_buffer)
audit_exception = e
end
audit_exception
diff --git a/lib/chef/event_dispatch/base.rb b/lib/chef/event_dispatch/base.rb
index 93caa62a65..73fe25ec13 100644
--- a/lib/chef/event_dispatch/base.rb
+++ b/lib/chef/event_dispatch/base.rb
@@ -244,13 +244,13 @@ class Chef
end
# Called when audit phase successfully finishes
- def audit_phase_complete
+ def audit_phase_complete(audit_output)
end
# Called if there is an uncaught exception during the audit phase. The audit runner should
# be catching and handling errors from the examples, so this is only uncaught errors (like
# bugs in our handling code)
- def audit_phase_failed(exception)
+ def audit_phase_failed(exception, audit_output)
end
# Signifies the start of a `control_group` block with a defined name
diff --git a/lib/chef/formatters/doc.rb b/lib/chef/formatters/doc.rb
index e63c764cbf..e76a940c38 100644
--- a/lib/chef/formatters/doc.rb
+++ b/lib/chef/formatters/doc.rb
@@ -179,11 +179,13 @@ class Chef
puts_line "Starting audit phase"
end
- def audit_phase_complete
+ def audit_phase_complete(audit_output)
+ puts_line audit_output
puts_line "Auditing complete"
end
- def audit_phase_failed(error)
+ def audit_phase_failed(error, audit_output)
+ puts_line audit_output
puts_line ""
puts_line "Audit phase exception:"
indent