summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJacob Helwig <jacob@puppetlabs.com>2011-02-17 11:52:45 -0800
committerJacob Helwig <jacob@puppetlabs.com>2011-02-18 15:26:47 -0800
commit6cb365a887d47606bdfae0ff540038b0c49b7451 (patch)
tree9ca7654b76e0a4118480e624dc34e38a656e9783 /lib
parent3b41d44812eed82d41e135375df15ae0bc3b4800 (diff)
(#6309) Ensure the correct device is mounted when managing mounts
Previously the mount type would only check if anything was mounted at the desired point, when 'ensure => mounted' was specified. Now we check not only whether something is mounted at the desired point, but also that it is the thing we wish to be mounted there. There is also a chance that the mount point directory could be "automagically" removed for us, when unmounting incorrect devices, so we attempt to re-create the directory after unmounting to give the mount of the correct device a better chance at succeeding. Paired-with: Matt Robinson <matt@puppetlabs.com> Paired-with: Nick Lewis <nick@puppetlabs.com> Paired-with: Jesse Wolfe <jesse@puppetlabs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/provider/mount.rb48
-rwxr-xr-xlib/puppet/type/mount.rb15
2 files changed, 50 insertions, 13 deletions
diff --git a/lib/puppet/provider/mount.rb b/lib/puppet/provider/mount.rb
index 354ddb16d..81d93b5c1 100644
--- a/lib/puppet/provider/mount.rb
+++ b/lib/puppet/provider/mount.rb
@@ -6,8 +6,28 @@ require 'puppet'
# A module just to store the mount/unmount methods. Individual providers
# still need to add the mount commands manually.
module Puppet::Provider::Mount
- # This only works when the mount point is synced to the fstab.
def mount
+ # Make sure the fstab file & entry exists
+ create
+
+ if correctly_mounted?
+ # Nothing to do!
+ else
+ if anything_mounted?
+ unmount
+
+ # We attempt to create the mount point here, because unmounting
+ # certain file systems/devices can cause the mount point to be
+ # deleted
+ ::FileUtils.mkdir_p(resource[:name])
+ end
+
+ mount!
+ end
+ end
+
+ # This only works when the mount point is synced to the fstab.
+ def mount!
# Manually pass the mount options in, since some OSes *cough*OS X*cough* don't
# read from /etc/fstab but still want to use this type.
args = []
@@ -33,8 +53,8 @@ module Puppet::Provider::Mount
umount resource[:name]
end
- # Is the mount currently mounted?
- def mounted?
+ # Is anything currently mounted at this point?
+ def anything_mounted?
platform = Facter.value("operatingsystem")
name = resource[:name]
mounts = mountcmd.split("\n").find do |line|
@@ -42,6 +62,7 @@ module Puppet::Provider::Mount
when "Darwin"
line =~ / on #{name} / or line =~ %r{ on /private/var/automount#{name}}
when "Solaris", "HP-UX"
+ # Yes, Solaris does list mounts as "mount_point on device"
line =~ /^#{name} on /
when "AIX"
line.split(/\s+/)[2] == name
@@ -50,4 +71,25 @@ module Puppet::Provider::Mount
end
end
end
+
+ # Is the desired thing mounted at this point?
+ def correctly_mounted?
+ platform = Facter.value("operatingsystem")
+ name = resource[:name]
+ device = resource[:device]
+ mounts = mountcmd.split("\n").find do |line|
+ case platform
+ when "Darwin"
+ line =~ /^#{device} on #{name} / or line =~ %r{^#{device} on /private/var/automount#{name}}
+ when "Solaris", "HP-UX"
+ # Yes, Solaris does list mounts as "mount_point on device"
+ line =~ /^#{name} on #{device}/
+ when "AIX"
+ line.split(/\s+/)[2] == name &&
+ line.split(/\s+/)[1] == device
+ else
+ line =~ /^#{device} on #{name} /
+ end
+ end
+ end
end
diff --git a/lib/puppet/type/mount.rb b/lib/puppet/type/mount.rb
index da9a70bdf..10eed5373 100755
--- a/lib/puppet/type/mount.rb
+++ b/lib/puppet/type/mount.rb
@@ -29,7 +29,7 @@ module Puppet
aliasvalue :present, :defined
newvalue(:unmounted) do
- if provider.mounted?
+ if provider.anything_mounted?
syncothers
provider.unmount
return :mount_unmounted
@@ -40,20 +40,15 @@ module Puppet
end
newvalue(:absent, :event => :mount_deleted) do
- provider.unmount if provider.mounted?
+ provider.unmount if provider.anything_mounted?
provider.destroy
end
newvalue(:mounted, :event => :mount_mounted) do
- # Create the mount point if it does not already exist.
- current_value = self.retrieve
- provider.create if current_value.nil? or current_value == :absent
-
syncothers
- # The fs can be already mounted if it was absent but mounted
- provider.mount unless provider.mounted?
+ provider.mount
end
def insync?(is)
@@ -70,7 +65,7 @@ module Puppet
curval = super()
if curval == :absent
return :absent
- elsif provider.mounted?
+ elsif provider.correctly_mounted?
return :mounted
else
return :unmounted
@@ -210,7 +205,7 @@ module Puppet
def refresh
# Only remount if we're supposed to be mounted.
- provider.remount if self.should(:fstype) != "swap" and provider.mounted?
+ provider.remount if self.should(:fstype) != "swap" and provider.anything_mounted?
end
def value(name)