summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2015-10-07 12:06:30 +0100
committerThom May <thom@chef.io>2015-11-09 15:02:39 +0000
commit28487132e3d5469c07cbe790fb46edfd555d1c12 (patch)
tree3a7eb22bf5512d98111880ad63a2f4fcbd28e0b1
parentc03d49c7cc3b5eb351abc9f6537a1a65692e93fc (diff)
downloadchef-28487132e3d5469c07cbe790fb46edfd555d1c12.tar.gz
Implement code review comments and fix failing tests
-rw-r--r--lib/chef/event_dispatch/dispatcher.rb4
-rw-r--r--lib/chef/formatters/base.rb7
-rw-r--r--lib/chef/provider/execute.rb18
-rw-r--r--spec/unit/provider/script_spec.rb4
4 files changed, 24 insertions, 9 deletions
diff --git a/lib/chef/event_dispatch/dispatcher.rb b/lib/chef/event_dispatch/dispatcher.rb
index affac8fb9d..7d7d2c0ad4 100644
--- a/lib/chef/event_dispatch/dispatcher.rb
+++ b/lib/chef/event_dispatch/dispatcher.rb
@@ -23,9 +23,7 @@ class Chef
# Check to see if we are dispatching to a formatter
def formatter?
@subscribers.each do |s|
- if s.class <= Chef::Formatters::Base && s.class != Chef::Formatters::NullFormatter
- return true
- end
+ return s.is_formatter? if s.respond_to?(:is_formatter?)
end
false
end
diff --git a/lib/chef/formatters/base.rb b/lib/chef/formatters/base.rb
index d3756ef00c..4c393f7a48 100644
--- a/lib/chef/formatters/base.rb
+++ b/lib/chef/formatters/base.rb
@@ -215,6 +215,10 @@ class Chef
def deprecation(message, location=caller(2..2)[0])
Chef::Log.deprecation("#{message} at #{location}")
end
+
+ def is_formatter?
+ true
+ end
end
@@ -225,6 +229,9 @@ class Chef
cli_name(:null)
+ def is_formatter?
+ false
+ end
end
end
diff --git a/lib/chef/provider/execute.rb b/lib/chef/provider/execute.rb
index 1091b82932..494267828f 100644
--- a/lib/chef/provider/execute.rb
+++ b/lib/chef/provider/execute.rb
@@ -78,6 +78,14 @@ class Chef
!!new_resource.sensitive
end
+ def stream_to_formatter?
+ Chef::Config[:always_stream_execute] || run_context.events.formatter?
+ end
+
+ def stream_to_stdout?
+ STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.info?
+ end
+
def opts
opts = {}
opts[:timeout] = timeout
@@ -89,10 +97,12 @@ class Chef
opts[:umask] = umask if umask
opts[:log_level] = :info
opts[:log_tag] = new_resource.to_s
- if (Chef::Config[:always_stream_execute] || run_context.events.formatter?) && !sensitive?
- opts[:live_stream] = Chef::EventDispatch::EventsOutputStream.new(run_context.events, :name => :execute)
- elsif STDOUT.tty? && !Chef::Config[:daemon] && Chef::Log.info? && !sensitive?
- opts[:live_stream] = STDOUT
+ unless sensitive?
+ if stream_to_formatter?
+ opts[:live_stream] = Chef::EventDispatch::EventsOutputStream.new(run_context.events, :name => :execute)
+ elsif stream_to_stdout?
+ opts[:live_stream] = STDOUT
+ end
end
opts
end
diff --git a/spec/unit/provider/script_spec.rb b/spec/unit/provider/script_spec.rb
index 423c1f51a1..7cc5abbd15 100644
--- a/spec/unit/provider/script_spec.rb
+++ b/spec/unit/provider/script_spec.rb
@@ -88,11 +88,11 @@ describe Chef::Provider::Script, "action_run" do
describe "when running the script" do
let (:default_opts) {
- {timeout: 3600, returns: 0, log_level: :info, log_tag: "script[run some perl code]",}
+ { timeout: 3600, returns: 0, log_level: :info, log_tag: "script[run some perl code]" }
}
before do
- allow(STDOUT).to receive(:tty?).and_return(true)
+ allow(STDOUT).to receive(:tty?).and_return(false)
end
it 'should set the command to "interpreter" "tempfile"' do