diff options
| author | Dominic Cleal <dcleal@redhat.com> | 2011-02-25 22:06:28 +0000 |
|---|---|---|
| committer | Dominic Cleal <dcleal@redhat.com> | 2011-02-25 22:06:28 +0000 |
| commit | 45cba13ee6d67c9c48e6db7b810f2fc55b1b14b8 (patch) | |
| tree | ccdd4ab64a22aec46257110887bf41b0c1d79baa | |
| parent | ea348761df0b5297dbac50c7f1c48d22746524fa (diff) | |
| download | puppet-45cba13ee6d67c9c48e6db7b810f2fc55b1b14b8.tar.gz puppet-45cba13ee6d67c9c48e6db7b810f2fc55b1b14b8.tar.xz puppet-45cba13ee6d67c9c48e6db7b810f2fc55b1b14b8.zip | |
(#6494) Add defvar command to Augeas provider
Uses Augeas' native defvar command to define variables for certain expressions
that can then be referenced later with $variable.
| -rw-r--r-- | lib/puppet/provider/augeas/augeas.rb | 5 | ||||
| -rw-r--r-- | 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 461968245..89f08ac00 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 9fcc85660..a65af9993 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 |
