From 1f3b8e755883c865026f3d76459000b808f5a3b0 Mon Sep 17 00:00:00 2001 From: Stefan Schulte Date: Sun, 1 May 2011 15:19:33 +0200 Subject: (#7300) Add specs for the mount provider Add specs to demonstrate that the instances method is currently broken because it does not take the actual mountstate into account. As a result running "puppet resource mount" on the commandline will report every mount that appears in /etc/(v)fstab as unmounted. --- spec/unit/provider/mount/parsed_spec.rb | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/spec/unit/provider/mount/parsed_spec.rb b/spec/unit/provider/mount/parsed_spec.rb index 0293e0758..2e1e1e92e 100755 --- a/spec/unit/provider/mount/parsed_spec.rb +++ b/spec/unit/provider/mount/parsed_spec.rb @@ -193,6 +193,47 @@ FSTAB my_fixtures('*.fstab').each do |fstab| platform = File.basename(fstab, '.fstab') + + describe "when calling instances on #{platform}" do + before :each do + if Facter[:operatingsystem] == "Solaris" then + platform == 'solaris' or + pending "We need to stub the operatingsystem fact at load time, but can't" + else + platform != 'solaris' or + pending "We need to stub the operatingsystem fact at load time, but can't" + end + + # Stub the mount output to our fixture. + begin + mount = my_fixture(platform + '.mount') + @provider.stubs(:mountcmd).returns File.read(mount) + rescue + pending "is #{platform}.mount missing at this point?" + end + + # Note: we have to stub default_target before creating resources + # because it is used by Puppet::Type::Mount.new to populate the + # :target property. + @provider.stubs(:default_target).returns fstab + @retrieve = @provider.instances.collect { |prov| {:name => prov.get(:name), :ensure => prov.get(:ensure)}} + end + + # Following mountpoint are present in all fstabs/mountoutputs + it "should include unmounted resources" do + @retrieve.should include(:name => '/', :ensure => :mounted) + end + + it "should include mounted resources" do + @retrieve.should include(:name => '/boot', :ensure => :unmounted) + end + + it "should include ghost resources" do + @retrieve.should include(:name => '/ghost', :ensure => :ghost) + end + + end + describe "when prefetching on #{platform}" do before :each do if Facter[:operatingsystem] == "Solaris" then -- cgit From 0b8ebaccfef829856720c29c3bc00c042a515c71 Mon Sep 17 00:00:00 2001 From: Stefan Schulte Date: Sun, 1 May 2011 15:22:17 +0200 Subject: (#7300) Fix instances method of mount provider The instance method now behaves like the prefetch method: After parsing /etc/(v)fstab run mount to update the ensure state from either :unmounted to :mounted and from :absent to :ghost Reviewed-By: Nick Lewis Reviewed-By: Josh Cooper --- lib/puppet/provider/mount/parsed.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/puppet/provider/mount/parsed.rb b/lib/puppet/provider/mount/parsed.rb index 11c5e21a9..13613a974 100755 --- a/lib/puppet/provider/mount/parsed.rb +++ b/lib/puppet/provider/mount/parsed.rb @@ -47,6 +47,24 @@ Puppet::Type.type(:mount).provide( end end + def self.instances + providers = super + mounts = mountinstances.dup + + # Update fstab entries that are mounted + providers.each do |prov| + if mounts.delete({:name => prov.get(:name), :mounted => :yes}) then + prov.set(:ensure => :mounted) + end + end + + # Add mounts that are not in fstab but mounted + mounts.each do |mount| + providers << new(:ensure => :ghost, :name => mount[:name]) + end + providers + end + def self.prefetch(resources = nil) # Get providers for all resources the user defined and that match # a record in /etc/fstab. -- cgit