[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 2.6.5-303-gfcfa26a

Stefan Schulte stefan.schulte at taunusstein.net
Thu Mar 17 10:47:28 UTC 2011


The following commit has been merged in the upstream branch:
commit c57c508e938083115bbc00037901f652505288b0
Author: Stefan Schulte <stefan.schulte at taunusstein.net>
Date:   Sun Feb 20 11:18:19 2011 +0100

    (#4914) Improved parsed_spec for mount
    
    Add specs for the new prefetching and the correct parsing of vfstab on
    Solaris and fstab on other systems

diff --git a/lib/puppet/provider/mount/parsed.rb b/lib/puppet/provider/mount/parsed.rb
index 9422ca6..4a64ca2 100755
--- a/lib/puppet/provider/mount/parsed.rb
+++ b/lib/puppet/provider/mount/parsed.rb
@@ -67,7 +67,7 @@ Puppet::Type.type(:mount).provide(:parsed,:parent => Puppet::Provider::ParsedFil
 
   def self.mountinstances
     # XXX: Will not work for mount points that have spaces in path (does fstab support this anyways?)
-    regex = case Facter.value("operatingsystem")
+    regex = case Facter.value(:operatingsystem)
       when "Darwin"
         / on (?:\/private\/var\/automount)?(\S*)/
       when "Solaris", "HP-UX"
diff --git a/spec/unit/provider/mount/parsed_spec.rb b/spec/unit/provider/mount/parsed_spec.rb
index 94e731b..2a305b9 100755
--- a/spec/unit/provider/mount/parsed_spec.rb
+++ b/spec/unit/provider/mount/parsed_spec.rb
@@ -27,89 +27,234 @@ module ParsedMountTesting
     fakefile(File::join("data/types/mount", name))
   end
 
+  def fake_mountoutput
+    os = Facter.value(:operatingsystem)
+    if os == "Darwin"
+      name = "darwin.mount"
+    elsif os == "HP-UX"
+      name = "hpux.mount"
+    elsif os == "Solaris"
+      name = "solaris.mount"
+    else
+      # Catchall for other fstabs
+      name = "linux.mount"
+    end
+    fakefile(File::join("data/providers/mount/parsed", name))
+  end
 
 end
 
 provider_class = Puppet::Type.type(:mount).provider(:parsed)
 
 describe provider_class do
+
   before :each do
     @mount_class = Puppet::Type.type(:mount)
-    @provider_class = @mount_class.provider(:parsed)
+    @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
 
-  describe provider_class do
-    include ParsedMountTesting
+  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
 
-    it "should be able to parse all of the example mount tabs" do
-      tab = fake_fstab
-      @provider = @provider_class
+  describe "when parsing a line" do
 
-      # LAK:FIXME Again, a relatively bad test, but I don't know how to rspec-ify this.
-      # I suppose this is more of an integration test?  I dunno.
-      fakedataparse(tab) do
-        # Now just make we've got some mounts we know will be there
-        hashes = @provider_class.target_records(tab).find_all { |i| i.is_a? Hash }
-        (hashes.length > 0).should be_true
-        root = hashes.find { |i| i[:name] == "/" }
+    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
 
-        proc { @provider_class.to_file(hashes) }.should_not raise_error
+
+    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
-    end
 
-    # LAK:FIXME I can't mock Facter because this test happens at parse-time.
-    it "should default to /etc/vfstab on Solaris and /etc/fstab everywhere else" do
-      should = case Facter.value(:operatingsystem)
-        when "Solaris"; "/etc/vfstab"
-        else
-          "/etc/fstab"
-        end
-      Puppet::Type.type(:mount).provider(:parsed).default_target.should == should
-    end
+      it "should extract device from the first field" do
+        @provider.parse_line(@example_line)[:device].should == '/dev/dsk/c0d0s0'
+      end
 
-    it "should not crash on incomplete lines in fstab" do
-      parse = @provider_class.parse <<-FSTAB
-/dev/incomplete
-/dev/device       name
-      FSTAB
+      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
 
-      lambda{ @provider_class.to_line(parse[0]) }.should_not raise_error
     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 provider_class, " when parsing information about the root filesystem", :if => Facter["operatingsystem"].value != "Darwin" do
+  describe "mountinstances" do
     include ParsedMountTesting
 
-    before do
-      @mount = @mount_class.new :name => "/"
-      @provider = @mount.provider
+    it "should get name from mountoutput found on Solaris" do
+      Facter.stubs(:value).with(:operatingsystem).returns 'Solaris'
+      @provider.stubs(:mountcmd).returns(File.read(fake_mountoutput))
+      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
+      Facter.stubs(:value).with(:operatingsystem).returns 'HP-UX'
+      @provider.stubs(:mountcmd).returns(File.read(fake_mountoutput))
+      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 have a filesystem tab" do
-      FileTest.should be_exist(@provider_class.default_target)
+    it "should get name from mountoutput found on Darwin" do
+      Facter.stubs(:value).with(:operatingsystem).returns 'Darwin'
+      @provider.stubs(:mountcmd).returns(File.read(fake_mountoutput))
+      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 find the root filesystem" do
-      @provider_class.prefetch("/" => @mount)
-      @mount.provider.property_hash[:ensure].should == :present
+    it "should get name from mountoutput found on Linux" do
+      Facter.stubs(:value).with(:operatingsystem).returns 'Gentoo'
+      @provider.stubs(:mountcmd).returns(File.read(fake_mountoutput))
+      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 determine that the root fs is mounted" do
-      @provider_class.prefetch("/" => @mount)
-      @mount.provider.should be_mounted
+    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
 
-  describe provider_class, " when mounting and unmounting" do
+  describe "when prefetching" do
     include ParsedMountTesting
 
-    it "should call the 'mount' command to mount the filesystem"
+    before :each do
+      @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)
+      @provider.stubs(:default_target).returns fake_fstab
+    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
+      @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
+      @provider.prefetch(@resource_hash)
+      @res_mounted.provider.get(:ensure).should == :mounted
+    end
 
-    it "should call the 'unmount' command to unmount the filesystem"
+    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
 
-    it "should specify the filesystem when remounting a filesystem"
   end
+
 end
diff --git a/test/data/providers/mount/parsed/darwin.mount b/test/data/providers/mount/parsed/darwin.mount
new file mode 100644
index 0000000..1bdfcf8
--- /dev/null
+++ b/test/data/providers/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/test/data/providers/mount/parsed/hpux.mount b/test/data/providers/mount/parsed/hpux.mount
new file mode 100644
index 0000000..d414fa4
--- /dev/null
+++ b/test/data/providers/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/test/data/providers/mount/parsed/linux.mount b/test/data/providers/mount/parsed/linux.mount
new file mode 100644
index 0000000..75dd71f
--- /dev/null
+++ b/test/data/providers/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/test/data/providers/mount/parsed/solaris.mount b/test/data/providers/mount/parsed/solaris.mount
new file mode 100644
index 0000000..26fabc5
--- /dev/null
+++ b/test/data/providers/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/test/data/types/mount/linux.fstab b/test/data/types/mount/linux.fstab
index b1debff..c94ec7f 100644
--- a/test/data/types/mount/linux.fstab
+++ b/test/data/types/mount/linux.fstab
@@ -9,3 +9,4 @@ 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
+/dev/sda1               /usr                    xfs     noatime         0 0
diff --git a/test/data/types/mount/solaris.fstab b/test/data/types/mount/solaris.fstab
index 54afc89..348b9d5 100644
--- a/test/data/types/mount/solaris.fstab
+++ b/test/data/types/mount/solaris.fstab
@@ -9,3 +9,4 @@ fd      -       /dev/fd fd      -       no      -
 ctfs    -       /system/contract        ctfs    -       no      -
 objfs   -       /system/object  objfs   -       no      -
 #swap   -       /tmp    tmpfs   -       yes     -
+/dev/dsk/c0d0s2 /dev/rdsk/c0d0s2        /usr       ufs     1       no      -

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list