Uses Augeas' native defvar command to define variables for certain expressions
that can then be referenced later with $variable.

Signed-off-by: Dominic Cleal <dcl...@redhat.com>
---
Local-branch: tickets/master/6494
 lib/puppet/provider/augeas/augeas.rb     |    5 +++++
 spec/unit/provider/augeas/augeas_spec.rb |   23 +++++++++++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/lib/puppet/provider/augeas/augeas.rb 
b/lib/puppet/provider/augeas/augeas.rb
index 4619682..89f08ac 100644
--- a/lib/puppet/provider/augeas/augeas.rb
+++ b/lib/puppet/provider/augeas/augeas.rb
@@ -36,6 +36,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do
     "clear" => [ :path ],
     "insert" => [ :string, :string, :path ],
     "get" => [ :path, :comparator, :string ],
+    "defvar" => [ :string, :path ],
     "match" => [ :path, :glob ],
     "size" => [:comparator, :int],
     "include" => [:string],
@@ -354,6 +355,10 @@ Puppet::Type.type(:augeas).provide(:augeas) do
             debug("sending command '#{command}' with params #{[label, where, 
path].inspect}")
             rv = aug.insert(path, label, before)
             fail("Error sending command '#{command}' with params 
#{cmd_array.inspect}") if (rv == -1)
+          when "defvar"
+            debug("sending command '#{command}' with params 
#{cmd_array.inspect}")
+            rv = aug.defvar(cmd_array[0], cmd_array[1])
+            fail("Error sending command '#{command}' with params 
#{cmd_array.inspect}") if (!rv)
           else fail("Command '#{command}' is not supported")
         end
       rescue SystemExit,NoMemoryError
diff --git a/spec/unit/provider/augeas/augeas_spec.rb 
b/spec/unit/provider/augeas/augeas_spec.rb
index 9fcc856..a65af99 100644
--- a/spec/unit/provider/augeas/augeas_spec.rb
+++ b/spec/unit/provider/augeas/augeas_spec.rb
@@ -433,5 +433,28 @@ describe provider_class do
       @augeas.expects(:close)
       @provider.execute_changes.should == :executed
     end
+
+    it "should handle defvar commands" do
+      command = "defvar myjar Jar/Jar"
+      context = "/foo/"
+      @resource.expects(:[]).times(2).returns(command).then.returns(context)
+      @augeas.expects(:defvar).with("myjar", "/foo/Jar/Jar").returns(true)
+      @augeas.expects(:save).returns(true)
+      @augeas.expects(:close)
+      @provider.execute_changes.should == :executed
+    end
+
+    it "should pass through augeas defvar variables without context" do
+      command = ["defvar myjar Jar/Jar","set $myjar/Binks 1"]
+      context = "/foo/"
+      @resource.expects(:[]).times(2).returns(command).then.returns(context)
+      @augeas.expects(:defvar).with("myjar", "/foo/Jar/Jar").returns(true)
+      # this is the important bit, shouldn't be /foo/$myjar/Binks
+      @augeas.expects(:set).with("$myjar/Binks", "1").returns(true)
+      @augeas.expects(:save).returns(true)
+      @augeas.expects(:close)
+      @provider.execute_changes.should == :executed
+    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 puppet-dev@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to