On Oct 29, 2009, at 11:02 AM, Aurelien Degremont wrote:

>
> Hello
>
> This patch add a new ensure value for Mount type.
> It ables to define a mount which will be added to fstab but do not  
> require to have it
> mounted or not. This is not managed by Puppet. It just ensures the  
> line is in fstab.
>
>
> ---
>  lib/puppet/type/mount.rb |   14 +++++++++++++-
>  spec/unit/type/mount.rb  |   10 ++++++++++
>  2 files changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/lib/puppet/type/mount.rb b/lib/puppet/type/mount.rb
> index fb9a9ef..f0bb082 100755
> --- a/lib/puppet/type/mount.rb
> +++ b/lib/puppet/type/mount.rb
> @@ -19,7 +19,11 @@ module Puppet
>                  but not mounted (if the filesystem is currently  
> mounted, it will be
>                  unmounted).  Set it to ``absent`` to unmount (if  
> necessary) and remove
>                  the filesystem from the fstab.  Set to ``mounted``  
> to add it to the
> -                fstab and mount it."
> +                fstab and mount it. Set to ``defined`` to only add  
> it to the fstab."
> +
> +            newvalue(:defined) do
> +                provider.create
> +            end
>
>              newvalue(:present) do
>                  if provider.mounted?
>
> @@ -65,6 +69,14 @@ module Puppet
>                  end
>              end
>
> +            def insync?(current)
> +                if should == :defined
> +                    return [:mounted, :present].include?(current)
> +                else
> +                    return should == current
> +                end
> +            end
> +
>              def syncothers
>                  # We have to flush any changes to disk.
>                  currentvalues = @resource.retrieve
> diff --git a/spec/unit/type/mount.rb b/spec/unit/type/mount.rb
> index fd9c6cb..dbcf5ea 100755
> --- a/spec/unit/type/mount.rb
> +++ b/spec/unit/type/mount.rb
> @@ -49,6 +49,10 @@ describe Puppet::Type.type(:mount)::Ensure, "when  
> validating values" do
>      it "should support :mounted as a value to :ensure" do
>          Puppet::Type.type(:mount).new(:name => "yay", :ensure  
> => :mounted)
>      end
> +
> +    it "should support :defined as a value to :ensure" do
> +        Puppet::Type.type(:mount).new(:name => "yay", :ensure  
> => :defined)
> +    end
>  end
>
>  describe Puppet::Type.type(:mount)::Ensure do
> @@ -91,6 +95,12 @@ describe Puppet::Type.type(:mount)::Ensure do
>              @provider.expects(:mounted?).returns(false)
>              @ensure.retrieve.should == :present
>          end
> +
> +        it "should return :defined if the provider's value is not  
> absent and should be
> :defined" do
> +            @provider.expects(:ensure).returns(:defined)
> +            @provider.expects(:mounted?)
> +            @ensure.retrieve.should == :defined
> +        end
>      end

This test isn't really a valid test, I think, and you're missing at  
least one other test.

The test isn't really valid because the provider can't ever actually  
return :defined as a value (at least, not without a patch).  The  
'insync?' changes you've provided are sufficient to provide the  
correct behaviour.

That being said, you haven't provided a test for 'insync?'.  Something  
like these should work:

   it "should be considered in sync if 'should' is 'defined' and the  
current value is 'present'"

   it "should be considered in sync if 'should' is 'defined' and the  
current value is 'mounted'"

   it "should not be considered in sync if 'should' is 'defined' and  
the current value is 'absent'"

-- 
It's not the voting that's democracy, it's the counting.
     -- Tom Stoppard
---------------------------------------------------------------------
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to