On Oct 6, 2009, at 11:40 AM, David Lutterkort wrote:
>
> 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
> ---
> lib/puppet/provider/augeas/augeas.rb | 7 +++++++
> lib/puppet/type/augeas.rb | 27 +++++++++++++++++++++++
> +---
> spec/unit/type/augeas.rb | 14 ++++++++++++++
> 3 files changed, 45 insertions(+), 3 deletions(-)
>
> 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
I'm not confident the behaviour matches the docs. It'd be nice to see
a couple of nices proving that this behaves appropriately.
>
> 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
> --
> 1.6.2.5
>
>
> >
--
Never interrupt your enemy when he is making a mistake.
--Napolean Bonaparte
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---