Please review pull request #596: (#13379) Add path of pluginsync'd lenses to Augeas load_path automatically opened by (domcleal)
Description:
This includes a cherry picked commit from master/Telly (part of issue 7285) that adds extra examples for the initialisation routine, which I then built on to test this new change.
The only point I wanted to confirm was which Puppet setting was correct to use for the path. I settled for using Puppet[:libdir] which should be equivalent to Puppet[:plugindest], based on the --genconfig comments. Other uses seem to prefer :libdir too.
- Opened: Sat Mar 24 16:27:31 UTC 2012
- Based on: puppetlabs:2.7.x (2b62839e54a815734db50f07ea902b367b306558)
- Requested merge: domcleal:tickets/2.7.x/13379-aug-pluginsync (c93993198bfa3c848e417f26f728867e6af8bfb6)
Diff follows:
diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb
index 2ff8bd9..a11d990 100644
--- a/lib/puppet/provider/augeas/augeas.rb
+++ b/lib/puppet/provider/augeas/augeas.rb
@@ -147,7 +147,7 @@ def open_augeas
flags = Augeas::TYPE_CHECK if resource[:type_check] == :true
flags |= Augeas::NO_MODL_AUTOLOAD if resource[:incl]
root = resource[:root]
- load_path = resource[:load_path]
+ load_path = get_load_path(resource)
debug("Opening augeas with root #{root}, lens path #{load_path}, flags #{flags}")
@aug = Augeas::open(root, load_path,flags)
@@ -253,6 +253,24 @@ def process_match(cmd_array)
!!return_value
end
+ # Generate lens load paths from user given paths and local pluginsync dir
+ def get_load_path(resource)
+ load_path = []
+
+ # Permits colon separated strings or arrays
+ if resource[:load_path]
+ load_path = [resource[:load_path]].flatten
+ load_path.map! { |path| path.split(/:/) }
+ load_path.flatten!
+ end
+
+ if File.exists?("#{Puppet[:libdir]}/augeas/lenses")
+ load_path << "#{Puppet[:libdir]}/augeas/lenses"
+ end
+
+ load_path.join(":")
+ end
+
def get_augeas_version
@aug.get("/augeas/version") || ""
end
diff --git a/lib/puppet/type/augeas.rb b/lib/puppet/type/augeas.rb
index cc2ca6b..ef075c3 100644
--- a/lib/puppet/type/augeas.rb
+++ b/lib/puppet/type/augeas.rb
@@ -149,7 +149,7 @@
end
newparam(:load_path) do
- desc "Optional colon-separated list of directories; these directories are searched for schema definitions."
+ desc "Optional colon-separated list or array of directories; these directories are searched for schema definitions. The agent's `$libdir/augeas/lenses` path will always be added to support pluginsync."
defaultto ""
end
diff --git a/spec/fixtures/unit/provider/augeas/augeas/augeas/lenses/test.aug b/spec/fixtures/unit/provider/augeas/augeas/augeas/lenses/test.aug
new file mode 100644
index 0000000..bea707e
--- /dev/null
+++ b/spec/fixtures/unit/provider/augeas/augeas/augeas/lenses/test.aug
@@ -0,0 +1,13 @@
+(*
+Simple lens, written to be distributed with Puppet unit tests.
+
+Author: Dominic Cleal <[email protected]>
+
+About: License:
+ This file is licensed under the Apache 2.0 licence, like the rest of Puppet.
+*)
+
+module Test = autoload xfm
+let lns = [ seq "line" . store /[^\n]+/ . del "\n" "\n" ]*
+let filter = incl "/etc/test"
+let xfm = transform lns filter
diff --git a/spec/fixtures/unit/provider/augeas/augeas/etc/fstab b/spec/fixtures/unit/provider/augeas/augeas/etc/fstab
new file mode 100644
index 0000000..ddbd8ff
--- /dev/null
+++ b/spec/fixtures/unit/provider/augeas/augeas/etc/fstab
@@ -0,0 +1,10 @@
+/dev/vg00/lv00 / ext3 defaults 1 1
+LABEL=/boot /boot ext3 defaults 1 2
+devpts /dev/pts devpts gid=5,mode=620 0 0
+tmpfs /dev/shm tmpfs defaults 0 0
+/dev/vg00/home /home ext3 defaults 1 2
+proc /proc proc defaults 0 0
+sysfs /sys sysfs defaults 0 0
+/dev/vg00/local /local ext3 defaults 1 2
+/dev/vg00/images /var/lib/xen/images ext3 defaults 1 2
+/dev/vg00/swap swap swap defaults 0 0
diff --git a/spec/fixtures/unit/provider/augeas/augeas/etc/hosts b/spec/fixtures/unit/provider/augeas/augeas/etc/hosts
new file mode 100644
index 0000000..44cd9da
--- /dev/null
+++ b/spec/fixtures/unit/provider/augeas/augeas/etc/hosts
@@ -0,0 +1,6 @@
+# Do not remove the following line, or various programs
+# that require network functionality will fail.
+127.0.0.1 localhost.localdomain localhost galia.watzmann.net galia
+#172.31.122.254 granny.watzmann.net granny puppet
+#172.31.122.1 galia.watzmann.net galia
+172.31.122.14 orange.watzmann.net orange
diff --git a/spec/fixtures/unit/provider/augeas/augeas/etc/test b/spec/fixtures/unit/provider/augeas/augeas/etc/test
new file mode 100644
index 0000000..86e041d
--- /dev/null
+++ b/spec/fixtures/unit/provider/augeas/augeas/etc/test
@@ -0,0 +1,3 @@
+foo
+bar
+baz
diff --git a/spec/fixtures/unit/provider/augeas/augeas/test.aug b/spec/fixtures/unit/provider/augeas/augeas/test.aug
new file mode 100644
index 0000000..bea707e
--- /dev/null
+++ b/spec/fixtures/unit/provider/augeas/augeas/test.aug
@@ -0,0 +1,13 @@
+(*
+Simple lens, written to be distributed with Puppet unit tests.
+
+Author: Dominic Cleal <[email protected]>
+
+About: License:
+ This file is licensed under the Apache 2.0 licence, like the rest of Puppet.
+*)
+
+module Test = autoload xfm
+let lns = [ seq "line" . store /[^\n]+/ . del "\n" "\n" ]*
+let filter = incl "/etc/test"
+let xfm = transform lns filter
diff --git a/spec/unit/provider/augeas/augeas_spec.rb b/spec/unit/provider/augeas/augeas_spec.rb
index 97d0f5d..d1a6243 100755
--- a/spec/unit/provider/augeas/augeas_spec.rb
+++ b/spec/unit/provider/augeas/augeas_spec.rb
@@ -587,4 +587,82 @@
File.read(target).should =~ /PermitRootLogin no/
end
end
+
+ # Run initialisation tests of the real Augeas library to test our open_augeas
+ # method. This relies on Augeas and ruby-augeas on the host to be
+ # functioning.
+ describe "augeas lib initialisation", :if => Puppet.features.augeas? do
+ # Expect lenses for fstab and hosts
+ it "should have loaded standard files by default" do
+ aug = @provider.open_augeas
+ aug.should_not == nil
+ aug.match("/files/etc/fstab").should == ["/files/etc/fstab"]
+ aug.match("/files/etc/hosts").should == ["/files/etc/hosts"]
+ aug.match("/files/etc/test").should == []
+ end
+
+ # Only the file specified should be loaded
+ it "should load one file if incl/lens used" do
+ @resource[:incl] = "/etc/hosts"
+ @resource[:lens] = "Hosts.lns"
+
+ aug = @provider.open_augeas
+ aug.should_not == nil
+ aug.match("/files/etc/fstab").should == []
+ aug.match("/files/etc/hosts").should == ["/files/etc/hosts"]
+ aug.match("/files/etc/test").should == []
+ end
+
+ it "should also load lenses from load_path" do
+ @resource[:load_path] = my_fixture_dir
+
+ aug = @provider.open_augeas
+ aug.should_not == nil
+ aug.match("/files/etc/fstab").should == ["/files/etc/fstab"]
+ aug.match("/files/etc/hosts").should == ["/files/etc/hosts"]
+ aug.match("/files/etc/test").should == ["/files/etc/test"]
+ end
+
+ it "should also load lenses from pluginsync'd path" do
+ Puppet.stubs(:[]).with(:libdir).returns(my_fixture_dir)
+
+ aug = @provider.open_augeas
+ aug.should_not == nil
+ aug.match("/files/etc/fstab").should == ["/files/etc/fstab"]
+ aug.match("/files/etc/hosts").should == ["/files/etc/hosts"]
+ aug.match("/files/etc/test").should == ["/files/etc/test"]
+ end
+ end
+
+ describe "get_load_path" do
+ it "should offer no load_path by default" do
+ @provider.get_load_path(@resource).should == ""
+ end
+
+ it "should offer one path from load_path" do
+ @resource[:load_path] = "/foo"
+ @provider.get_load_path(@resource).should == "/foo"
+ end
+
+ it "should offer multiple colon-separated paths from load_path" do
+ @resource[:load_path] = "/foo:/bar:/baz"
+ @provider.get_load_path(@resource).should == "/foo:/bar:/baz"
+ end
+
+ it "should offer multiple paths in array from load_path" do
+ @resource[:load_path] = ["/foo", "/bar", "/baz"]
+ @provider.get_load_path(@resource).should == "/foo:/bar:/baz"
+ end
+
+ it "should offer pluginsync augeas/lenses subdir" do
+ Puppet.stubs(:[]).with(:libdir).returns(my_fixture_dir)
+ @provider.get_load_path(@resource).should == "#{my_fixture_dir}/augeas/lenses"
+ end
+
+ it "should offer both pluginsync and load_path paths" do
+ Puppet.stubs(:[]).with(:libdir).returns(my_fixture_dir)
+ @resource[:load_path] = ["/foo", "/bar", "/baz"]
+ @provider.get_load_path(@resource).should == "/foo:/bar:/baz:#{my_fixture_dir}/augeas/lenses"
+ end
+ end
end
-- 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.
