diff options
-rwxr-xr-x | lib/puppet/type/parsedtype/mount.rb | 75 | ||||
-rw-r--r-- | test/data/types/mount/freebsd.fstab | 7 | ||||
-rw-r--r-- | test/data/types/mount/linux.fstab | 11 | ||||
-rw-r--r-- | test/data/types/mount/solaris.fstab | 11 | ||||
-rw-r--r-- | test/puppettest.rb | 10 | ||||
-rwxr-xr-x | test/types/mount.rb | 17 |
6 files changed, 101 insertions, 30 deletions
diff --git a/lib/puppet/type/parsedtype/mount.rb b/lib/puppet/type/parsedtype/mount.rb index 69254e1b6..f21348131 100755 --- a/lib/puppet/type/parsedtype/mount.rb +++ b/lib/puppet/type/parsedtype/mount.rb @@ -103,37 +103,47 @@ module Puppet @doc = "Manages mounted mounts, including putting mount information into the mount table." - @instances = [] - - @platform = Facter["operatingsystem"].value - case @platform - when "Solaris": - @path = "/etc/vfstab" - @fields = [:device, :blockdevice, :path, :fstype, :pass, :atboot, - :options] - when "Darwin": - @filetype = Puppet::FileType.filetype(:netinfo) - @filetype.format = "fstab" - @path = "mounts" - @fields = [:device, :path, :fstype, :options, :dump, :pass] - - # How to map the dumped table to what we want - @fieldnames = { - "name" => :device, - "dir" => :path, - "dump_freq" => :dump, - "passno" => :pass, - "vfstype" => :fstype, - "opts" => :options - } - else - @path = "/etc/fstab" - @fields = [:device, :path, :fstype, :options, :dump, :pass] + def self.init + @platform = Facter["operatingsystem"].value + case @platform + when "Solaris": + @path = "/etc/vfstab" + @fields = [:device, :blockdevice, :path, :fstype, :pass, :atboot, + :options] + @defaults = [ nil ] * @fields.size + when "Darwin": + @filetype = Puppet::FileType.filetype(:netinfo) + @filetype.format = "fstab" + @path = "mounts" + @fields = [:device, :path, :fstype, :options, :dump, :pass] + @defaults = [ nil ] * @fields.size + + # How to map the dumped table to what we want + @fieldnames = { + "name" => :device, + "dir" => :path, + "dump_freq" => :dump, + "passno" => :pass, + "vfstype" => :fstype, + "opts" => :options + } + else + @path = "/etc/fstab" + @fields = [:device, :path, :fstype, :options, :dump, :pass] + @defaults = [ nil ] * 4 + [ "0" ] * 2 + end + + # Allow Darwin to override the default filetype + unless defined? @filetype + @filetype = Puppet::FileType.filetype(:flat) + end end - # Allow Darwin to override the default filetype - unless defined? @filetype - @filetype = Puppet::FileType.filetype(:flat) + init + + def self.clear + init + super end # Parse a mount tab. @@ -156,10 +166,15 @@ module Puppet comment(line) else values = line.split(/\s+/) - unless @fields.length == values.length + if @fields.length < values.length raise Puppet::Error, "Could not parse line %s" % line end + values = @defaults.zip(values).collect { |d, v| v || d } + unless @fields.length == values.length + raise Puppet::Error, "Could not parse line %s" % line + end + @fields.zip(values).each do |field, value| hash[field] = value end diff --git a/test/data/types/mount/freebsd.fstab b/test/data/types/mount/freebsd.fstab new file mode 100644 index 000000000..c39416bc8 --- /dev/null +++ b/test/data/types/mount/freebsd.fstab @@ -0,0 +1,7 @@ +# Device Mountpoint FStype Options Dump Pass# +/dev/ad0s1b none swap sw 0 0 +/dev/ad0s1a / ufs rw 1 1 +/dev/ad0s1e /tmp ufs rw 2 2 +/dev/ad0s1f /usr ufs rw 2 2 +/dev/ad0s1d /var ufs rw 2 2 +/dev/acd0 /cdrom cd9660 ro,noauto 0 0 diff --git a/test/data/types/mount/linux.fstab b/test/data/types/mount/linux.fstab new file mode 100644 index 000000000..06afe1242 --- /dev/null +++ b/test/data/types/mount/linux.fstab @@ -0,0 +1,11 @@ +# A sample fstab, typical for a Fedora system +/dev/vg00/lv00 / ext3 defaults 1 1 +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 +proc /proc proc defaults 0 0 +/dev/vg00/lv01 /spare ext3 defaults 1 2 +sysfs /sys sysfs defaults 0 0 +LABEL=SWAP-hda6 swap swap defaults 0 0 diff --git a/test/data/types/mount/solaris.fstab b/test/data/types/mount/solaris.fstab new file mode 100644 index 000000000..c7de9671b --- /dev/null +++ b/test/data/types/mount/solaris.fstab @@ -0,0 +1,11 @@ +#device device mount FS fsck mount mount +#to mount to fsck point type pass at boot options +# +fd - /dev/fd fd - no - +/proc - /proc proc - no - +/dev/dsk/c0d0s0 /dev/rdsk/c0d0s0 / ufs 1 no - +/dev/dsk/c0d0p0:boot - /boot pcfs - no - +/devices - /devices devfs - no - +ctfs - /system/contract ctfs - no - +objfs - /system/object objfs - no - +#swap - /tmp tmpfs - yes - diff --git a/test/puppettest.rb b/test/puppettest.rb index f601a3660..5cf247a63 100644 --- a/test/puppettest.rb +++ b/test/puppettest.rb @@ -320,6 +320,16 @@ module TestPuppet return files end + def fakefile(name) + ary = [$puppetbase, "test"] + ary += name.split("/") + file = File.join(ary) + unless FileTest.exists?(file) + raise Puppet::DevError, "No fakedata file %s" % file + end + return file + end + # wrap how to retrieve the masked mode def filemode(file) File.stat(file).mode & 007777 diff --git a/test/types/mount.rb b/test/types/mount.rb index 0a6062ff7..70170289e 100755 --- a/test/types/mount.rb +++ b/test/types/mount.rb @@ -93,6 +93,7 @@ class TestMounts < Test::Unit::TestCase unless Facter["operatingsystem"].value == "Darwin" def test_mountsparse + use_fake_fstab assert_nothing_raised { @mounttype.retrieve } @@ -104,6 +105,7 @@ class TestMounts < Test::Unit::TestCase def test_rootfs fs = nil + use_fake_fstab assert_nothing_raised { Puppet.type(:mount).retrieve } @@ -121,6 +123,7 @@ class TestMounts < Test::Unit::TestCase # Make sure it reads and writes correctly. def test_readwrite + use_fake_fstab assert_nothing_raised { Puppet::Type.type(:mount).retrieve } @@ -272,6 +275,20 @@ class TestMounts < Test::Unit::TestCase 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 + end end # $Id$ |