diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-05 01:03:57 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-09-05 01:03:57 +0000 |
| commit | b43b489073beb01da9b4de501d3c019326d97961 (patch) | |
| tree | 58264a9554ca1e71f5441fb3703fb798cb71a6eb /test | |
| parent | 639ed3d75380dc59e05bb38c920f18836fd12913 (diff) | |
| download | puppet-b43b489073beb01da9b4de501d3c019326d97961.tar.gz puppet-b43b489073beb01da9b4de501d3c019326d97961.tar.xz puppet-b43b489073beb01da9b4de501d3c019326d97961.zip | |
Committing functional mount support. All that's left in this chunk of work is cron.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1552 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
| -rw-r--r-- | test/data/types/mount/linux.fstab | 2 | ||||
| -rwxr-xr-x | test/providers/parsedmount.rb | 220 | ||||
| -rwxr-xr-x | test/providers/parsedport.rb | 21 | ||||
| -rw-r--r-- | test/puppettest.rb | 29 | ||||
| -rwxr-xr-x | test/types/mount.rb | 272 |
5 files changed, 318 insertions, 226 deletions
diff --git a/test/data/types/mount/linux.fstab b/test/data/types/mount/linux.fstab index 06afe1242..978103b69 100644 --- a/test/data/types/mount/linux.fstab +++ b/test/data/types/mount/linux.fstab @@ -4,7 +4,7 @@ LABEL=/boot /boot ext3 defaults 1 2 devpts /dev/pts devpts gid=5,mode=620 0 0 tmpfs /dev/shm tmpfs defaults 0 0 LABEL=/home /home ext3 defaults 1 2 -/home /homes auto bind +/home /homes auto bind 0 2 proc /proc proc defaults 0 0 /dev/vg00/lv01 /spare ext3 defaults 1 2 sysfs /sys sysfs defaults 0 0 diff --git a/test/providers/parsedmount.rb b/test/providers/parsedmount.rb new file mode 100755 index 000000000..a1630f7be --- /dev/null +++ b/test/providers/parsedmount.rb @@ -0,0 +1,220 @@ +if __FILE__ == $0 + $:.unshift '..' + $:.unshift '../../lib' + $puppetbase = "../.." +end + +require 'puppettest' +require 'puppet' +require 'test/unit' +require 'facter' + +class TestParsedMounts < Test::Unit::TestCase + include TestPuppet + + def setup + super + @provider = Puppet.type(:mount).provider(:parsed) + + @oldfiletype = @provider.filetype + end + + def teardown + Puppet::FileType.filetype(:ram).clear + @provider.filetype = @oldfiletype + super + end + + def mkmountargs + mount = nil + + if defined? @pcount + @pcount += 1 + else + @pcount = 1 + end + args = { + :path => "/fspuppet%s" % @pcount, + :device => "/dev/dsk%s" % @pcount, + } + + @provider.fields.each do |field| + unless args.include? field + args[field] = "fake%s" % @pcount + end + end + + return args + end + + def mkmount + hash = mkmountargs() + #hash[:provider] = @provider.name + + fakemodel = fakemodel(:mount, hash[:name]) + + mount = @provider.new(fakemodel) + #mount = Puppet.type(:mount).create(hash) + + hash.each do |name, val| + fakemodel[name] = val + end + assert(mount, "Could not create provider mount") + + return mount + end + + # Here we just create a fake host type that answers to all of the methods + # but does not modify our actual system. + def mkfaketype + @provider.filetype = Puppet::FileType.filetype(:ram) + end + + def test_simplemount + mkfaketype + assert_nothing_raised { + assert_equal([], @provider.retrieve) + } + + # Now create a provider + mount = nil + assert_nothing_raised { + mount = mkmount + } + + # Make sure we're still empty + assert_nothing_raised { + assert_equal([], @provider.retrieve) + } + + hash = mount.model.to_hash + + if hash.has_key? :name + hash.delete :name + end + + # Try storing it + assert_nothing_raised do + mount.store(hash) + end + + # Make sure we get the mount back + assert_nothing_raised { + assert_equal([hash], @provider.retrieve) + } + + # Now remove the whole object + assert_nothing_raised { + mount.store({}) + assert_equal([], @provider.retrieve) + } + end + + unless Facter["operatingsystem"].value == "Darwin" + def test_mountsparse + fakedataparse(fake_fstab) do + # Now just make we've got some mounts we know will be there + hashes = @provider.retrieve.find_all { |i| i.is_a? Hash } + assert(hashes.length > 0, "Did not create any hashes") + root = hashes.find { |i| i[:path] == "/" } + assert(root, "Could not retrieve root mount") + end + end + + def test_rootfs + fs = nil + @provider.path = fake_fstab() + fakemodel = fakemodel(:mount, "/") + mount = @provider.new(fakemodel) + mount.model[:path] = "/" + assert(mount.hash, "Could not retrieve root fs") + + assert_nothing_raised { + assert(mount.mounted?, "Root is considered not mounted") + } + end + end + + if Process.uid == 0 + def test_mountfs + fs = nil + case Facter["hostname"].value + when "culain": fs = "/ubuntu" + when "atalanta": fs = "/mnt" + when "figurehead": fs = "/cg4/net/depts" + else + $stderr.puts "No mount for mount testing; skipping" + return + end + + oldtext = @provider.fileobj.read + + ftype = @provider.filetype + + # Make sure the original gets reinstalled. + if ftype == Puppet::FileType.filetype(:netinfo) + cleanup do + IO.popen("niload -r /mounts .", "w") do |file| + file.puts oldtext + end + end + else + cleanup do + @provider.fileobj.write(oldtext) + end + end + + fakemodel = fakemodel(:mount, "/") + obj = @provider.new(fakemodel) + obj.model[:path] = fs + + current = nil + + assert_nothing_raised { + current = obj.mounted? + } + + if current + # Make sure the original gets reinstalled. + cleanup do + unless obj.mounted? + obj.mount + end + end + end + + unless current + assert_nothing_raised { + obj.mount + } + end + + assert_nothing_raised { + obj.unmount + } + assert(! obj.mounted?, "FS still mounted") + assert_nothing_raised { + obj.mount + } + assert(obj.mounted?, "FS not mounted") + + 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.path + cleanup do @provider.path = oldpath end + return fakefile(File::join("data/types/mount", name)) + end +end + +# $Id$ diff --git a/test/providers/parsedport.rb b/test/providers/parsedport.rb index e1fa4457b..51901f7f4 100755 --- a/test/providers/parsedport.rb +++ b/test/providers/parsedport.rb @@ -56,27 +56,6 @@ class TestParsedPort < Test::Unit::TestCase assert_equal(text.gsub(/\s+/, ' '), newtext.gsub(/\s+/, ' ')) end end - - def disabled_test_portsparse - fakedata("data/types/ports").each { |file| - @porttype.path = file - Puppet.info "Parsing %s" % file - assert_nothing_raised { - @porttype.retrieve - } - - # Now just make we've got some ports we know will be there - dns = @porttype["domain"] - assert(dns, "Could not retrieve DNS port") - - assert_equal("53", dns.is(:number), "DNS number was wrong") - %w{udp tcp}.each { |v| - assert(dns.is(:protocols).include?(v), "DNS did not include proto %s" % v) - } - - @porttype.clear - } - end end # $Id$ diff --git a/test/puppettest.rb b/test/puppettest.rb index 5056f2d40..2506f9fc3 100644 --- a/test/puppettest.rb +++ b/test/puppettest.rb @@ -80,6 +80,33 @@ module TestPuppet def initialize(model) @model = model end + + # Called in Type#remove + def remove(var = true) + end + end + + class FakeParsedProvider < FakeProvider + def hash + ret = {} + instance_variables.each do |v| + v = v.sub("@", '') + if val = self.send(v) + ret[v.intern] = val + end + end + + return ret + end + + def store(hash) + hash.each do |n, v| + method = n.to_s + "=" + if respond_to? method + send(method, v) + end + end + end end @@fakemodels = {} @@ -450,6 +477,8 @@ module TestPuppet text = @provider.fileobj.read + yield if block_given? + dest = tempfile() @provider.path = dest diff --git a/test/types/mount.rb b/test/types/mount.rb index 70170289e..c7bd378a9 100755 --- a/test/types/mount.rb +++ b/test/types/mount.rb @@ -8,40 +8,63 @@ end require 'puppettest' require 'puppet' -require 'puppet/type/parsedtype/mount' require 'test/unit' -require 'facter' class TestMounts < Test::Unit::TestCase include TestPuppet + + p = Puppet::Type.type(:mount).provide :fake, :parent => TestPuppet::FakeParsedProvider do + @name = :fake + apimethods :ensure + + attr_accessor :mounted + + def create + @ensure = :present + end + + def delete + @ensure = :absent + @mounted = false + end + + def exists? + if defined? @ensure and @ensure == :present + true + else + false + end + end + + def mounted? + self.mounted + end + + def mount + self.mounted = true + end + + def unmount + self.mounted = false + end + end + + FakeMountProvider = p + + @@fakeproviders[:mount] = p + def setup super - @mounttype = Puppet.type(:mount) - @oldfiletype = @mounttype.filetype + @realprovider = Puppet::Type.type(:mount).defaultprovider + Puppet::Type.type(:mount).defaultprovider = FakeMountProvider end def teardown - @mounttype.filetype = @oldfiletype - Puppet.type(:file).clear + Puppet.type(:mount).clear + Puppet::Type.type(:mount).defaultprovider = nil super end - # Here we just create a fake host type that answers to all of the methods - # but does not modify our actual system. - def mkfaketype - pfile = tempfile() - old = @mounttype.filetype - @mounttype.filetype = Puppet::FileType.filetype(:ram) - - cleanup do - @mounttype.filetype = old - @mounttype.fileobj = nil - end - - # Reset this, just in case - @mounttype.fileobj = nil - end - def mkmount mount = nil @@ -55,7 +78,7 @@ class TestMounts < Test::Unit::TestCase :device => "/dev/dsk%s" % @pcount, } - Puppet.type(:mount).fields.each do |field| + @realprovider.fields.each do |field| unless args.include? field args[field] = "fake%s" % @pcount end @@ -69,178 +92,47 @@ class TestMounts < Test::Unit::TestCase end def test_simplemount - mkfaketype - host = nil - assert_nothing_raised { - assert_nil(Puppet.type(:mount).retrieve) - } - - mount = mkmount - - assert_nothing_raised { - Puppet.type(:mount).store - } - + mount = nil + oldprv = Puppet.type(:mount).defaultprovider + Puppet.type(:mount).defaultprovider = nil assert_nothing_raised { - assert( - Puppet.type(:mount).to_file.include?( - Puppet.type(:mount).fileobj.read - ), - "File does not include all of our objects" - ) - } - end - - unless Facter["operatingsystem"].value == "Darwin" - def test_mountsparse - use_fake_fstab - assert_nothing_raised { - @mounttype.retrieve - } - - # Now just make we've got some mounts we know will be there - root = @mounttype["/"] - assert(root, "Could not retrieve root mount") - end + Puppet.type(:mount).defaultprovider.retrieve - def test_rootfs - fs = nil - use_fake_fstab - assert_nothing_raised { - Puppet.type(:mount).retrieve - } - - assert_nothing_raised { - fs = Puppet.type(:mount)["/"] - } - assert(fs, "Could not retrieve root fs") - - assert_nothing_raised { - assert(fs.mounted?, "Root is considered not mounted") - } - end - end + count = 0 + Puppet.type(:mount).each do |h| + count += 1 + end - # Make sure it reads and writes correctly. - def test_readwrite - use_fake_fstab - assert_nothing_raised { - Puppet::Type.type(:mount).retrieve + assert_equal(0, count, "Found mounts in empty file somehow") } + Puppet.type(:mount).defaultprovider = oldprv - oldtype = Puppet::Type.type(:mount).filetype - - # Now switch to storing in ram - mkfaketype - - fs = mkmount - - assert(Puppet::Type.type(:mount).filetype != oldtype) - - assert_events([:mount_created], fs) - - text = Puppet::Type.type(:mount).fileobj.read - - assert(text =~ /#{fs[:path]}/, "Text did not include new fs") - - fs[:ensure] = :absent - - assert_events([:mount_removed], fs) - text = Puppet::Type.type(:mount).fileobj.read - - assert(text !~ /#{fs[:path]}/, "Text still includes new fs") - - fs[:ensure] = :present - - assert_events([:mount_created], fs) - - text = Puppet::Type.type(:mount).fileobj.read + mount = mkmount - assert(text =~ /#{fs[:path]}/, "Text did not include new fs") + assert_apply(mount) - fs[:options] = "rw,noauto" + assert_nothing_raised { mount.retrieve } - assert_events([:mount_changed], fs) + assert_equal(:mounted, mount.is(:ensure)) end - if Process.uid == 0 + # Make sure fs mounting behaves appropriately. This is more a test of + # whether things get mounted and unmounted based on the value of 'ensure'. def test_mountfs - fs = nil - case Facter["hostname"].value - when "culain": fs = "/ubuntu" - when "atalanta": fs = "/mnt" - when "figurehead": fs = "/cg4/net/depts" - else - $stderr.puts "No mount for mount testing; skipping" - return - end - - assert_nothing_raised { - Puppet.type(:mount).retrieve - } - - oldtext = Puppet::Type.type(:mount).fileobj.read - - ftype = Puppet::Type.type(:mount).filetype - - # Make sure the original gets reinstalled. - if ftype == Puppet::FileType.filetype(:netinfo) - cleanup do - IO.popen("niload -r /mounts .", "w") do |file| - file.puts oldtext - end - end - else - cleanup do - Puppet::Type.type(:mount).fileobj.write(oldtext) - end - end - - obj = Puppet.type(:mount)[fs] + obj = mkmount - assert(obj, "Could not retrieve %s object" % fs) - - current = nil - - assert_nothing_raised { - current = obj.mounted? - } - - if current - # Make sure the original gets reinstalled. - cleanup do - unless obj.mounted? - obj.mount - end - end - end - - unless current - assert_nothing_raised { - obj.mount - } - end - - # Now copy all of the states' "is" values to the "should" values - obj.each do |state| - state.should = state.is - end + assert_apply(obj) # Verify we can remove the mount assert_nothing_raised { obj[:ensure] = :absent } - assert_events([:mount_removed], obj) + assert_events([:mount_deleted], obj) assert_events([], obj) # And verify it's gone - assert(!obj.mounted?, "Object is mounted after being removed") - - text = Puppet.type(:mount).fileobj.read - - assert(text !~ /#{fs}/, - "Fstab still contains %s" % fs) + assert(!obj.provider.mounted?, "Object is mounted after being removed") assert_nothing_raised { obj[:ensure] = :present @@ -249,10 +141,7 @@ class TestMounts < Test::Unit::TestCase assert_events([:mount_created], obj) assert_events([], obj) - text = Puppet::Type.type(:mount).fileobj.read - assert(text =~ /#{fs}/, "Fstab does not contain %s" % fs) - - assert(! obj.mounted?, "Object is mounted incorrectly") + assert(! obj.provider.mounted?, "Object is mounted incorrectly") assert_nothing_raised { obj[:ensure] = :mounted @@ -261,33 +150,8 @@ class TestMounts < Test::Unit::TestCase assert_events([:mount_mounted], obj) assert_events([], obj) - text = Puppet::Type.type(:mount).fileobj.read - assert(text =~ /#{fs}/, - "Fstab does not contain %s" % fs) - obj.retrieve - assert(obj.mounted?, "Object is not mounted") - - unless current - assert_nothing_raised { - obj.unmount - } - end - end - end - - def use_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 - fstab = fakefile(File::join("data/types/mount", name)) - Puppet::Type.type(:mount).path = fstab + assert(obj.provider.mounted?, "Object is not mounted") end end |
