diff options
author | Serdar Sutay <serdar@opscode.com> | 2015-05-21 14:03:31 -0700 |
---|---|---|
committer | Serdar Sutay <serdar@opscode.com> | 2015-05-29 08:41:12 -0700 |
commit | 3e1cbd6856eda733a1ed800184d8545e5d070e8e (patch) | |
tree | ae3acb56976aaee7963ba20851a9684702d23370 /lib | |
parent | c58162b9ce165bde444ff396a95668666884c052 (diff) | |
download | chef-3e1cbd6856eda733a1ed800184d8545e5d070e8e.tar.gz |
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.rb | 4 | ||||
-rw-r--r-- | lib/chef/audit/logger.rb | 38 | ||||
-rw-r--r-- | lib/chef/audit/runner.rb | 6 | ||||
-rw-r--r-- | lib/chef/client.rb | 4 | ||||
-rw-r--r-- | lib/chef/event_dispatch/base.rb | 4 | ||||
-rw-r--r-- | lib/chef/formatters/doc.rb | 6 |
6 files changed, 52 insertions, 10 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..c5c9f5c8a2 --- /dev/null +++ b/lib/chef/audit/logger.rb @@ -0,0 +1,38 @@ +# +# 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="") + if @buffer.nil? + @buffer = StringIO.new + end + + @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..9f16efb31e 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -725,11 +725,11 @@ class Chef audit_exception = Chef::Exceptions::AuditsFailed.new(auditor.num_failed, auditor.num_total) events.audit_phase_failed(audit_exception) 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 |