summaryrefslogtreecommitdiffstats
path: root/lib/puppet
diff options
context:
space:
mode:
authorPaul Berry <paul@puppetlabs.com>2011-02-28 13:13:52 -0800
committerPaul Berry <paul@puppetlabs.com>2011-02-28 13:13:52 -0800
commitecb953646b2defbab3bbc53a58ce7ba98d560b50 (patch)
treec86769e10eade8ffb7bcc6e94299416ac2e709f7 /lib/puppet
parenta949a83c4f100be0254fadcb915f418f73705861 (diff)
parent23a510a321e47a98768dc47f95cfa0bd8c1a314c (diff)
downloadpuppet-ecb953646b2defbab3bbc53a58ce7ba98d560b50.tar.gz
puppet-ecb953646b2defbab3bbc53a58ce7ba98d560b50.tar.xz
puppet-ecb953646b2defbab3bbc53a58ce7ba98d560b50.zip
Merge branch 'ticket/2.6.x/4914' into maint/2.6.next/revert-6309
* ticket/2.6.x/4914: (#4914) Improved stubbing in mount/parsed_spec tests. (#4914) Improved parsed_spec for mount (#4914) Remove mount specs (#4914) Specs for mounted? match new behaviour (#4914) Add specs for modified mount provider (#4914) Add specs for modified mount type (#4914) Update property blocks (#4914) Query property_hash for mountstate (#4914) Prefetch mountstate (#4914) Join lines for better readability Conflicts: lib/puppet/provider/mount.rb lib/puppet/provider/mount/parsed.rb spec/unit/provider/mount/parsed_spec.rb spec/unit/provider/mount_spec.rb spec/unit/type/mount_spec.rb
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/provider/mount.rb28
-rwxr-xr-xlib/puppet/provider/mount/parsed.rb62
-rwxr-xr-xlib/puppet/type/mount.rb55
3 files changed, 107 insertions, 38 deletions
diff --git a/lib/puppet/provider/mount.rb b/lib/puppet/provider/mount.rb
index 354ddb16d..65296eed2 100644
--- a/lib/puppet/provider/mount.rb
+++ b/lib/puppet/provider/mount.rb
@@ -14,8 +14,11 @@ module Puppet::Provider::Mount
args << "-o" << self.options if self.options and self.options != :absent
args << resource[:name]
- flush if respond_to?(:flush)
mountcmd(*args)
+ case get(:ensure)
+ when :absent; set(:ensure => :ghost)
+ when :unmounted; set(:ensure => :mounted)
+ end
end
def remount
@@ -30,24 +33,17 @@ module Puppet::Provider::Mount
# This only works when the mount point is synced to the fstab.
def unmount
- umount resource[:name]
+ umount(resource[:name])
+
+ # Update property hash for future queries (e.g. refresh is called)
+ case get(:ensure)
+ when :mounted; set(:ensure => :unmounted)
+ when :ghost; set(:ensure => :absent)
+ end
end
# Is the mount currently mounted?
def mounted?
- platform = Facter.value("operatingsystem")
- name = resource[:name]
- mounts = mountcmd.split("\n").find do |line|
- case platform
- when "Darwin"
- line =~ / on #{name} / or line =~ %r{ on /private/var/automount#{name}}
- when "Solaris", "HP-UX"
- line =~ /^#{name} on /
- when "AIX"
- line.split(/\s+/)[2] == name
- else
- line =~ / on #{name} /
- end
- end
+ [:mounted, :ghost].include?(get(:ensure))
end
end
diff --git a/lib/puppet/provider/mount/parsed.rb b/lib/puppet/provider/mount/parsed.rb
index 69a6fc06b..42e543c15 100755
--- a/lib/puppet/provider/mount/parsed.rb
+++ b/lib/puppet/provider/mount/parsed.rb
@@ -18,8 +18,7 @@ Puppet::Type.type(:mount).provide(
commands :mountcmd => "mount", :umount => "umount"
- @platform = Facter["operatingsystem"].value
- case @platform
+ case Facter["operatingsystem"]
when "Solaris"
@fields = [:device, :blockdevice, :name, :fstype, :pass, :atboot, :options]
else
@@ -39,4 +38,63 @@ Puppet::Type.type(:mount).provide(
text_line :incomplete, :match => /^(?!#{field_pattern}{#{mandatory_fields.length}})/
record_line self.name, :fields => @fields, :separator => /\s+/, :joiner => "\t", :optional => optional_fields
+
+ # Every entry in fstab is :unmounted until we can prove different
+ def self.prefetch_hook(target_records)
+ target_records.collect do |record|
+ record[:ensure] = :unmounted if record[:record_type] == :parsed
+ record
+ end
+ end
+
+ def self.prefetch(resources = nil)
+ # Get providers for all resources the user defined and that match
+ # a record in /etc/fstab.
+ super
+ # We need to do two things now:
+ # - Update ensure from :unmounted to :mounted if the resource is mounted
+ # - Check for mounted devices that are not in fstab and
+ # set ensure to :ghost (if the user wants to add an entry
+ # to fstab we need to know if the device was mounted before)
+ mountinstances.each do |hash|
+ if mount = resources[hash[:name]]
+ case mount.provider.get(:ensure)
+ when :absent # Mount not in fstab
+ mount.provider.set(:ensure => :ghost)
+ when :unmounted # Mount in fstab
+ mount.provider.set(:ensure => :mounted)
+ end
+ end
+ end
+ end
+
+ def self.mountinstances
+ # XXX: Will not work for mount points that have spaces in path (does fstab support this anyways?)
+ regex = case Facter.value(:operatingsystem)
+ when "Darwin"
+ / on (?:\/private\/var\/automount)?(\S*)/
+ when "Solaris", "HP-UX"
+ /^(\S*) on /
+ when "AIX"
+ /^(?:\S*\s+\S+\s+)(\S+)/
+ else
+ / on (\S*)/
+ end
+ instances = []
+ mount_output = mountcmd.split("\n")
+ if mount_output.length >= 2 and mount_output[1] =~ /^[- \t]*$/
+ # On some OSes (e.g. AIX) mount output begins with a header line
+ # followed by a line consisting of dashes and whitespace.
+ # Discard these two lines.
+ mount_output[0..1] = []
+ end
+ mount_output.each do |line|
+ if match = regex.match(line) and name = match.captures.first
+ instances << {:name => name, :mounted => :yes} # Only :name is important here
+ else
+ raise Puppet::Error, "Could not understand line #{line} from mount output"
+ end
+ end
+ instances
+ end
end
diff --git a/lib/puppet/type/mount.rb b/lib/puppet/type/mount.rb
index da9a70bdf..98a1f2509 100755
--- a/lib/puppet/type/mount.rb
+++ b/lib/puppet/type/mount.rb
@@ -21,6 +21,11 @@ module Puppet
fstab and mount it. Set to `present` to add to fstab but not change
mount/unmount status"
+ # IS -> SHOULD In Sync Action
+ # ghost -> present NO create
+ # absent -> present NO create
+ # (mounted -> present YES)
+ # (unmounted -> present YES)
newvalue(:defined) do
provider.create
return :mount_created
@@ -28,27 +33,48 @@ module Puppet
aliasvalue :present, :defined
+ # IS -> SHOULD In Sync Action
+ # ghost -> unmounted NO create, unmount
+ # absent -> unmounted NO create
+ # mounted -> unmounted NO unmount
newvalue(:unmounted) do
- if provider.mounted?
- syncothers
+ case self.retrieve
+ when :ghost # (not in fstab but mounted)
+ provider.create
+ @resource.flush
provider.unmount
return :mount_unmounted
- else
+ when nil, :absent # (not in fstab and not mounted)
provider.create
return :mount_created
+ when :mounted # (in fstab and mounted)
+ provider.unmount
+ syncothers # I guess it's more likely that the mount was originally mounted with
+ # the wrong attributes so I sync AFTER the umount
+ return :mount_unmounted
+ else
+ raise Puppet::Error, "Unexpected change from #{current_value} to unmounted}"
end
end
+ # IS -> SHOULD In Sync Action
+ # ghost -> absent NO unmount
+ # mounted -> absent NO provider.destroy AND unmount
+ # unmounted -> absent NO provider.destroy
newvalue(:absent, :event => :mount_deleted) do
+ current_value = self.retrieve
provider.unmount if provider.mounted?
-
- provider.destroy
+ provider.destroy unless current_value == :ghost
end
+ # IS -> SHOULD In Sync Action
+ # ghost -> mounted NO provider.create
+ # absent -> mounted NO provider.create AND mount
+ # unmounted -> mounted NO mount
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
+ provider.create if [nil, :absent, :ghost].include?(current_value)
syncothers
@@ -56,27 +82,16 @@ module Puppet
provider.mount unless provider.mounted?
end
+ # insync: mounted -> present
+ # unmounted -> present
def insync?(is)
- if should == :defined and is != :absent
+ if should == :defined and [:mounted,:unmounted].include?(is)
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 :absent
- elsif provider.mounted?
- return :mounted
- else
- return :unmounted
- end
- end
-
def syncothers
# We have to flush any changes to disk.
currentvalues = @resource.retrieve_resource