diff options
| author | Luke Kanies <luke@madstop.com> | 2007-11-08 17:06:00 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-11-08 17:06:00 -0600 |
| commit | 3f583dc133ce50ae34bfc151474c6d4196f803ca (patch) | |
| tree | 5bbca2e0a72425b34cdf39facdee8d9f14e7831c | |
| parent | 964aebb96416984815f5ef74e36825915d52fe2a (diff) | |
| download | puppet-3f583dc133ce50ae34bfc151474c6d4196f803ca.tar.gz puppet-3f583dc133ce50ae34bfc151474c6d4196f803ca.tar.xz puppet-3f583dc133ce50ae34bfc151474c6d4196f803ca.zip | |
Adding unit tests for the module that handles the
logic around mounting and unmounting. This includes a fix for
bug #761, which required a different regex for Solaris.
| -rw-r--r-- | lib/puppet/provider/mount.rb | 17 | ||||
| -rwxr-xr-x | spec/unit/ral/provider/mount.rb | 134 |
2 files changed, 144 insertions, 7 deletions
diff --git a/lib/puppet/provider/mount.rb b/lib/puppet/provider/mount.rb index 6a05d9826..a63a0402c 100644 --- a/lib/puppet/provider/mount.rb +++ b/lib/puppet/provider/mount.rb @@ -14,7 +14,7 @@ module Puppet::Provider::Mount if self.options and self.options != :absent args << "-o" << self.options end - args << @resource[:name] + args << resource[:name] if respond_to?(:flush) flush @@ -24,8 +24,8 @@ module Puppet::Provider::Mount def remount info "Remounting" - if @resource[:remounts] == :true - mountcmd "-o", "remount", @resource[:name] + if resource[:remounts] == :true + mountcmd "-o", "remount", resource[:name] else unmount() mount() @@ -34,16 +34,19 @@ module Puppet::Provider::Mount # This only works when the mount point is synced to the fstab. def unmount - umount @resource[:name] + umount resource[:name] end # Is the mount currently mounted? def mounted? - platform = Facter["operatingsystem"].value - name = @resource[:name] + platform = Facter.value("operatingsystem") + name = resource[:name] mounts = mountcmd.split("\n").find do |line| - if platform == "Darwin" + case platform + when "Darwin" line =~ / on #{name} / or line =~ %r{ on /private/var/automount#{name}} + when "Solaris" + line =~ /^#{name} on / else line =~ / on #{name} / end diff --git a/spec/unit/ral/provider/mount.rb b/spec/unit/ral/provider/mount.rb new file mode 100755 index 000000000..65aaf7053 --- /dev/null +++ b/spec/unit/ral/provider/mount.rb @@ -0,0 +1,134 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' + +require 'puppet/provider/mount' + +module MountModuleTesting + def setup + @mounter = Object.new + @mounter.extend(Puppet::Provider::Mount) + + @name = "/" + + @resource = stub 'resource' + @resource.stubs(:[]).with(:name).returns(@name) + + @mounter.stubs(:resource).returns(@resource) + end +end + +describe Puppet::Provider::Mount, " when mounting" do + include MountModuleTesting + + it "should use the 'mountcmd' method to mount" do + @mounter.stubs(:options).returns(nil) + @mounter.expects(:mountcmd) + + @mounter.mount + end + + it "should flush before mounting if a flush method exists" do + @mounter.meta_def(:flush) { } + @mounter.expects(:flush) + @mounter.stubs(:mountcmd) + @mounter.stubs(:options).returns(nil) + + @mounter.mount + end + + it "should add the options following '-o' if they exist and are not set to :absent" do + @mounter.stubs(:options).returns("ro") + @mounter.expects(:mountcmd).with { |*ary| ary[0] == "-o" and ary[1] == "ro" } + + @mounter.mount + end + + it "should specify the filesystem name to the mount command" do + @mounter.stubs(:options).returns(nil) + @mounter.expects(:mountcmd).with { |*ary| ary[-1] == @name } + + @mounter.mount + end +end + +describe Puppet::Provider::Mount, " when remounting" do + include MountModuleTesting + + it "should use '-o remount' if the resource specifies it supports remounting" do + @mounter.stubs(:info) + @resource.stubs(:[]).with(:remounts).returns(:true) + @mounter.expects(:mountcmd).with("-o", "remount", @name) + @mounter.remount + end + + it "should unmount and mount if the resource does not specify it supports remounting" do + @mounter.stubs(:info) + @resource.stubs(:[]).with(:remounts).returns(false) + @mounter.expects(:unmount) + @mounter.expects(:mount) + @mounter.remount + end + + it "should log that it is remounting" do + @resource.stubs(:[]).with(:remounts).returns(:true) + @mounter.stubs(:mountcmd) + @mounter.expects(:info).with("Remounting") + @mounter.remount + end +end + +describe Puppet::Provider::Mount, " when unmounting" do + include MountModuleTesting + + it "should call the :umount command with the resource name" do + @mounter.expects(:umount).with(@name) + @mounter.unmount + end +end + +describe Puppet::Provider::Mount, " when determining if it is mounted" do + include MountModuleTesting + + it "should parse the results of running the mount command with no arguments" do + Facter.stubs(:value).returns("whatever") + @mounter.expects(:mountcmd).returns("") + + @mounter.mounted? + end + + it "should match ' on /private/var/automount<name>' if the operating system is Darwin" do + Facter.stubs(:value).with("operatingsystem").returns("Darwin") + @mounter.expects(:mountcmd).returns("/dev/whatever on /private/var/automount/\ndevfs on /dev") + + @mounter.should be_mounted + end + + it "should match ' on <name>' if the operating system is Darwin" do + Facter.stubs(:value).with("operatingsystem").returns("Darwin") + @mounter.expects(:mountcmd).returns("/dev/disk03 on / (local, journaled)\ndevfs on /dev") + + @mounter.should be_mounted + end + + it "should match '^<name> on' if the operating system is Solaris" do + Facter.stubs(:value).with("operatingsystem").returns("Solaris") + @mounter.expects(:mountcmd).returns("/ on /dev/dsk/whatever\n/var on /dev/dsk/other") + + @mounter.should be_mounted + end + + it "should match ' on <name>' if the operating system is not Darwin or Solaris" do + Facter.stubs(:value).with("operatingsystem").returns("Debian") + @mounter.expects(:mountcmd).returns("/dev/dsk/whatever on / and stuff\n/dev/other/disk on /var and stuff") + + @mounter.should be_mounted + end + + it "should not be considered mounted if it did not match the mount output" do + Facter.stubs(:value).with("operatingsystem").returns("Debian") + @mounter.expects(:mountcmd).returns("/dev/dsk/whatever on /something/else and stuff\n/dev/other/disk on /var and stuff") + + @mounter.should_not be_mounted + end +end |
