summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2011-03-29 16:30:27 -0700
committerJesse Wolfe <jes5199@gmail.com>2011-03-29 16:30:27 -0700
commit9290b2f990fd4b267b2eb0da719b8f320484c4d7 (patch)
treee028dfab8ad5708f6754904d0e97fb27c2872031
parent12f5a15305ce7dc86dbd21f4f77162cae637cbfd (diff)
parentf0d768465d011e01a4ce247130e3f139a23b4c54 (diff)
downloadpuppet-9290b2f990fd4b267b2eb0da719b8f320484c4d7.tar.gz
puppet-9290b2f990fd4b267b2eb0da719b8f320484c4d7.tar.xz
puppet-9290b2f990fd4b267b2eb0da719b8f320484c4d7.zip
Merge branch 'tickets/master/6494' of https://github.com/domcleal/puppet into next
-rw-r--r--lib/puppet/provider/augeas/augeas.rb21
-rw-r--r--spec/unit/provider/augeas/augeas_spec.rb54
2 files changed, 75 insertions, 0 deletions
diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb
index 461968245..5488c6674 100644
--- a/lib/puppet/provider/augeas/augeas.rb
+++ b/lib/puppet/provider/augeas/augeas.rb
@@ -32,10 +32,14 @@ Puppet::Type.type(:augeas).provide(:augeas) do
COMMANDS = {
"set" => [ :path, :string ],
+ "setm" => [ :path, :string, :string ],
"rm" => [ :path ],
"clear" => [ :path ],
+ "mv" => [ :path, :path ],
"insert" => [ :string, :string, :path ],
"get" => [ :path, :comparator, :string ],
+ "defvar" => [ :string, :path ],
+ "defnode" => [ :string, :path, :string ],
"match" => [ :path, :glob ],
"size" => [:comparator, :int],
"include" => [:string],
@@ -46,6 +50,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do
COMMANDS["ins"] = COMMANDS["insert"]
COMMANDS["remove"] = COMMANDS["rm"]
+ COMMANDS["move"] = COMMANDS["mv"]
attr_accessor :aug
@@ -334,6 +339,10 @@ Puppet::Type.type(:augeas).provide(:augeas) do
debug("sending command '#{command}' with params #{cmd_array.inspect}")
rv = aug.set(cmd_array[0], cmd_array[1])
fail("Error sending command '#{command}' with params #{cmd_array.inspect}") if (!rv)
+ when "setm"
+ debug("sending command '#{command}' with params #{cmd_array.inspect}")
+ rv = aug.setm(cmd_array[0], cmd_array[1], cmd_array[2])
+ fail("Error sending command '#{command}' with params #{cmd_array.inspect}") if (rv == -1)
when "rm", "remove"
debug("sending command '#{command}' with params #{cmd_array.inspect}")
rv = aug.rm(cmd_array[0])
@@ -354,6 +363,18 @@ 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)
+ when "defnode"
+ debug("sending command '#{command}' with params #{cmd_array.inspect}")
+ rv = aug.defnode(cmd_array[0], cmd_array[1], cmd_array[2])
+ fail("Error sending command '#{command}' with params #{cmd_array.inspect}") if (!rv)
+ when "mv", "move"
+ debug("sending command '#{command}' with params #{cmd_array.inspect}")
+ rv = aug.mv(cmd_array[0], cmd_array[1])
+ fail("Error sending command '#{command}' with params #{cmd_array.inspect}") if (rv == -1)
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..c65f39097 100644
--- a/spec/unit/provider/augeas/augeas_spec.rb
+++ b/spec/unit/provider/augeas/augeas_spec.rb
@@ -433,5 +433,59 @@ 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 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
+
+ it "should handle defnode commands" do
+ command = "defnode newjar Jar/Jar[last()+1] Binks"
+ context = "/foo/"
+ @resource.expects(:[]).times(2).returns(command).then.returns(context)
+ @augeas.expects(:defnode).with("newjar", "/foo/Jar/Jar[last()+1]", "Binks").returns(true)
+ @augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
+ @provider.execute_changes.should == :executed
+ end
+
+ it "should handle mv commands" do
+ command = "mv Jar/Jar Binks"
+ context = "/foo/"
+ @resource.expects(:[]).times(2).returns(command).then.returns(context)
+ @augeas.expects(:mv).with("/foo/Jar/Jar", "/foo/Binks").returns(true)
+ @augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
+ @provider.execute_changes.should == :executed
+ end
+
+ it "should handle setm commands" do
+ command = ["set test[1]/Jar/Jar Foo","set test[2]/Jar/Jar Bar","setm test Jar/Jar Binks"]
+ context = "/foo/"
+ @resource.expects(:[]).times(2).returns(command).then.returns(context)
+ @augeas.expects(:set).with("/foo/test[1]/Jar/Jar", "Foo").returns(true)
+ @augeas.expects(:set).with("/foo/test[2]/Jar/Jar", "Bar").returns(true)
+ @augeas.expects(:setm).with("/foo/test", "Jar/Jar", "Binks").returns(true)
+ @augeas.expects(:save).returns(true)
+ @augeas.expects(:close)
+ @provider.execute_changes.should == :executed
+ end
end
end