summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorJacob Helwig <jacob@puppetlabs.com>2011-02-18 15:33:29 -0800
committerJacob Helwig <jacob@puppetlabs.com>2011-02-18 15:33:29 -0800
commit7e611714c56e3e28ff2077a024498acd26da0604 (patch)
tree3af24fe0cb0ee06070a317fa65a63de4d0b0bcb5 /lib/puppet
parent652971c48f2f4fd8515bc1d34f1ac00aac8449a9 (diff)
parente85420585158ab1a74727efcff449190f6d84899 (diff)
downloadpuppet-7e611714c56e3e28ff2077a024498acd26da0604.tar.gz
puppet-7e611714c56e3e28ff2077a024498acd26da0604.tar.xz
puppet-7e611714c56e3e28ff2077a024498acd26da0604.zip
Merge branch 'tickets/2.6.x/6309-check-what-is-mounted' into 2.6.next
* tickets/2.6.x/6309-check-what-is-mounted: Remove pending tests from parsed mount provider (#6309) Ensure the correct device is mounted when managing mounts Clean up whitespace, and commented out code in parsed mount provider
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/provider/mount.rb48
-rwxr-xr-xlib/puppet/provider/mount/parsed.rb9
-rwxr-xr-xlib/puppet/type/mount.rb15
3 files changed, 52 insertions, 20 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/provider/mount/parsed.rb b/lib/puppet/provider/mount/parsed.rb
index 82d1628bd..69a6fc06b 100755
--- a/lib/puppet/provider/mount/parsed.rb
+++ b/lib/puppet/provider/mount/parsed.rb
@@ -8,16 +8,13 @@ else
fstab = "/etc/fstab"
end
-
- Puppet::Type.type(:mount).provide(
- :parsed,
+Puppet::Type.type(:mount).provide(
+ :parsed,
:parent => Puppet::Provider::ParsedFile,
:default_target => fstab,
-
:filetype => :flat
) do
include Puppet::Provider::Mount
- #confine :exists => fstab
commands :mountcmd => "mount", :umount => "umount"
@@ -42,6 +39,4 @@ end
text_line :incomplete, :match => /^(?!#{field_pattern}{#{mandatory_fields.length}})/
record_line self.name, :fields => @fields, :separator => /\s+/, :joiner => "\t", :optional => optional_fields
-
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)