summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorNigel Kersten <nigelk@google.com>2010-05-17 16:38:19 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commite0e6b642c4eefc1b5f44b44638d2db24f4845ef1 (patch)
tree48f3e9c1c442c7ffaa351564a97af1ac8e387be0 /spec
parentc8ca19a4e7d48d5c45fd67efb981c1c3d3b80e5c (diff)
Provides #3723. Add ability for execs to have several attempts at a successful
execution and fix minor bug with logoutput and returns as an array.. * Add 'tries' and 'try_sleep' parameters * Fix bug where returns is specified as an array and logoutput on * failure. * unit tests for both cases above.
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/type/exec.rb41
1 files changed, 38 insertions, 3 deletions
diff --git a/spec/unit/type/exec.rb b/spec/unit/type/exec.rb
index 777fa0127..1eaf80390 100755
--- a/spec/unit/type/exec.rb
+++ b/spec/unit/type/exec.rb
@@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Type.type(:exec) do
- def create_resource(command, output, exitstatus, returns = [0])
+ def create_resource(command, output, exitstatus, returns = 0)
@user_name = 'some_user_name'
@group_name = 'some_group_name'
Puppet.features.stubs(:root?).returns(true)
@@ -16,8 +16,8 @@ describe Puppet::Type.type(:exec) do
Puppet::Util::SUIDManager.expects(:run_and_capture).with([command], @user_name, @group_name).returns([output, status])
end
- def create_logging_resource(command, output, exitstatus, logoutput, loglevel)
- create_resource(command, output, exitstatus)
+ def create_logging_resource(command, output, exitstatus, logoutput, loglevel, returns = 0)
+ create_resource(command, output, exitstatus, returns)
@execer[:logoutput] = logoutput
@execer[:loglevel] = loglevel
end
@@ -104,6 +104,16 @@ describe Puppet::Type.type(:exec) do
proc { @execer.refresh }.should raise_error(Puppet::Error)
end
+ it "should log the output on failure when returns is specified as an array" do
+ #Puppet::Util::Log.newdestination :console
+ command = "false"
+ output = "output1\noutput2\n"
+ create_logging_resource(command, output, 1, :on_failure, :err, [0, 100])
+ expect_output(output, :err)
+
+ proc { @execer.refresh }.should raise_error(Puppet::Error)
+ end
+
it "shouldn't log the output on success" do
#Puppet::Util::Log.newdestination :console
command = "true"
@@ -114,6 +124,31 @@ describe Puppet::Type.type(:exec) do
end
end
+ it "shouldn't log the output on success when non-zero exit status is in a returns array" do
+ #Puppet::Util::Log.newdestination :console
+ command = "true"
+ output = "output1\noutput2\n"
+ create_logging_resource(command, output, 100, :on_failure, :err, [1,100])
+ @execer.property(:returns).expects(:err).never
+ @execer.refresh
+ end
+
+ describe " when multiple tries are set," do
+
+ it "should repeat the command attempt 'tries' times on failure and produce an error" do
+ Puppet.features.stubs(:root?).returns(true)
+ command = "false"
+ user = "user"
+ group = "group"
+ tries = 5
+ retry_exec = Puppet::Type.type(:exec).new(:name => command, :path => %w{/usr/bin /bin}, :user => user, :group => group, :returns => 0, :tries => tries, :try_sleep => 0)
+ status = stub "process"
+ status.stubs(:exitstatus).returns(1)
+ Puppet::Util::SUIDManager.expects(:run_and_capture).with([command], user, group).times(tries).returns(["", status])
+ proc { retry_exec.refresh }.should raise_error(Puppet::Error)
+ end
+ end
+
it "should be able to autorequire files mentioned in the command" do
catalog = Puppet::Resource::Catalog.new
catalog.add_resource Puppet::Type.type(:file).new(:name => @executable)