diff --git a/spec/fixtures/unit/provider/mount/parsed/aix.mount b/spec/fixtures/unit/provider/mount/parsed/aix.mount new file mode 100644 index 000000000..380dbc5ae --- /dev/null +++ b/spec/fixtures/unit/provider/mount/parsed/aix.mount @@ -0,0 +1,7 @@ +node mounted mounted over vfs date options +---- ------- ------------ --- ------------ ------------------- + /dev/hd0 / jfs Dec 17 08:04 rw, log =/dev/hd8 + /dev/hd3 /tmp jfs Dec 17 08:04 rw, log =/dev/hd8 + /dev/hd1 /home jfs Dec 17 08:06 rw, log =/dev/hd8 + /dev/hd2 /usr jfs Dec 17 08:06 rw, log =/dev/hd8 +sue /home/local/src /usr/code nfs Dec 17 08:06 ro, log =/dev/hd8 diff --git a/spec/fixtures/unit/provider/mount/parsed/darwin.mount b/spec/fixtures/unit/provider/mount/parsed/darwin.mount new file mode 100644 index 000000000..1bdfcf89a --- /dev/null +++ b/spec/fixtures/unit/provider/mount/parsed/darwin.mount @@ -0,0 +1,6 @@ +/dev/disk0s2 on / (hfs, local, journaled) +devfs on /dev (devfs, local, nobrowse) +map -hosts on /net (autofs, nosuid, automounted, nobrowse) +map auto_home on /home (autofs, automounted, nobrowse) +/dev/disk0s3 on /usr (hfs, local, journaled) +/dev/fake on /ghost (hfs, local, journaled) diff --git a/spec/fixtures/unit/provider/mount/parsed/freebsd.fstab b/spec/fixtures/unit/provider/mount/parsed/freebsd.fstab index a41104236..41b749bff 100644 --- a/spec/fixtures/unit/provider/mount/parsed/freebsd.fstab +++ b/spec/fixtures/unit/provider/mount/parsed/freebsd.fstab @@ -1,7 +1,8 @@ # 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/ad0s1g /boot ufs rw 2 2 /dev/acd0 /cdrom cd9660 ro,noauto 0 0 diff --git a/spec/fixtures/unit/provider/mount/parsed/freebsd.mount b/spec/fixtures/unit/provider/mount/parsed/freebsd.mount new file mode 100644 index 000000000..89c518c5d --- /dev/null +++ b/spec/fixtures/unit/provider/mount/parsed/freebsd.mount @@ -0,0 +1,3 @@ +/dev/ad0s1a on / (ufs, local, soft-updates) +/dev/ad0s1d on /ghost (ufs, local, soft-updates) +devfs on /dev (devfs, local, multilabel) diff --git a/spec/fixtures/unit/provider/mount/parsed/hpux.mount b/spec/fixtures/unit/provider/mount/parsed/hpux.mount new file mode 100644 index 000000000..d414fa47a --- /dev/null +++ b/spec/fixtures/unit/provider/mount/parsed/hpux.mount @@ -0,0 +1,17 @@ +/ on rpool/ROOT/opensolaris read/write/setuid/devices/dev=2d90002 on Wed Dec 31 16:00:00 1969 +/devices on /devices read/write/setuid/devices/dev=4a00000 on Thu Feb 17 14:34:02 2011 +/dev on /dev read/write/setuid/devices/dev=4a40000 on Thu Feb 17 14:34:02 2011 +/system/contract on ctfs read/write/setuid/devices/dev=4ac0001 on Thu Feb 17 14:34:02 2011 +/proc on proc read/write/setuid/devices/dev=4b00000 on Thu Feb 17 14:34:02 2011 +/etc/mnttab on mnttab read/write/setuid/devices/dev=4b40001 on Thu Feb 17 14:34:02 2011 +/etc/svc/volatile on swap read/write/setuid/devices/xattr/dev=4b80001 on Thu Feb 17 14:34:02 2011 +/system/object on objfs read/write/setuid/devices/dev=4bc0001 on Thu Feb 17 14:34:02 2011 +/etc/dfs/sharetab on sharefs read/write/setuid/devices/dev=4c00001 on Thu Feb 17 14:34:02 2011 +/lib/libc.so.1 on /usr/lib/libc/libc_hwcap1.so.1 read/write/setuid/devices/dev=2d90002 on Thu Feb 17 14:34:14 2011 +/dev/fd on fd read/write/setuid/devices/dev=4d00001 on Thu Feb 17 14:34:18 2011 +/tmp on swap read/write/setuid/devices/xattr/dev=4b80002 on Thu Feb 17 14:34:19 2011 +/var/run on swap read/write/setuid/devices/xattr/dev=4b80003 on Thu Feb 17 14:34:19 2011 +/export on rpool/export read/write/setuid/devices/nonbmand/exec/xattr/atime/dev=2d90006 on Thu Feb 17 14:37:48 2011 +/export/home on rpool/export/home read/write/setuid/devices/nonbmand/exec/xattr/atime/dev=2d90007 on Thu Feb 17 14:37:48 2011 +/rpool on rpool read/write/setuid/devices/nonbmand/exec/xattr/atime/dev=2d90009 on Thu Feb 17 14:37:48 2011 +/ghost on /dev/fake read/write/setuid/devices/nonbmand/exec/xattr/atime/dev=2d90009 on Thu Feb 17 14:37:48 2011 diff --git a/spec/fixtures/unit/provider/mount/parsed/linux.mount b/spec/fixtures/unit/provider/mount/parsed/linux.mount new file mode 100644 index 000000000..75dd71fd4 --- /dev/null +++ b/spec/fixtures/unit/provider/mount/parsed/linux.mount @@ -0,0 +1,5 @@ +/dev/root on / type jfs (rw,noatime) +rc-svcdir on /lib64/rc/init.d type tmpfs (rw,nosuid,nodev,noexec,relatime,size=1024k,mode=755) +sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) +/dev/sda9 on /usr/portage type jfs (rw) +/dev/fake on /ghost type jfs (rw) diff --git a/spec/fixtures/unit/provider/mount/parsed/freebsd.fstab b/spec/fixtures/unit/provider/mount/parsed/netbsd.fstab similarity index 68% copy from spec/fixtures/unit/provider/mount/parsed/freebsd.fstab copy to spec/fixtures/unit/provider/mount/parsed/netbsd.fstab index a41104236..ca3ca8450 100644 --- a/spec/fixtures/unit/provider/mount/parsed/freebsd.fstab +++ b/spec/fixtures/unit/provider/mount/parsed/netbsd.fstab @@ -1,7 +1,9 @@ # 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 +/dev/ad3s1b none swap sw 0 0 +/dev/ad3s1e /data ufs rw 2 2 +/dev/ad3s1g /boot ufs rw 2 2 diff --git a/spec/fixtures/unit/provider/mount/parsed/netbsd.mount b/spec/fixtures/unit/provider/mount/parsed/netbsd.mount new file mode 100644 index 000000000..dfdc26a34 --- /dev/null +++ b/spec/fixtures/unit/provider/mount/parsed/netbsd.mount @@ -0,0 +1,8 @@ +/dev/ad0s1a on / (ufs, local) +devfs on /dev (devfs, local) +/dev/ad0s1e on /tmp (ufs, local, soft-updates) +/dev/ad0s1f on /usr (ufs, local, soft-updates) +/dev/ad0s1d on /var (ufs, local, soft-updates) +/dev/ad3s1e on /data (ufs, local, soft-updates) +/dev/ad3s1h on /ghost (ufs, local, soft-updates) +devfs on /var/named/dev (devfs, local) diff --git a/spec/fixtures/unit/provider/mount/parsed/openbsd.fstab b/spec/fixtures/unit/provider/mount/parsed/openbsd.fstab new file mode 100644 index 000000000..44c83eed1 --- /dev/null +++ b/spec/fixtures/unit/provider/mount/parsed/openbsd.fstab @@ -0,0 +1,4 @@ +/dev/wd0a / ffs rw 1 1 +/dev/wd0e /home ffs rw,nodev,nosuid 1 2 +/dev/wd0d /usr ffs rw,nodev 1 2 +/dev/wd0f /boot ffs rw,nodev 1 2 diff --git a/spec/fixtures/unit/provider/mount/parsed/openbsd.mount b/spec/fixtures/unit/provider/mount/parsed/openbsd.mount new file mode 100644 index 000000000..367475783 --- /dev/null +++ b/spec/fixtures/unit/provider/mount/parsed/openbsd.mount @@ -0,0 +1,4 @@ +/dev/wd0a on / type ffs (local) +/dev/wd0e on /home type ffs (local, nodev, nosuid) +/dev/wd0d on /usr type ffs (local, nodev) +/dev/wd0g on /ghost type ffs (local, nodev) diff --git a/spec/fixtures/unit/provider/mount/parsed/solaris.mount b/spec/fixtures/unit/provider/mount/parsed/solaris.mount new file mode 100644 index 000000000..26fabc575 --- /dev/null +++ b/spec/fixtures/unit/provider/mount/parsed/solaris.mount @@ -0,0 +1,6 @@ +/ on /dev/dsk/c0t0d0s0 read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Mon Mar 18 08:48:45 2002 +/proc on /proc read/write/setuid/dev=4300000 on Mon Mar 18 08:48:44 2002 +/etc/mnttab on mnttab read/write/setuid/dev=43c0000 on Mon Mar 18 08:48:44 2002 +/tmp on swap read/write/setuid/xattr/dev=2 on Mon Mar 18 08:48:52 2002 +/export/home on /dev/dsk/c0t0d0s7 read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Mon Mar 18 +/ghost on /dev/dsk/c0t1d0s7 read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Mon Mar 18 diff --git a/spec/unit/provider/mount/parsed_spec.rb b/spec/unit/provider/mount/parsed_spec.rb index 216680e6d..43defbe87 100755 --- a/spec/unit/provider/mount/parsed_spec.rb +++ b/spec/unit/provider/mount/parsed_spec.rb @@ -1,242 +1,250 @@ #!/usr/bin/env ruby # # Created by Luke Kanies on 2007-9-12. # Copyright (c) 2006. All rights reserved. require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper') require 'shared_behaviours/all_parsedfile_providers' provider_class = Puppet::Type.type(:mount).provider(:parsed) describe provider_class do before :each do @mount_class = Puppet::Type.type(:mount) @provider = @mount_class.provider(:parsed) end # LAK:FIXME I can't mock Facter because this test happens at parse-time. it "should default to /etc/vfstab on Solaris" do pending "This test only works on Solaris" unless Facter.value(:operatingsystem) == 'Solaris' Puppet::Type.type(:mount).provider(:parsed).default_target.should == '/etc/vfstab' end it "should default to /etc/fstab on anything else" do pending "This test does not work on Solaris" if Facter.value(:operatingsystem) == 'Solaris' Puppet::Type.type(:mount).provider(:parsed).default_target.should == '/etc/fstab' end describe "when parsing a line" do it "should not crash on incomplete lines in fstab" do parse = @provider.parse <<-FSTAB /dev/incomplete /dev/device name FSTAB lambda{ @provider.to_line(parse[0]) }.should_not raise_error end # it_should_behave_like "all parsedfile providers", # provider_class, my_fixtures('*.fstab') describe "on Solaris", :if => Facter.value(:operatingsystem) == 'Solaris' do before :each do @example_line = "/dev/dsk/c0d0s0 /dev/rdsk/c0d0s0 \t\t / \t ufs 1 no\t-" end it "should extract device from the first field" do @provider.parse_line(@example_line)[:device].should == '/dev/dsk/c0d0s0' end it "should extract blockdevice from second field" do @provider.parse_line(@example_line)[:blockdevice].should == "/dev/rdsk/c0d0s0" end it "should extract name from third field" do @provider.parse_line(@example_line)[:name].should == "/" end it "should extract fstype from fourth field" do @provider.parse_line(@example_line)[:fstype].should == "ufs" end it "should extract pass from fifth field" do @provider.parse_line(@example_line)[:pass].should == "1" end it "should extract atboot from sixth field" do @provider.parse_line(@example_line)[:atboot].should == "no" end it "should extract options from seventh field" do @provider.parse_line(@example_line)[:options].should == "-" end end describe "on other platforms than Solaris", :if => Facter.value(:operatingsystem) != 'Solaris' do before :each do @example_line = "/dev/vg00/lv01\t/spare \t \t ext3 defaults\t1 2" end it "should extract device from the first field" do @provider.parse_line(@example_line)[:device].should == '/dev/vg00/lv01' end it "should extract name from second field" do @provider.parse_line(@example_line)[:name].should == "/spare" end it "should extract fstype from third field" do @provider.parse_line(@example_line)[:fstype].should == "ext3" end it "should extract options from fourth field" do @provider.parse_line(@example_line)[:options].should == "defaults" end it "should extract dump from fifth field" do @provider.parse_line(@example_line)[:dump].should == "1" end it "should extract options from sixth field" do @provider.parse_line(@example_line)[:pass].should == "2" end end end describe "mountinstances" do it "should get name from mountoutput found on Solaris" do - pending Facter.stubs(:value).with(:operatingsystem).returns 'Solaris' - @provider.stubs(:mountcmd).returns(File.read(fake_mountoutput)) + @provider.stubs(:mountcmd).returns(File.read(my_fixture('solaris.mount'))) mounts = @provider.mountinstances mounts.size.should == 6 mounts[0].should == { :name => '/', :mounted => :yes } mounts[1].should == { :name => '/proc', :mounted => :yes } mounts[2].should == { :name => '/etc/mnttab', :mounted => :yes } mounts[3].should == { :name => '/tmp', :mounted => :yes } mounts[4].should == { :name => '/export/home', :mounted => :yes } mounts[5].should == { :name => '/ghost', :mounted => :yes } end it "should get name from mountoutput found on HP-UX" do - pending Facter.stubs(:value).with(:operatingsystem).returns 'HP-UX' - @provider.stubs(:mountcmd).returns(File.read(fake_mountoutput)) + @provider.stubs(:mountcmd).returns(File.read(my_fixture('hpux.mount'))) mounts = @provider.mountinstances mounts.size.should == 17 mounts[0].should == { :name => '/', :mounted => :yes } mounts[1].should == { :name => '/devices', :mounted => :yes } mounts[2].should == { :name => '/dev', :mounted => :yes } mounts[3].should == { :name => '/system/contract', :mounted => :yes } mounts[4].should == { :name => '/proc', :mounted => :yes } mounts[5].should == { :name => '/etc/mnttab', :mounted => :yes } mounts[6].should == { :name => '/etc/svc/volatile', :mounted => :yes } mounts[7].should == { :name => '/system/object', :mounted => :yes } mounts[8].should == { :name => '/etc/dfs/sharetab', :mounted => :yes } mounts[9].should == { :name => '/lib/libc.so.1', :mounted => :yes } mounts[10].should == { :name => '/dev/fd', :mounted => :yes } mounts[11].should == { :name => '/tmp', :mounted => :yes } mounts[12].should == { :name => '/var/run', :mounted => :yes } mounts[13].should == { :name => '/export', :mounted => :yes } mounts[14].should == { :name => '/export/home', :mounted => :yes } mounts[15].should == { :name => '/rpool', :mounted => :yes } mounts[16].should == { :name => '/ghost', :mounted => :yes } end it "should get name from mountoutput found on Darwin" do - pending Facter.stubs(:value).with(:operatingsystem).returns 'Darwin' - @provider.stubs(:mountcmd).returns(File.read(fake_mountoutput)) + @provider.stubs(:mountcmd).returns(File.read(my_fixture('darwin.mount'))) mounts = @provider.mountinstances mounts.size.should == 6 mounts[0].should == { :name => '/', :mounted => :yes } mounts[1].should == { :name => '/dev', :mounted => :yes } mounts[2].should == { :name => '/net', :mounted => :yes } mounts[3].should == { :name => '/home', :mounted => :yes } mounts[4].should == { :name => '/usr', :mounted => :yes } mounts[5].should == { :name => '/ghost', :mounted => :yes } end it "should get name from mountoutput found on Linux" do - pending Facter.stubs(:value).with(:operatingsystem).returns 'Gentoo' - @provider.stubs(:mountcmd).returns(File.read(fake_mountoutput)) + @provider.stubs(:mountcmd).returns(File.read(my_fixture('linux.mount'))) mounts = @provider.mountinstances mounts[0].should == { :name => '/', :mounted => :yes } mounts[1].should == { :name => '/lib64/rc/init.d', :mounted => :yes } mounts[2].should == { :name => '/sys', :mounted => :yes } mounts[3].should == { :name => '/usr/portage', :mounted => :yes } mounts[4].should == { :name => '/ghost', :mounted => :yes } end it "should get name from mountoutput found on AIX" do - pending Facter.stubs(:value).with(:operatingsystem).returns 'AIX' - @provider.stubs(:mountcmd).returns(File.read(fake_mountoutput)) + @provider.stubs(:mountcmd).returns(File.read(my_fixture('aix.mount'))) mounts = @provider.mountinstances mounts[0].should == { :name => '/', :mounted => :yes } mounts[1].should == { :name => '/tmp', :mounted => :yes } mounts[2].should == { :name => '/home', :mounted => :yes } mounts[3].should == { :name => '/usr', :mounted => :yes } mounts[4].should == { :name => '/usr/code', :mounted => :yes } end it "should raise an error if a line is not understandable" do @provider.stubs(:mountcmd).returns("bazinga!") lambda { @provider.mountinstances }.should raise_error Puppet::Error end end my_fixtures('*.fstab').each do |fstab| - describe "when prefetching #{fstab}" do + platform = File.basename(fstab, '.fstab') + describe "when prefetching on #{platform}" do before :each do - pending "need to rework how testing mount output works after this merge is complete" + 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 @res_ghost = Puppet::Type::Mount.new(:name => '/ghost') # in no fake fstab @res_mounted = Puppet::Type::Mount.new(:name => '/') # in every fake fstab @res_unmounted = Puppet::Type::Mount.new(:name => '/boot') # in every fake fstab @res_absent = Puppet::Type::Mount.new(:name => '/absent') # in no fake fstab # Simulate transaction.rb:prefetch @resource_hash = {} [@res_ghost, @res_mounted, @res_unmounted, @res_absent].each do |resource| @resource_hash[resource.name] = resource end - - @provider.stubs(:mountcmd).returns File.read(fake_mountoutput) end it "should set :ensure to :unmounted if found in fstab but not mounted" do @provider.prefetch(@resource_hash) @res_unmounted.provider.get(:ensure).should == :unmounted end - it "should set :ensure to :mounted if found in fstab and mounted" do + it "should set :ensure to :ghost if not found in fstab but mounted" do @provider.prefetch(@resource_hash) @res_ghost.provider.get(:ensure).should == :ghost end - it "should set :ensure to :ghost if not found in fstab but mounted" do + it "should set :ensure to :mounted if found in fstab and mounted" do @provider.prefetch(@resource_hash) @res_mounted.provider.get(:ensure).should == :mounted end it "should set :ensure to :absent if not found in fstab and not mounted" do @provider.prefetch(@resource_hash) @res_absent.provider.get(:ensure).should == :absent end end end - end