summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-19 18:37:15 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-19 18:37:15 +0000
commitbc15e049826fea2ef88e2e6d1bc031835a078b77 (patch)
tree89f8257e200a737b03f9af585fdaf7805283a899
parentf0a93455982129112b8680f47f8f9182adbcd810 (diff)
downloadpuppet-bc15e049826fea2ef88e2e6d1bc031835a078b77.tar.gz
puppet-bc15e049826fea2ef88e2e6d1bc031835a078b77.tar.xz
puppet-bc15e049826fea2ef88e2e6d1bc031835a078b77.zip
Fixing provider commands and Util#execute so they always include the command output when possible, as mentioned on the list
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1635 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/provider.rb14
-rw-r--r--lib/puppet/util.rb2
-rw-r--r--test/providers/provider.rb39
3 files changed, 43 insertions, 12 deletions
diff --git a/lib/puppet/provider.rb b/lib/puppet/provider.rb
index e9dcdec15..88a7ba8a6 100644
--- a/lib/puppet/provider.rb
+++ b/lib/puppet/provider.rb
@@ -51,17 +51,9 @@ class Puppet::Provider
unless metaclass.method_defined? name
meta_def(name) do |args|
cmd = command(name) + " " + args
- begin
- output = execute cmd
- rescue Puppet::ExecutionFailure
- if output
- raise Puppet::ExecutionFailure.new(output)
- else
- raise Puppet::ExecutionFailure, "Could not execute '#{cmd}'"
- end
- end
-
- return output
+ # This might throw an ExecutionFailure, but the system above
+ # will catch it, if so.
+ return execute(cmd)
end
unless method_defined? name
define_method(name) do |args|
diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
index e91ea0156..c6ad30e3b 100644
--- a/lib/puppet/util.rb
+++ b/lib/puppet/util.rb
@@ -436,7 +436,7 @@ module Util
if failonfail
unless $? == 0
- raise ExecutionFailure, output
+ raise ExecutionFailure, "Could not execute '%s': %s" % [command, output]
end
end
diff --git a/test/providers/provider.rb b/test/providers/provider.rb
index e540f29fe..28d92e3d6 100644
--- a/test/providers/provider.rb
+++ b/test/providers/provider.rb
@@ -142,6 +142,45 @@ class TestProvider < Test::Unit::TestCase
assert(! provider.default?, "Was considered default")
end
+
+ # Make sure that failed commands get their output in the error.
+ def test_outputonfailure
+ provider = newprovider
+
+ dir = tstdir()
+ file = File.join(dir, "mycmd")
+ sh = Puppet::Util.binary("sh")
+ File.open(file, "w") { |f|
+ f.puts %{#!#{sh}
+ echo A Failure >&2
+ exit 2
+ }
+ }
+ File.chmod(0755, file)
+
+ provider.commands :cmd => file
+
+ inst = provider.new(nil)
+
+ assert_raise(Puppet::ExecutionFailure) do
+ inst.cmd "some arguments"
+ end
+
+ out = nil
+ begin
+ inst.cmd "some arguments"
+ rescue Puppet::ExecutionFailure => detail
+ out = detail.to_s
+ end
+
+ assert(out =~ /A Failure/,
+ "Did not receive command output on failure")
+
+ assert(out =~ /Could not execute/,
+ "Did not receive info wrapper on failure")
+
+
+ end
end
# $Id$