[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

James Turnbull james at lovedthanlost.net
Wed Jul 14 10:29:23 UTC 2010


The following commit has been merged in the upstream branch:
commit 66a44ddc3032654109036371a5f3a60dd2ab4a9f
Author: David Lutterkort <lutter at redhat.com>
Date:   Mon Oct 5 20:32:38 2009 -0700

    type augeas: add 'incl' and 'lens' parameters
    
    These parameters allow loading a file anywhere on the filesystem; using
    them also greatly speeds up processing the resource.
    
      * lib/puppet/type/augeas.rb: add 'incl' and 'lens' parameters; change
        default for 'context' when 'incl' is given.
      * lib/puppet/provider/augeas/augeas.rb: when 'lens' and 'incl' are given,
        only load that file
      * spec/unit/type/augeas.rb: check that constraints on new parameters are
        enforced
    
    This fixes ticket #2694

diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb
index a645fbe..78be1d7 100644
--- a/lib/puppet/provider/augeas/augeas.rb
+++ b/lib/puppet/provider/augeas/augeas.rb
@@ -133,6 +133,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do
         unless @aug
             flags = Augeas::NONE
             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]
             debug("Opening augeas with root #{root}, lens path #{load_path}, flags #{flags}")
@@ -141,6 +142,12 @@ Puppet::Type.type(:augeas).provide(:augeas) do
             if get_augeas_version >= "0.3.6"
                 debug("Augeas version #{get_augeas_version} is installed")
             end
+
+            if resource[:incl]
+                aug.set("/augeas/load/Xfm/lens", resource[:lens])
+                aug.set("/augeas/load/Xfm/incl", resource[:incl])
+                aug.load
+            end
         end
         @aug
     end
diff --git a/lib/puppet/type/augeas.rb b/lib/puppet/type/augeas.rb
index 4ae3f06..b8d08bb 100644
--- a/lib/puppet/type/augeas.rb
+++ b/lib/puppet/type/augeas.rb
@@ -58,10 +58,15 @@ Puppet::Type.newtype(:augeas) do
     end
 
     newparam (:context) do
-        desc "Optional context path. This value is pre-pended to the paths of all changes if the
-              path is relative. So a path specified as /files/foo will not be prepended with the
-              context whild files/foo will be prepended"
+        desc "Optional context path. This value is prepended to the paths of all changes if the path is relative. If INCL is set, defaults to '/files' + INCL, otherwise the empty string"
         defaultto ""
+        munge do |value|
+            if value.empty? and resource[:incl]
+                "/files" + resource[:incl]
+            else
+                value
+            end
+        end
     end
 
     newparam (:onlyif) do
@@ -129,6 +134,22 @@ Puppet::Type.newtype(:augeas) do
         defaultto :false
     end
 
+    newparam(:lens) do
+        desc "Use a specific lens, e.g. 'Hosts.lns'. When this parameter is set, you must also set the incl parameter to indicate which file to load. Only that file will be loaded, which greatly speeds up execution of the type"
+    end
+
+    newparam(:incl) do
+        desc "Load only a specific file, e.g. '/etc/hosts'.  When this parameter is set, you must also set the lens parameter to indicate which lens to use."
+    end
+
+    validate do
+        has_lens = !self[:lens].nil?
+        has_incl = !self[:incl].nil?
+        if has_lens != has_incl
+            self.fail "You must specify both the lens and incl parameters, or neither"
+        end
+    end
+
     # This is the acutal meat of the code. It forces
     # augeas to be run and fails or not based on the augeas return
     # code.
diff --git a/spec/unit/type/augeas.rb b/spec/unit/type/augeas.rb
index 5276d2c..2c1b044 100644
--- a/spec/unit/type/augeas.rb
+++ b/spec/unit/type/augeas.rb
@@ -103,4 +103,18 @@ describe augeas do
             changes.retrieve.should == :need_to_run
         end
     end
+
+    describe "loading specific files" do
+        it "should require lens when incl is used" do
+            lambda { augeas.new(:name => :no_lens, :incl => "/etc/hosts")}.should raise_error(Puppet::Error)
+        end
+
+        it "should require incl when lens is used" do
+            lambda { augeas.new(:name => :no_incl, :lens => "Hosts.lns") }.should raise_error(Puppet::Error)
+        end
+
+        it "should set the context when a specific file is used" do
+            augeas.new(:name => :no_incl, :lens => "Hosts.lns", :incl => "/etc/hosts")[:context].should == "/files/etc/hosts"
+        end
+    end
 end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list