summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2011-03-24 12:02:51 -0700
committerNick Lewis <nick@puppetlabs.com>2011-03-24 12:02:51 -0700
commit9f1a01653f97c55cb4be8ab560a726a130042b35 (patch)
tree10395e72bdd2d4c0d6ea16ba59d403f16c39a48b
parent3875b5ba9014a6ba540e51e0ffb411d58aa521e4 (diff)
parentf8941b80bb8ba6042dddce02d132abe252756162 (diff)
downloadpuppet-9f1a01653f97c55cb4be8ab560a726a130042b35.tar.gz
puppet-9f1a01653f97c55cb4be8ab560a726a130042b35.tar.xz
puppet-9f1a01653f97c55cb4be8ab560a726a130042b35.zip
Merge branch 'ticket/2.6.next/4769' into 2.6.next
-rwxr-xr-xlib/puppet/type/exec.rb14
-rwxr-xr-xspec/unit/type/exec_spec.rb16
2 files changed, 20 insertions, 10 deletions
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb
index 4458bf081..be0ece023 100755
--- a/lib/puppet/type/exec.rb
+++ b/lib/puppet/type/exec.rb
@@ -229,19 +229,17 @@ module Puppet
newparam(:timeout) do
desc "The maximum time the command should take. If the command takes
longer than the timeout, the command is considered to have failed
- and will be stopped. Use any negative number to disable the timeout.
+ and will be stopped. Use 0 to disable the timeout.
The time is specified in seconds."
munge do |value|
value = value.shift if value.is_a?(Array)
- if value.is_a?(String)
- unless value =~ /^[-\d.]+$/
- raise ArgumentError, "The timeout must be a number."
- end
- Float(value)
- else
- value
+ begin
+ value = Float(value)
+ rescue ArgumentError => e
+ raise ArgumentError, "The timeout must be a number."
end
+ [value, 0.0].max
end
defaultto 300
diff --git a/spec/unit/type/exec_spec.rb b/spec/unit/type/exec_spec.rb
index 07ad1df4c..e155506b0 100755
--- a/spec/unit/type/exec_spec.rb
+++ b/spec/unit/type/exec_spec.rb
@@ -336,7 +336,7 @@ describe Puppet::Type.type(:exec) do
end
describe "when setting timeout" do
- [-3.5, -1, 0, 0.1, 1, 10, 4294967295].each do |valid|
+ [0, 0.1, 1, 10, 4294967295].each do |valid|
it "should accept '#{valid}' as valid" do
@exec[:timeout] = valid
@exec[:timeout].should == valid
@@ -348,7 +348,7 @@ describe Puppet::Type.type(:exec) do
end
end
- ['1/2', '1_000_000', '+12', '', 'foo'].each do |invalid|
+ ['1/2', '', 'foo', '5foo'].each do |invalid|
it "should reject '#{invalid}' as invalid" do
expect { @exec[:timeout] = invalid }.
should raise_error Puppet::Error, /The timeout must be a number/
@@ -366,6 +366,18 @@ describe Puppet::Type.type(:exec) do
sleep_exec = Puppet::Type.type(:exec).new(:name => 'sleep 1', :path => ['/bin'], :timeout => '0.2')
lambda { sleep_exec.refresh }.should raise_error Puppet::Error, "Command exceeded timeout"
end
+
+ it "should convert timeout to a float" do
+ resource = Puppet::Type.type(:exec).new :command => "/bin/false", :timeout => "12"
+ resource[:timeout].should be_a(Float)
+ resource[:timeout].should == 12.0
+ end
+
+ it "should munge negative timeouts to 0.0" do
+ resource = Puppet::Type.type(:exec).new :command => "/bin/false", :timeout => "-12.0"
+ resource.parameter(:timeout).value.should be_a(Float)
+ resource.parameter(:timeout).value.should == 0.0
+ end
end
describe "when setting tries" do