summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xlib/puppet/type/exec.rb13
-rwxr-xr-xspec/unit/type/exec.rb16
2 files changed, 21 insertions, 8 deletions
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb
index 730417cda..a68bfb189 100755
--- a/lib/puppet/type/exec.rb
+++ b/lib/puppet/type/exec.rb
@@ -70,7 +70,7 @@ module Puppet
@checks.keys
end
- newproperty(:returns) do |property|
+ newproperty(:returns, :array_matching => :all) do |property|
include Puppet::Util::Execution
munge do |value|
value.to_s
@@ -79,8 +79,9 @@ module Puppet
defaultto "0"
attr_reader :output
- desc "The expected return code. An error will be returned if the
- executed command returns something else. Defaults to 0."
+ desc "The expected return code(s). An error will be returned if the
+ executed command returns something else. Defaults to 0. Can be
+ specified as an array of acceptable return codes or a single value."
# Make output a bit prettier
def change_to_s(currentvalue, newvalue)
@@ -131,9 +132,9 @@ module Puppet
end
end
- if status.exitstatus.to_s != self.should.to_s
- self.fail("%s returned %s instead of %s" %
- [self.resource[:command], status.exitstatus, self.should.to_s])
+ unless self.should.include?(status.exitstatus.to_s)
+ self.fail("%s returned %s instead of one of [%s]" %
+ [self.resource[:command], status.exitstatus, self.should.join(",")])
end
return event
diff --git a/spec/unit/type/exec.rb b/spec/unit/type/exec.rb
index 816e01bcc..761d41403 100755
--- a/spec/unit/type/exec.rb
+++ b/spec/unit/type/exec.rb
@@ -3,11 +3,11 @@
require File.dirname(__FILE__) + '/../../spec_helper'
module ExecModuleTesting
- def create_resource(command, output, exitstatus)
+ def create_resource(command, output, exitstatus, returns = [0])
@user_name = 'some_user_name'
@group_name = 'some_group_name'
Puppet.features.stubs(:root?).returns(true)
- @execer = Puppet::Type.type(:exec).new(:name => command, :path => %w{/usr/bin /bin}, :user => @user_name, :group => @group_name)
+ @execer = Puppet::Type.type(:exec).new(:name => command, :path => %w{/usr/bin /bin}, :user => @user_name, :group => @group_name, :returns => returns)
status = stub "process"
status.stubs(:exitstatus).returns(exitstatus)
@@ -44,6 +44,18 @@ describe Puppet::Type.type(:exec), " when execing" do
proc { @execer.refresh }.should raise_error(Puppet::Error)
end
+
+ it "should not report a failure if the exit status is specified in a returns array" do
+ command = "false"
+ create_resource(command, "", 1, [0,1])
+ proc { @execer.refresh }.should_not raise_error(Puppet::Error)
+ end
+
+ it "should report a failure if the exit status is not specified in a returns array" do
+ command = "false"
+ create_resource(command, "", 1, [0,100])
+ proc { @execer.refresh }.should raise_error(Puppet::Error)
+ end
it "should log the output on success" do
#Puppet::Util::Log.newdestination :console