From: Matt Robinson <[email protected]>

This makes it possible to use shell builtins when the exec is inline
bash commands.

Paired-with: Max Martin

Signed-off-by: Max Martin <[email protected]>
---
 lib/puppet/provider/exec/shell.rb     |   17 ++++++++++++
 spec/unit/provider/exec/shell_spec.rb |   44 +++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 0 deletions(-)
 create mode 100644 lib/puppet/provider/exec/shell.rb
 create mode 100644 spec/unit/provider/exec/shell_spec.rb

diff --git a/lib/puppet/provider/exec/shell.rb 
b/lib/puppet/provider/exec/shell.rb
new file mode 100644
index 0000000..98f309e
--- /dev/null
+++ b/lib/puppet/provider/exec/shell.rb
@@ -0,0 +1,17 @@
+Puppet::Type.type(:exec).provide :shell, :parent => :posix do
+  include Puppet::Util::Execution
+
+  confine :feature => :posix
+
+  desc "Execute external binaries directly, on POSIX systems.
+passing through a shell so that shell built ins are available."
+
+  def run(command, check = false)
+    command = %Q{/bin/sh -c "#{command.gsub(/"/,'\"')}"}
+    super(command, check)
+  end
+
+  def validatecmd(command)
+    true
+  end
+end
diff --git a/spec/unit/provider/exec/shell_spec.rb 
b/spec/unit/provider/exec/shell_spec.rb
new file mode 100644
index 0000000..44390ff
--- /dev/null
+++ b/spec/unit/provider/exec/shell_spec.rb
@@ -0,0 +1,44 @@
+#!/usr/bin/env ruby
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+provider_class = Puppet::Type.type(:exec).provider(:shell)
+
+describe provider_class do
+  before :each do
+    @resource = Puppet::Resource.new(:exec, 'foo')
+    @provider = provider_class.new(@resource)
+  end
+
+  describe "#run" do
+    it "should be able to run builtin shell commands" do
+      output, status = @provider.run("echo foo")
+      status.exitstatus.should == 0
+      output.should == "foo\n"
+    end
+
+    it "should be able to run commands with single quotes in them" do
+      output, status = @provider.run("echo 'foo bar'")
+      status.exitstatus.should == 0
+      output.should == "foo bar\n"
+    end
+
+    it "should be able to run commands with double quotes in them" do
+      output, status = @provider.run("echo 'foo bar'")
+      status.exitstatus.should == 0
+      output.should == "foo bar\n"
+    end
+
+    it "should be able to read values from the environment parameter" do
+      @resource[:environment] = "FOO=bar"
+      output, status = @provider.run("echo $FOO")
+      status.exitstatus.should == 0
+      output.should == "bar\n"
+    end
+  end
+
+  describe "#validatecmd" do
+    it "should always return true because builtins don't need path or to be 
fully qualified" do
+      @provider.validatecmd('whateverdoesntmatter').should == true
+    end
+  end
+end
-- 
1.7.4

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to