diff options
-rw-r--r-- | CHANGELOG | 2 | ||||
-rw-r--r-- | lib/puppet/provider/augeas/augeas.rb | 32 | ||||
-rw-r--r-- | spec/unit/provider/augeas/augeas.rb | 25 |
3 files changed, 41 insertions, 18 deletions
@@ -1,4 +1,6 @@ 0.24.8 + Fixing #1948 and #1953 - augeas ins bug: wrong number of arguments (1 for 3) + Fixing #944 - changing error message from warning to info - connection recycled Fixed #961 - puppetd creating too many/not closing TCP connections diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb index 0ffddebb0..fd47da389 100644 --- a/lib/puppet/provider/augeas/augeas.rb +++ b/lib/puppet/provider/augeas/augeas.rb @@ -164,14 +164,34 @@ Puppet::Type.type(:augeas).provide(:augeas) do fail("invalid command #{cmd_array.join[" "]}") if cmd_array.length < 2 command = cmd_array[0] cmd_array.shift() - cmd_array[0]=File.join(context, cmd_array[0]) - debug("sending command '#{command}' with params #{cmd_array.inspect}") begin case command - when "set": aug.set(cmd_array[0], cmd_array[1]) - when "rm", "remove": aug.rm(cmd_array[0]) - when "clear": aug.clear(cmd_array[0]) - when "insert", "ins": aug.insert(cmd_array[0]) + when "set": + cmd_array[0]=File.join(context, cmd_array[0]) + debug("sending command '#{command}' with params #{cmd_array.inspect}") + aug.set(cmd_array[0], cmd_array[1]) + when "rm", "remove": + cmd_array[0]=File.join(context, cmd_array[0]) + debug("sending command '#{command}' with params #{cmd_array.inspect}") + aug.rm(cmd_array[0]) + when "clear": + cmd_array[0]=File.join(context, cmd_array[0]) + debug("sending command '#{command}' with params #{cmd_array.inspect}") + aug.clear(cmd_array[0]) + when "insert", "ins" + if cmd_array.size < 3 + fail("ins requires 3 parameters") + end + label = cmd_array[0] + where = cmd_array[1] + path = File.join(context, cmd_array[2]) + case where + when "before": before = true + when "after": before = false + else fail("Invalid value '#{where}' for where param") + end + debug("sending command '#{command}' with params #{[label, where, path]}") + aug.insert(path, label, before) else fail("Command '#{command}' is not supported") end rescue Exception => e diff --git a/spec/unit/provider/augeas/augeas.rb b/spec/unit/provider/augeas/augeas.rb index 1bbf18f83..4bc1814e5 100644 --- a/spec/unit/provider/augeas/augeas.rb +++ b/spec/unit/provider/augeas/augeas.rb @@ -206,30 +206,31 @@ describe provider_class do @augeas.expects(:save).returns(true) @provider.execute_changes.should == :executed end - - it "should handle insert commands" do - command = [["insert", "/Jar/Jar"]] + + + it "should handle ins commands with before" do + command = [["ins", "Binks", "before", "/Jar/Jar"]] context = "/foo" @resource.expects(:[]).times(2).returns(command).then.returns(context) - @augeas.expects(:insert).with("/foo/Jar/Jar") + @augeas.expects(:insert).with("/foo/Jar/Jar", "Binks", true) @augeas.expects(:save).returns(true) @provider.execute_changes.should == :executed - end - - it "should handle ins commands" do - command = [["ins", "/Jar/Jar"]] + end + + it "should handle ins commands with before" do + command = [["ins", "Binks", "after", "/Jar/Jar"]] context = "/foo" @resource.expects(:[]).times(2).returns(command).then.returns(context) - @augeas.expects(:insert).with("/foo/Jar/Jar") + @augeas.expects(:insert).with("/foo/Jar/Jar", "Binks", false) @augeas.expects(:save).returns(true) @provider.execute_changes.should == :executed - end + end it "should handle multiple commands" do - command = [["ins", "/Jar/Jar"], ["clear", "/Jar/Jar"]] + command = [["ins", "Binks", "after", "/Jar/Jar"], ["clear", "/Jar/Jar"]] context = "/foo" @resource.expects(:[]).times(2).returns(command).then.returns(context) - @augeas.expects(:insert).with("/foo/Jar/Jar") + @augeas.expects(:insert).with("/foo/Jar/Jar", "Binks", false) @augeas.expects(:clear).with("/foo/Jar/Jar") @augeas.expects(:save).returns(true) @provider.execute_changes.should == :executed |