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

Markus Roberts Markus at reality.com
Wed Jul 14 10:36:52 UTC 2010


The following commit has been merged in the upstream branch:
commit 1715f3af5db3459c373358fe5ab1ab3b793f7045
Author: Jesse Wolfe <jes5199 at gmail.com>
Date:   Thu Jul 8 16:43:13 2010 -0700

    [#2730] mount ensure present shouldn't unmount
    
    Ensuring "defined" on a mount just demands that the entry appears in the
    fstab file.
    Ensure "present" is now an alias for ensure "defined", so drives are no
    longer unmounted unless the resource is set to ensure "unmounted"
    
    This patch is based on a patch submitted by Aurelien Degremont.

diff --git a/lib/puppet/type/mount.rb b/lib/puppet/type/mount.rb
index ea4b94f..64ba22b 100755
--- a/lib/puppet/type/mount.rb
+++ b/lib/puppet/type/mount.rb
@@ -15,13 +15,21 @@ module Puppet
         # call code when sync() is called.
         newproperty(:ensure) do
             desc "Control what to do with this mount. Set this attribute to
-                ``present`` to make sure the filesystem is in the filesystem table
+                ``umounted`` to make sure the filesystem is in the filesystem table
                 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 ``present`` to add to fstab but not change
+                mount/unmount status"
 
-            newvalue(:present) do
+            newvalue(:defined) do
+                provider.create
+                return :mount_created
+            end
+
+            aliasvalue :present, :defined
+            
+            newvalue(:unmounted) do
                 if provider.mounted?
                     syncothers()
                     provider.unmount
@@ -31,7 +39,6 @@ module Puppet
                     return :mount_created
                 end
             end
-            aliasvalue :unmounted, :present
 
             newvalue(:absent, :event => :mount_deleted) do
                 if provider.mounted?
@@ -52,16 +59,24 @@ module Puppet
                 provider.mount unless provider.mounted?
             end
 
+            def insync?(is)
+                if should == :defined and is != :absent
+                    true
+                else
+                    super
+                end
+            end
+
             def retrieve
                 # We need to special case :mounted; if we're absent, we still
                 # want
                 curval = super()
                 if curval == :absent
-                    return curval
+                    return :absent
                 elsif provider.mounted?
                     return :mounted
                 else
-                    return curval
+                    return :unmounted
                 end
             end
 
diff --git a/spec/unit/type/mount_spec.rb b/spec/unit/type/mount_spec.rb
index c9622fd..0cf52e8 100755
--- a/spec/unit/type/mount_spec.rb
+++ b/spec/unit/type/mount_spec.rb
@@ -33,13 +33,14 @@ describe Puppet::Type.type(:mount)::Ensure, "when validating values" do
         Puppet::Type.type(:mount).defaultprovider.expects(:new).returns(@provider)
     end
 
-    it "should support :present as a value to :ensure" do
-        Puppet::Type.type(:mount).new(:name => "yay", :ensure => :present)
+    it "should alias :present to :defined as a value to :ensure" do
+        mount = Puppet::Type.type(:mount).new(:name => "yay", :ensure => :present)
+        mount.should(:ensure).should == :defined
     end
 
-    it "should alias :unmounted to :present as a value to :ensure" do
+    it "should support :unmounted as a value to :ensure" do
         mount = Puppet::Type.type(:mount).new(:name => "yay", :ensure => :unmounted)
-        mount.should(:ensure).should == :present
+        mount.should(:ensure).should == :unmounted
     end
 
     it "should support :absent as a value to :ensure" do
@@ -86,10 +87,10 @@ describe Puppet::Type.type(:mount)::Ensure do
             @ensure.retrieve.should == :mounted
         end
 
-        it "should return :present if the provider indicates it is not mounted and the value is not :absent" do
+        it "should return :unmounted if the provider indicates it is not mounted and the value is not :absent" do
             @provider.expects(:ensure).returns(:present)
             @provider.expects(:mounted?).returns(false)
-            @ensure.retrieve.should == :present
+            @ensure.retrieve.should == :unmounted
         end
     end
 
@@ -110,20 +111,46 @@ describe Puppet::Type.type(:mount)::Ensure do
             @ensure.sync
         end
 
-        it "should create itself if it is absent and should be present" do
+        it "should create itself if it is absent and should be defined" do
+            @provider.stubs(:ensure).returns(:absent)
+            @provider.stubs(:mounted?).returns(true)
+
             @provider.stubs(:mounted?).returns(false)
             @provider.expects(:create)
+            @ensure.should = :defined
+            @ensure.sync
+        end
+        
+        it "should not unmount itself if it is mounted and should be defined" do
+            @provider.stubs(:ensure).returns(:mounted)
+            @provider.stubs(:mounted?).returns(true)
+
+            @provider.stubs(:create)
+            @provider.expects(:mount).never
+            @provider.expects(:unmount).never
+            @ensure.should = :defined
+            @ensure.sync
+        end
+        
+        it "should not mount itself if it is unmounted and should be defined" do
+            @provider.stubs(:ensure).returns(:unmounted)
+            @provider.stubs(:mounted?).returns(false)
+
+            @ensure.stubs(:syncothers)
+            @provider.stubs(:create)
+            @provider.expects(:mount).never
+            @provider.expects(:unmount).never
             @ensure.should = :present
             @ensure.sync
         end
 
-        it "should unmount itself if it is mounted and should be present" do
+        it "should unmount itself if it is mounted and should be unmounted" do
+            @provider.stubs(:ensure).returns(:present)
             @provider.stubs(:mounted?).returns(true)
 
-            # The interface here is just too much work to test right now.
             @ensure.stubs(:syncothers)
             @provider.expects(:unmount)
-            @ensure.should = :present
+            @ensure.should = :unmounted
             @ensure.sync
         end
 
@@ -154,6 +181,26 @@ describe Puppet::Type.type(:mount)::Ensure do
             @ensure.should = :mounted
             @ensure.sync
         end
+
+        it "should be insync if it is mounted and should be defined" do
+            @ensure.should = :defined
+            @ensure.insync?(:mounted).should == true
+        end
+        
+        it "should be insync if it is unmounted and should be defined" do
+            @ensure.should = :defined
+            @ensure.insync?(:unmounted).should == true
+        end
+
+        it "should be insync if it is mounted and should be present" do
+            @ensure.should = :present
+            @ensure.insync?(:mounted).should == true
+        end
+        
+        it "should be insync if it is unmounted and should be present" do
+            @ensure.should = :present
+            @ensure.insync?(:unmounted).should == true
+        end
     end
 
     describe Puppet::Type.type(:mount), "when responding to events" do

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list