diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/fixtures/unit/provider/mount/mount-output.aix.txt | 14 | ||||
-rw-r--r-- | spec/fixtures/unit/provider/mount/mount-output.darwin.txt | 5 | ||||
-rw-r--r-- | spec/fixtures/unit/provider/mount/mount-output.hp-ux.txt | 16 | ||||
-rw-r--r-- | spec/fixtures/unit/provider/mount/mount-output.other.txt | 14 | ||||
-rw-r--r-- | spec/fixtures/unit/provider/mount/mount-output.solaris.txt | 16 | ||||
-rwxr-xr-x[-rw-r--r--] | spec/unit/application/inspect_spec.rb | 2 | ||||
-rwxr-xr-x | spec/unit/file_bucket/dipper_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/file_bucket/file_spec.rb | 35 | ||||
-rwxr-xr-x | spec/unit/indirector/file_bucket_file/file_spec.rb | 109 | ||||
-rwxr-xr-x | spec/unit/provider/mount/parsed_spec.rb | 14 | ||||
-rwxr-xr-x | spec/unit/provider/mount_spec.rb | 185 | ||||
-rwxr-xr-x | spec/unit/type/mount_spec.rb | 56 |
12 files changed, 299 insertions, 169 deletions
diff --git a/spec/fixtures/unit/provider/mount/mount-output.aix.txt b/spec/fixtures/unit/provider/mount/mount-output.aix.txt index 54edb9c1c..380dbc5ae 100644 --- a/spec/fixtures/unit/provider/mount/mount-output.aix.txt +++ b/spec/fixtures/unit/provider/mount/mount-output.aix.txt @@ -1,7 +1,7 @@ -/dev/hd4 / jfs2 Nov 11 12:11 rw,log=/dev/hd8 -/dev/hd2 /usr jfs2 Nov 11 12:11 rw,log=/dev/hd8 -/dev/hd9var /var jfs2 Nov 11 12:11 rw,log=/dev/hd8 -/dev/hd3 /tmp jfs2 Nov 11 12:11 rw,log=/dev/hd8 -/dev/hd1 /home jfs2 Nov 11 12:11 rw,log=/dev/hd8 -/proc /proc procfs Nov 11 12:11 rw -/dev/hd10opt /opt jfs2 Nov 11 12:11 rw,log=/dev/hd8 +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/mount-output.darwin.txt b/spec/fixtures/unit/provider/mount/mount-output.darwin.txt new file mode 100644 index 000000000..fbb9d9832 --- /dev/null +++ b/spec/fixtures/unit/provider/mount/mount-output.darwin.txt @@ -0,0 +1,5 @@ +/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) diff --git a/spec/fixtures/unit/provider/mount/mount-output.hp-ux.txt b/spec/fixtures/unit/provider/mount/mount-output.hp-ux.txt new file mode 100644 index 000000000..477926138 --- /dev/null +++ b/spec/fixtures/unit/provider/mount/mount-output.hp-ux.txt @@ -0,0 +1,16 @@ +/ 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 diff --git a/spec/fixtures/unit/provider/mount/mount-output.other.txt b/spec/fixtures/unit/provider/mount/mount-output.other.txt new file mode 100644 index 000000000..0e4dff0c5 --- /dev/null +++ b/spec/fixtures/unit/provider/mount/mount-output.other.txt @@ -0,0 +1,14 @@ +/dev/sda1 on / type ext4 (rw,errors=remount-ro,commit=0) +proc on /proc type proc (rw,noexec,nosuid,nodev) +none on /sys type sysfs (rw,noexec,nosuid,nodev) +fusectl on /sys/fs/fuse/connections type fusectl (rw) +none on /sys/kernel/debug type debugfs (rw) +none on /sys/kernel/security type securityfs (rw) +none on /dev type devtmpfs (rw,mode=0755) +none on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620) +none on /dev/shm type tmpfs (rw,nosuid,nodev) +none on /var/run type tmpfs (rw,nosuid,mode=0755) +none on /var/lock type tmpfs (rw,noexec,nosuid,nodev) +none on /proc/fs/vmblock/mountPoint type vmblock (rw) +binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev) +/dev/sda2 on /usr type ext4 (rw,errors=remount-ro,commit=0) diff --git a/spec/fixtures/unit/provider/mount/mount-output.solaris.txt b/spec/fixtures/unit/provider/mount/mount-output.solaris.txt new file mode 100644 index 000000000..477926138 --- /dev/null +++ b/spec/fixtures/unit/provider/mount/mount-output.solaris.txt @@ -0,0 +1,16 @@ +/ 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 diff --git a/spec/unit/application/inspect_spec.rb b/spec/unit/application/inspect_spec.rb index 1d99c6ca9..d334a87ee 100644..100755 --- a/spec/unit/application/inspect_spec.rb +++ b/spec/unit/application/inspect_spec.rb @@ -174,7 +174,7 @@ describe Puppet::Application::Inspect do @inspect.run_command - @report.logs.count.should == 1 + @report.logs.first.should_not == nil @report.logs.first.message.should =~ /Could not back up/ end end diff --git a/spec/unit/file_bucket/dipper_spec.rb b/spec/unit/file_bucket/dipper_spec.rb index db40c6296..c40d79589 100755 --- a/spec/unit/file_bucket/dipper_spec.rb +++ b/spec/unit/file_bucket/dipper_spec.rb @@ -92,7 +92,7 @@ describe Puppet::FileBucket::Dipper do [request1, request2].each do |r| r.server.should == 'puppetmaster' r.port.should == 31337 - r.key.should == "md5/#{checksum}" + r.key.should == "md5/#{checksum}#{real_path}" end end diff --git a/spec/unit/file_bucket/file_spec.rb b/spec/unit/file_bucket/file_spec.rb index 82063c2e3..f80b16238 100644 --- a/spec/unit/file_bucket/file_spec.rb +++ b/spec/unit/file_bucket/file_spec.rb @@ -64,30 +64,6 @@ describe Puppet::FileBucket::File do end end - describe "when saving files" do - it "should save the contents to the calculated path" do - ::File.stubs(:directory?).with(@dir).returns(true) - ::File.expects(:exist?).with("#{@dir}/contents").returns false - - mockfile = mock "file" - mockfile.expects(:print).with(@contents) - ::File.expects(:open).with("#{@dir}/contents", ::File::WRONLY|::File::CREAT, 0440).yields(mockfile) - - Puppet::FileBucket::File.new(@contents).save - end - - it "should make any directories necessary for storage" do - FileUtils.expects(:mkdir_p).with do |arg| - ::File.umask == 0007 and arg == @dir - end - ::File.expects(:directory?).with(@dir).returns(false) - ::File.expects(:open).with("#{@dir}/contents", ::File::WRONLY|::File::CREAT, 0440) - ::File.expects(:exist?).with("#{@dir}/contents").returns false - - Puppet::FileBucket::File.new(@contents).save - end - end - it "should return a url-ish name" do Puppet::FileBucket::File.new(@contents).name.should == "md5/4a8ec4fa5f01b4ab1a0ab8cbccb709f0" end @@ -105,17 +81,6 @@ describe Puppet::FileBucket::File do Puppet::FileBucket::File.from_pson({"contents"=>"file contents"}).contents.should == "file contents" end - it "should save a file" do - ::File.expects(:exist?).with("#{@dir}/contents").returns false - ::File.expects(:directory?).with(@dir).returns false - ::FileUtils.expects(:mkdir_p).with(@dir) - ::File.expects(:open).with("#{@dir}/contents", ::File::WRONLY|::File::CREAT, 0440) - - bucketfile = Puppet::FileBucket::File.new(@contents) - bucketfile.save - - end - def make_bucketed_file FileUtils.mkdir_p(@dir) File.open("#{@dir}/contents", 'w') { |f| f.write @contents } diff --git a/spec/unit/indirector/file_bucket_file/file_spec.rb b/spec/unit/indirector/file_bucket_file/file_spec.rb index 9187f4da0..0c33593d7 100755 --- a/spec/unit/indirector/file_bucket_file/file_spec.rb +++ b/spec/unit/indirector/file_bucket_file/file_spec.rb @@ -22,13 +22,97 @@ describe Puppet::FileBucketFile::File do Puppet[:bucketdir] = tmpdir('bucketdir') end - describe "when diffing files" do - def save_bucket_file(contents) - bucket_file = Puppet::FileBucket::File.new(contents) - bucket_file.save - bucket_file.checksum_data + def save_bucket_file(contents, path = "/who_cares") + bucket_file = Puppet::FileBucket::File.new(contents) + bucket_file.save("md5/#{Digest::MD5.hexdigest(contents)}#{path}") + bucket_file.checksum_data + end + + describe "when servicing a save request" do + describe "when supplying a path" do + it "should store the path if not already stored" do + checksum = save_bucket_file("stuff", "/foo/bar") + dir_path = "#{Puppet[:bucketdir]}/c/1/3/d/8/8/c/b/c13d88cb4cb02003daedb8a84e5d272a" + File.read("#{dir_path}/contents").should == "stuff" + File.read("#{dir_path}/paths").should == "foo/bar\n" + end + + it "should leave the paths file alone if the path is already stored" do + checksum = save_bucket_file("stuff", "/foo/bar") + checksum = save_bucket_file("stuff", "/foo/bar") + dir_path = "#{Puppet[:bucketdir]}/c/1/3/d/8/8/c/b/c13d88cb4cb02003daedb8a84e5d272a" + File.read("#{dir_path}/contents").should == "stuff" + File.read("#{dir_path}/paths").should == "foo/bar\n" + end + + it "should store an additional path if the new path differs from those already stored" do + checksum = save_bucket_file("stuff", "/foo/bar") + checksum = save_bucket_file("stuff", "/foo/baz") + dir_path = "#{Puppet[:bucketdir]}/c/1/3/d/8/8/c/b/c13d88cb4cb02003daedb8a84e5d272a" + File.read("#{dir_path}/contents").should == "stuff" + File.read("#{dir_path}/paths").should == "foo/bar\nfoo/baz\n" + end + end + + describe "when not supplying a path" do + it "should save the file and create an empty paths file" do + checksum = save_bucket_file("stuff", "") + dir_path = "#{Puppet[:bucketdir]}/c/1/3/d/8/8/c/b/c13d88cb4cb02003daedb8a84e5d272a" + File.read("#{dir_path}/contents").should == "stuff" + File.read("#{dir_path}/paths").should == "" + end + end + end + + describe "when servicing a head/find request" do + describe "when supplying a path" do + it "should return false/nil if the file isn't bucketed" do + Puppet::FileBucket::File.head("md5/0ae2ec1980410229885fe72f7b44fe55/foo/bar").should == false + Puppet::FileBucket::File.find("md5/0ae2ec1980410229885fe72f7b44fe55/foo/bar").should == nil + end + + it "should return false/nil if the file is bucketed but with a different path" do + checksum = save_bucket_file("I'm the contents of a file", '/foo/bar') + Puppet::FileBucket::File.head("md5/#{checksum}/foo/baz").should == false + Puppet::FileBucket::File.find("md5/#{checksum}/foo/baz").should == nil + end + + it "should return true/file if the file is already bucketed with the given path" do + contents = "I'm the contents of a file" + checksum = save_bucket_file(contents, '/foo/bar') + Puppet::FileBucket::File.head("md5/#{checksum}/foo/bar").should == true + find_result = Puppet::FileBucket::File.find("md5/#{checksum}/foo/bar") + find_result.should be_a(Puppet::FileBucket::File) + find_result.checksum.should == "{md5}#{checksum}" + find_result.to_s.should == contents + end + end + + describe "when not supplying a path" do + [false, true].each do |trailing_slash| + describe "#{trailing_slash ? 'with' : 'without'} a trailing slash" do + trailing_string = trailing_slash ? '/' : '' + + it "should return false/nil if the file isn't bucketed" do + Puppet::FileBucket::File.head("md5/0ae2ec1980410229885fe72f7b44fe55#{trailing_string}").should == false + Puppet::FileBucket::File.find("md5/0ae2ec1980410229885fe72f7b44fe55#{trailing_string}").should == nil + end + + it "should return true/file if the file is already bucketed" do + contents = "I'm the contents of a file" + checksum = save_bucket_file(contents, '/foo/bar') + Puppet::FileBucket::File.head("md5/#{checksum}#{trailing_string}").should == true + find_result = Puppet::FileBucket::File.find("md5/#{checksum}#{trailing_string}") + find_result.should be_a(Puppet::FileBucket::File) + find_result.checksum.should == "{md5}#{checksum}" + find_result.to_s.should == contents + end + end + end end + end + describe "when diffing files" do it "should generate an empty string if there is no diff" do checksum = save_bucket_file("I'm the contents of a file") Puppet::FileBucket::File.find("md5/#{checksum}", :diff_with => checksum).should == '' @@ -102,7 +186,7 @@ HERE key = "md5/#{@digest}" if supply_path - key += "//path/to/file" + key += "/path/to/file" end @request = Puppet::Indirector::Request.new(:indirection_name, :find, key, request_options) @@ -116,10 +200,15 @@ HERE it "should return an instance of Puppet::FileBucket::File created with the content if the file exists" do make_bucketed_file - bucketfile = @store.find(@request) - bucketfile.should be_a(Puppet::FileBucket::File) - bucketfile.contents.should == @contents - @store.head(@request).should == true + if supply_path + @store.find(@request).should == nil + @store.head(@request).should == false # because path didn't match + else + bucketfile = @store.find(@request) + bucketfile.should be_a(Puppet::FileBucket::File) + bucketfile.contents.should == @contents + @store.head(@request).should == true + end end it "should return nil if no file is found" do diff --git a/spec/unit/provider/mount/parsed_spec.rb b/spec/unit/provider/mount/parsed_spec.rb index 5a1c986b1..069d9495a 100755 --- a/spec/unit/provider/mount/parsed_spec.rb +++ b/spec/unit/provider/mount/parsed_spec.rb @@ -130,7 +130,7 @@ describe provider_class do mount.stubs(:mountcmd) # just so we don't actually try to mount anything mount.expects(:flush) - mount.mount + mount.mount! end end @@ -176,17 +176,7 @@ describe provider_class do it "should determine that the root fs is mounted" do @provider_class.prefetch("/" => @mount) - @mount.provider.should be_mounted + @mount.provider.should be_anything_mounted end end - - describe provider_class, " when mounting and unmounting" do - include ParsedMountTesting - - it "should call the 'mount' command to mount the filesystem" - - it "should call the 'unmount' command to unmount the filesystem" - - it "should specify the filesystem when remounting a filesystem" - end end diff --git a/spec/unit/provider/mount_spec.rb b/spec/unit/provider/mount_spec.rb index f567a4a40..1f2501765 100755 --- a/spec/unit/provider/mount_spec.rb +++ b/spec/unit/provider/mount_spec.rb @@ -2,28 +2,30 @@ require File.dirname(__FILE__) + '/../../spec_helper' +require 'puppet_spec/files' require 'puppet/provider/mount' describe Puppet::Provider::Mount do - before :each do - @mounter = Object.new - @mounter.extend(Puppet::Provider::Mount) + include PuppetSpec::Files + before :each do @name = "/" - @resource = stub 'resource' - @resource.stubs(:[]).with(:name).returns(@name) + @resource = Puppet::Type.type(:mount).new( + :name => '/', + :device => '/dev/sda1', + :target => tmpfile("mount_provider") + ) - @mounter.stubs(:resource).returns(@resource) + @mounter = Puppet::Type.type(:mount).defaultprovider().new(@resource) end - describe Puppet::Provider::Mount, " when mounting" do - + describe "when calling mount!" do it "should use the 'mountcmd' method to mount" do @mounter.stubs(:options).returns(nil) @mounter.expects(:mountcmd) - @mounter.mount + @mounter.mount! end it "should flush before mounting if a flush method exists" do @@ -32,114 +34,169 @@ describe Puppet::Provider::Mount do @mounter.stubs(:mountcmd) @mounter.stubs(:options).returns(nil) - @mounter.mount + @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 + @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 + @mounter.mount! end end - describe Puppet::Provider::Mount, " when remounting" do - + describe "when remounting" do it "should use '-o remount' if the resource specifies it supports remounting" do @mounter.stubs(:info) - @resource.stubs(:[]).with(:remounts).returns(:true) + @resource[:remounts] = 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) + @resource[:remounts] = false @mounter.expects(:unmount) @mounter.expects(:mount) @mounter.remount end it "should log that it is remounting" do - @resource.stubs(:[]).with(:remounts).returns(:true) + @resource[:remounts] = true @mounter.stubs(:mountcmd) @mounter.expects(:info).with("Remounting") @mounter.remount end end - describe Puppet::Provider::Mount, " when unmounting" do - + describe "when unmounting" do 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 - - 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 + %w{Darwin Solaris HP-UX AIX Other}.each do |platform| + describe "on #{platform}" do + before :each do + case platform + when 'Darwin' + mount_fixture = 'mount-output.darwin.txt' + @mount_device = '/dev/disk0s3' + @mount_point = '/usr' + when 'Solaris' + mount_fixture = 'mount-output.solaris.txt' + @mount_device = 'swap' + @mount_point = '/tmp' + when 'HP-UX' + mount_fixture = 'mount-output.hp-ux.txt' + @mount_device = 'swap' + @mount_point = '/tmp' + when 'AIX' + mount_fixture = 'mount-output.aix.txt' + @mount_device = '/dev/hd2' + @mount_point = '/usr' + when 'Other' + mount_fixture = 'mount-output.other.txt' + @mount_device = '/dev/sda2' + @mount_point = '/usr' + end + @mount_data = File.read(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'unit', 'provider', 'mount', mount_fixture)) + Facter.stubs(:value).with("operatingsystem").returns(platform) + end + + describe "when the correct thing is mounted" do + before :each do + @mounter.expects(:mountcmd).returns(@mount_data) + @resource.stubs(:[]).with(:name).returns(@mount_point) + @resource.stubs(:[]).with(:device).returns(@mount_device) + end + + it "should say anything_mounted?" do + @mounter.should be_anything_mounted + end + + it "should say correctly_mounted?" do + @mounter.should be_correctly_mounted + end + end + + describe "when the wrong thing is mounted" do + before :each do + @mounter.expects(:mountcmd).returns(@mount_data) + @resource.stubs(:[]).with(:name).returns(@mount_point) + @resource.stubs(:[]).with(:device).returns('/dev/bogus/thing') + end + + it "should say anything_mounted?" do + @mounter.should be_anything_mounted + end + + it "should not say correctly_mounted?" do + @mounter.should_not be_correctly_mounted + end + end + + describe "when nothing is mounted" do + before :each do + @mounter.expects(:mountcmd).returns(@mount_data) + @resource.stubs(:[]).with(:name).returns('/bogus/location') + @resource.stubs(:[]).with(:device).returns(@mount_device) + end + + it "should not say anything_mounted?" do + @mounter.should_not be_anything_mounted + end + + it "should not say correctly_mounted?" do + @mounter.should_not be_correctly_mounted + end + end end + 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 + describe "when mounting a device" do + it "should not mount! or unmount anything when the correct device is mounted" do + @mounter.stubs(:correctly_mounted?).returns(true) - 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.expects(:anything_mounted?).never + @mounter.expects(:create).once + @mounter.expects(:mount!).never + @mounter.expects(:unmount).never + FileUtils.expects(:mkdir_p).never - @mounter.should be_mounted + @mounter.mount end - it "should match '^<name> on' if the operating system is HP-UX" do - Facter.stubs(:value).with("operatingsystem").returns("HP-UX") - @mounter.expects(:mountcmd).returns("/ on /dev/dsk/whatever\n/var on /dev/dsk/other") + it "should mount the device when nothing is mounted at the desired point" do + @mounter.stubs(:correctly_mounted?).returns(false) + @mounter.stubs(:anything_mounted?).returns(false) - @mounter.should be_mounted - end - - it "should match mounted devices if the operating system is AIX" do - Facter.stubs(:value).with("operatingsystem").returns("AIX") - mount_data = File.read(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'unit', 'provider', 'mount', 'mount-output.aix.txt')) - @mounter.expects(:mountcmd).returns(mount_data) + @mounter.expects(:create).once + @mounter.expects(:mount!).once + @mounter.expects(:unmount).never + FileUtils.expects(:mkdir_p).never - @mounter.should be_mounted + @mounter.mount end - it "should match ' on <name>' if the operating system is not Darwin, Solaris, or HP-UX" 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") + it "should unmount the incorrect device and mount the correct device" do + @mounter.stubs(:correctly_mounted?).returns(false) + @mounter.stubs(:anything_mounted?).returns(true) - @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.expects(:create).once + @mounter.expects(:mount!).once + @mounter.expects(:unmount).once + FileUtils.expects(:mkdir_p).with(@name).returns(true) - @mounter.should_not be_mounted + @mounter.mount end end end diff --git a/spec/unit/type/mount_spec.rb b/spec/unit/type/mount_spec.rb index 0d74042e3..c6d2b5ba0 100755 --- a/spec/unit/type/mount_spec.rb +++ b/spec/unit/type/mount_spec.rb @@ -74,8 +74,7 @@ describe Puppet::Type.type(:mount)::Ensure do end end - describe Puppet::Type.type(:mount)::Ensure, "when retrieving its current state" do - + describe "when retrieving its current state" do it "should return the provider's value if it is :absent" do @provider.expects(:ensure).returns(:absent) @ensure.retrieve.should == :absent @@ -83,28 +82,27 @@ describe Puppet::Type.type(:mount)::Ensure do it "should return :mounted if the provider indicates it is mounted and the value is not :absent" do @provider.expects(:ensure).returns(:present) - @provider.expects(:mounted?).returns(true) + @provider.expects(:correctly_mounted?).returns(true) @ensure.retrieve.should == :mounted end it "should return :unmounted if the provider indicates it is not mounted and the value is not :absent" do @provider.expects(:ensure).returns(:present) - @provider.expects(:mounted?).returns(false) + @provider.expects(:correctly_mounted?).returns(false) @ensure.retrieve.should == :unmounted end end - describe Puppet::Type.type(:mount)::Ensure, "when changing the host" do - + describe "when changing the host" do it "should destroy itself if it should be absent" do - @provider.stubs(:mounted?).returns(false) + @provider.stubs(:anything_mounted?).returns(false) @provider.expects(:destroy) @ensure.should = :absent @ensure.sync end it "should unmount itself before destroying if it is mounted and should be absent" do - @provider.expects(:mounted?).returns(true) + @provider.expects(:anything_mounted?).returns(true) @provider.expects(:unmount) @provider.expects(:destroy) @ensure.should = :absent @@ -113,9 +111,9 @@ describe Puppet::Type.type(:mount)::Ensure do it "should create itself if it is absent and should be defined" do @provider.stubs(:ensure).returns(:absent) - @provider.stubs(:mounted?).returns(true) + @provider.stubs(:anything_mounted?).returns(true) - @provider.stubs(:mounted?).returns(false) + @provider.stubs(:anything_mounted?).returns(false) @provider.expects(:create) @ensure.should = :defined @ensure.sync @@ -123,7 +121,7 @@ describe Puppet::Type.type(:mount)::Ensure do it "should not unmount itself if it is mounted and should be defined" do @provider.stubs(:ensure).returns(:mounted) - @provider.stubs(:mounted?).returns(true) + @provider.stubs(:anything_mounted?).returns(true) @provider.stubs(:create) @provider.expects(:mount).never @@ -134,7 +132,7 @@ describe Puppet::Type.type(:mount)::Ensure do it "should not mount itself if it is unmounted and should be defined" do @provider.stubs(:ensure).returns(:unmounted) - @provider.stubs(:mounted?).returns(false) + @provider.stubs(:anything_mounted?).returns(false) @ensure.stubs(:syncothers) @provider.stubs(:create) @@ -146,7 +144,7 @@ describe Puppet::Type.type(:mount)::Ensure do it "should unmount itself if it is mounted and should be unmounted" do @provider.stubs(:ensure).returns(:present) - @provider.stubs(:mounted?).returns(true) + @provider.stubs(:anything_mounted?).returns(true) @ensure.stubs(:syncothers) @provider.expects(:unmount) @@ -154,34 +152,14 @@ describe Puppet::Type.type(:mount)::Ensure do @ensure.sync end - it "should create and mount itself if it does not exist and should be mounted" do - @provider.stubs(:ensure).returns(:absent) - @provider.stubs(:mounted?).returns(false) - @provider.expects(:create) - @ensure.stubs(:syncothers) - @provider.expects(:mount) - @ensure.should = :mounted - @ensure.sync - end - - it "should mount itself if it is present and should be mounted" do + it "should ask the provider to mount itself" do @provider.stubs(:ensure).returns(:present) - @provider.stubs(:mounted?).returns(false) @ensure.stubs(:syncothers) @provider.expects(:mount) @ensure.should = :mounted @ensure.sync end - it "should create but not mount itself if it is absent and mounted and should be mounted" do - @provider.stubs(:ensure).returns(:absent) - @provider.stubs(:mounted?).returns(true) - @ensure.stubs(:syncothers) - @provider.expects(:create) - @ensure.should = :mounted - @ensure.sync - end - it "should be insync if it is mounted and should be defined" do @ensure.should = :defined @ensure.safe_insync?(:mounted).should == true @@ -203,17 +181,16 @@ describe Puppet::Type.type(:mount)::Ensure do end end - describe Puppet::Type.type(:mount), "when responding to events" do - + describe "when responding to events" do it "should remount if it is currently mounted" do - @provider.expects(:mounted?).returns(true) + @provider.expects(:anything_mounted?).returns(true) @provider.expects(:remount) @mount.refresh end it "should not remount if it is not currently mounted" do - @provider.expects(:mounted?).returns(false) + @provider.expects(:anything_mounted?).returns(false) @provider.expects(:remount).never @mount.refresh @@ -241,7 +218,8 @@ describe Puppet::Type.type(:mount), "when modifying an existing mount entry" do @mount[param] = value end - @mount.provider.stubs(:mounted?).returns true + @mount.provider.stubs(:anything_mounted?).returns true + @mount.provider.stubs(:correctly_mounted?).returns true # stub this to not try to create state.yaml Puppet::Util::Storage.stubs(:store) |