diff options
-rw-r--r-- | lib/puppet/provider/mount.rb | 3 | ||||
-rwxr-xr-x | test/ral/providers/mount/parsed.rb | 113 |
2 files changed, 71 insertions, 45 deletions
diff --git a/lib/puppet/provider/mount.rb b/lib/puppet/provider/mount.rb index 89b769726..446ed641c 100644 --- a/lib/puppet/provider/mount.rb +++ b/lib/puppet/provider/mount.rb @@ -16,6 +16,9 @@ module Puppet::Provider::Mount end args << @resource[:name] + if respond_to?(:flush) + flush + end mountcmd(*args) end diff --git a/test/ral/providers/mount/parsed.rb b/test/ral/providers/mount/parsed.rb index e5d8669e7..9637a840f 100755 --- a/test/ral/providers/mount/parsed.rb +++ b/test/ral/providers/mount/parsed.rb @@ -2,11 +2,12 @@ $:.unshift("../../../lib") if __FILE__ =~ /\.rb$/ +require 'mocha' require 'puppettest' require 'puppettest/fileparsing' require 'facter' -class TestParsedMounts < Test::Unit::TestCase +module MountTesting include PuppetTest include PuppetTest::FileParsing @@ -25,6 +26,20 @@ class TestParsedMounts < Test::Unit::TestCase super end + def fake_fstab + os = Facter['operatingsystem'] + if os == "Solaris" + name = "solaris.fstab" + elsif os == "FreeBSD" + name = "freebsd.fstab" + else + # Catchall for other fstabs + name = "linux.fstab" + end + oldpath = @provider.default_target + return fakefile(File::join("data/types/mount", name)) + end + def mkmountargs mount = nil @@ -67,6 +82,10 @@ class TestParsedMounts < Test::Unit::TestCase def mkfaketype @provider.filetype = Puppet::Util::FileType.filetype(:ram) end +end + +class TestParsedMounts < Test::Unit::TestCase + include MountTesting def test_default_target should = case Facter.value(:operatingsystem) @@ -113,45 +132,64 @@ class TestParsedMounts < Test::Unit::TestCase assert_equal(5, mount.dump, "did not flush change to disk") end - unless Facter["operatingsystem"].value == "Darwin" - def test_mountsparse - tab = fake_fstab - fakedataparse(tab) do - # Now just make we've got some mounts we know will be there - hashes = @provider.target_records(tab).find_all { |i| i.is_a? Hash } - assert(hashes.length > 0, "Did not create any hashes") - root = hashes.find { |i| i[:name] == "/" } - assert(root, "Could not retrieve root mount") - - assert_nothing_raised("Could not rewrite file") do - @provider.to_file(hashes) - end + # #730 - Make sure 'flush' is called when a mount is moving from absent to mounted + def test_flush_when_mounting_absent_fs + @provider.filetype = :ram + mount = mkmount + + mount.expects(:flush) + mount.expects(:mountcmd) # just so we don't actually try to mount anything + mount.mount + end +end + +class TestParsedMountsNonDarwin < PuppetTest::TestCase + confine "Mount type not tested on Darwin" => Facter["operatingsystem"].value != "Darwin" + include MountTesting + + def test_mountsparse + tab = fake_fstab + fakedataparse(tab) do + # Now just make we've got some mounts we know will be there + hashes = @provider.target_records(tab).find_all { |i| i.is_a? Hash } + assert(hashes.length > 0, "Did not create any hashes") + root = hashes.find { |i| i[:name] == "/" } + assert(root, "Could not retrieve root mount") + + assert_nothing_raised("Could not rewrite file") do + @provider.to_file(hashes) end end + end - def test_rootfs - fs = nil - type = @mount.create :name => "/" + def test_rootfs + fs = nil + type = @mount.create :name => "/" - provider = type.provider + provider = type.provider - assert(FileTest.exists?(@provider.default_target), - "FSTab %s does not exist" % @provider.default_target) + assert(FileTest.exists?(@provider.default_target), + "FSTab %s does not exist" % @provider.default_target) - assert_nothing_raised do - @provider.prefetch("/" => type) - end + assert_nothing_raised do + @provider.prefetch("/" => type) + end - assert_equal(:present, type.provider.property_hash[:ensure], - "Could not find root fs with provider %s" % provider.class.name) + assert_equal(:present, type.provider.property_hash[:ensure], + "Could not find root fs with provider %s" % provider.class.name) - assert_nothing_raised { - assert(provider.mounted?, "Root is considered not mounted") - } - end + assert_nothing_raised { + assert(provider.mounted?, "Root is considered not mounted") + } end +end + +class TestParsedMountsNonDarwinAsRoot < PuppetTest::TestCase + confine "Mount type not tested on Darwin" => Facter["operatingsystem"].value != "Darwin" + confine "Not running as root" => Puppet.features.root? + + include MountTesting - if Puppet.features.root? and Facter.value(:operatingsystem) != "Darwin" def test_mountfs fs = nil case Facter.value(:hostname) @@ -208,21 +246,6 @@ class TestParsedMounts < Test::Unit::TestCase obj.remount end end - end - - def fake_fstab - os = Facter['operatingsystem'] - if os == "Solaris" - name = "solaris.fstab" - elsif os == "FreeBSD" - name = "freebsd.fstab" - else - # Catchall for other fstabs - name = "linux.fstab" - end - oldpath = @provider.default_target - return fakefile(File::join("data/types/mount", name)) - end end # $Id$ |