summaryrefslogtreecommitdiffstats
path: root/spec/unit/provider/mount
diff options
context:
space:
mode:
authorMatt Robinson <matt@puppetlabs.com>2011-03-06 20:42:39 -0800
committerMatt Robinson <matt@puppetlabs.com>2011-03-07 14:02:17 -0800
commit28095d7435bcab15b76ddfa4435d61653f2f890d (patch)
tree74ae5f037aaee78ed31de178c6e6f4203e9d7959 /spec/unit/provider/mount
parent6869385300dc694c4f087e134949dff9e1e43df9 (diff)
parente8145f91debc863b341a270e1d8cff6c43d93ef5 (diff)
downloadpuppet-28095d7435bcab15b76ddfa4435d61653f2f890d.tar.gz
puppet-28095d7435bcab15b76ddfa4435d61653f2f890d.tar.xz
puppet-28095d7435bcab15b76ddfa4435d61653f2f890d.zip
Merge branch '2.6.next' into next
This was a particularly nasty merge, so rather than hold up merges into next any longer, I'm going to push this merge with a few outstanding problems. The tests that were failing in the following areas have been marked pending, and will be addressed separately, immediately following this push. TODO: Verify that brice's rdoc change is still valid: tests to show that line numbers from class, define and node get into the ast Fix mount parsed_spec spec/unit/provider/mount/parsed_spec.rb * 2.6.next: (85 commits) (#5148) Fix failing spec due to timezone (#5148) Add support for PSON to facts (#6338) Remove inventory indirection, and move to facts indirection (#6445) Fix inline docs: puppet agent does not accept --mkusers Update CHANGELOG and version for 2.6.6rc1 (#6541) Fix content with checksum truncation bug (#6418) Recursive files shouldn't be audited (#6541) maint: whitespace cleanup on the file integration spec (#6541) Fix content with checksum truncation bug (#5466) Write specs for output of puppet resource (#5466) Monkey patch Symbol so that you can sort them (#5466) Fixed puppet resource bug with trailing , Update CHANGELOG for 2.6.5 (#4922) Don't truncate remotely-sourced files on 404 (#6338) Remove unused version control tags Maint: Align tabs in a code block in the Augeas type. (#6509) Inline docs: Fix erroneous code block in directoryservice provider for computer type Maint: Rewrite comments about symlinks to reflect best practice. (#6509) Inline docs: Fix broken lists in Launchd provider. (#6509) Inline docs: Fix broken code blocks in zpool type ... Manually Resolved Conflicts: lib/puppet/application/inspect.rb lib/puppet/defaults.rb lib/puppet/file_bucket/dipper.rb lib/puppet/network/http/handler.rb lib/puppet/node/facts.rb lib/puppet/parser/parser.rb lib/puppet/parser/parser_support.rb lib/puppet/util/command_line/puppet lib/puppet/util/command_line/puppetd lib/puppet/util/command_line/puppetmasterd lib/puppet/util/monkey_patches.rb lib/puppet/util/rdoc/parser.rb spec/unit/application/agent_spec.rb spec/unit/file_bucket/file_spec.rb spec/unit/indirector/file_bucket_file/file_spec.rb spec/unit/network/http/handler_spec.rb spec/unit/parser/parser_spec.rb spec/unit/provider/mount/parsed_spec.rb
Diffstat (limited to 'spec/unit/provider/mount')
-rwxr-xr-xspec/unit/provider/mount/parsed_spec.rb311
1 files changed, 187 insertions, 124 deletions
diff --git a/spec/unit/provider/mount/parsed_spec.rb b/spec/unit/provider/mount/parsed_spec.rb
index 01262f94c..216680e6d 100755
--- a/spec/unit/provider/mount/parsed_spec.rb
+++ b/spec/unit/provider/mount/parsed_spec.rb
@@ -6,174 +6,237 @@
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
require 'shared_behaviours/all_parsedfile_providers'
-module ParsedMountTesting
- def mkmountargs
- mount = nil
-
- if defined?(@pcount)
- @pcount += 1
- else
- @pcount = 1
- end
- args = {
- :name => "/fspuppet#{@pcount}",
- :device => "/dev/dsk#{@pcount}",
- }
+provider_class = Puppet::Type.type(:mount).provider(:parsed)
- @provider_class.fields(:parsed).each do |field|
- args[field] = "fake#{field}#{@pcount}" unless args.include? field
- end
+describe provider_class do
- args
+ before :each do
+ @mount_class = Puppet::Type.type(:mount)
+ @provider = @mount_class.provider(:parsed)
end
- def mkmount
- hash = mkmountargs
- #hash[:provider] = @provider_class.name
-
- fakeresource = stub :type => :mount, :name => hash[:name]
- fakeresource.stubs(:[]).with(:name).returns(hash[:name])
- fakeresource.stubs(:should).with(:target).returns(nil)
-
- mount = @provider_class.new(fakeresource)
- hash[:record_type] = :parsed
- hash[:ensure] = :present
- mount.property_hash = hash
-
- mount
+ # 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
- # Here we just create a fake host type that answers to all of the methods
- # but does not modify our actual system.
- def mkfaketype
- @provider.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram))
+ 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
-end
-provider_class = Puppet::Type.type(:mount).provider(:parsed)
+ describe "when parsing a line" do
-describe provider_class do
- before :each do
- @mount_class = Puppet::Type.type(:mount)
- @provider_class = @mount_class.provider(:parsed)
- end
+ 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 provider_class do
- include ParsedMountTesting
+ describe "on Solaris", :if => Facter.value(:operatingsystem) == 'Solaris' do
- it_should_behave_like "all parsedfile providers",
- provider_class, my_fixtures('*.fstab')
+ before :each do
+ @example_line = "/dev/dsk/c0d0s0 /dev/rdsk/c0d0s0 \t\t / \t ufs 1 no\t-"
+ end
- it "should be able to parse all of the example mount tabs" do
- pending "REVISIT: these may want to be dropped, or maybe rewritten."
- # fake_fstab was just one of the *.fstab files, based on running OS,
- # despite the claim in the title of this test. --daniel 2011-03-03
- tab = fake_fstab
- @provider = @provider_class
+ it "should extract device from the first field" do
+ @provider.parse_line(@example_line)[:device].should == '/dev/dsk/c0d0s0'
+ end
- # 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 extract blockdevice from second field" do
+ @provider.parse_line(@example_line)[:blockdevice].should == "/dev/rdsk/c0d0s0"
+ end
- proc { @provider_class.to_file(hashes) }.should_not raise_error
+ it "should extract name from third field" do
+ @provider.parse_line(@example_line)[:name].should == "/"
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 fstype from fourth field" do
+ @provider.parse_line(@example_line)[:fstype].should == "ufs"
+ 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 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 provider_class, " when mounting an absent filesystem" do
- include ParsedMountTesting
+ describe "on other platforms than Solaris", :if => Facter.value(:operatingsystem) != 'Solaris' do
- # #730 - Make sure 'flush' is called when a mount is moving from absent to mounted
- it "should flush the fstab to disk" do
- mount = mkmount
+ before :each do
+ @example_line = "/dev/vg00/lv01\t/spare \t \t ext3 defaults\t1 2"
+ end
- # Mark the mount as absent
- mount.property_hash[:ensure] = :absent
+ it "should extract device from the first field" do
+ @provider.parse_line(@example_line)[:device].should == '/dev/vg00/lv01'
+ end
- mount.stubs(:mountcmd) # just so we don't actually try to mount anything
+ it "should extract name from second field" do
+ @provider.parse_line(@example_line)[:name].should == "/spare"
+ end
- mount.expects(:flush)
- mount.mount
- end
- end
+ it "should extract fstype from third field" do
+ @provider.parse_line(@example_line)[:fstype].should == "ext3"
+ end
- describe provider_class, " when modifying the filesystem tab" do
- include ParsedMountTesting
- before do
- Puppet.settings.stubs(:use)
- # Never write to disk, only to RAM.
- #@provider_class.stubs(:filetype).returns(Puppet::Util::FileType.filetype(:ram))
- @provider_class.stubs(:target_object).returns(Puppet::Util::FileType.filetype(:ram).new("eh"))
- @provider_class.clear
-
- @mount = mkmount
- @target = @provider_class.default_target
- end
+ it "should extract options from fourth field" do
+ @provider.parse_line(@example_line)[:options].should == "defaults"
+ end
- it "should write the mount to disk when :flush is called" do
- old_text = @provider_class.target_object(@provider_class.default_target).read
+ it "should extract dump from fifth field" do
+ @provider.parse_line(@example_line)[:dump].should == "1"
+ end
- @mount.flush
+ it "should extract options from sixth field" do
+ @provider.parse_line(@example_line)[:pass].should == "2"
+ end
- text = @provider_class.target_object(@provider_class.default_target).read
- text.should == old_text + @mount.class.to_line(@mount.property_hash) + "\n"
end
+
end
- describe provider_class, " when parsing information about the root filesystem", :if => Facter["operatingsystem"].value != "Darwin" do
- include ParsedMountTesting
+ 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))
+ 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))
+ 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
- before do
- @mount = @mount_class.new :name => "/"
- @provider = @mount.provider
+ 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))
+ 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 have a filesystem tab" do
- FileTest.should be_exist(@provider_class.default_target)
+ 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))
+ 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 find the root filesystem" do
- @provider_class.prefetch("/" => @mount)
- @mount.provider.property_hash[:ensure].should == :present
+ 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))
+ 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 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
- include ParsedMountTesting
+ my_fixtures('*.fstab').each do |fstab|
+ describe "when prefetching #{fstab}" do
+ before :each do
+ pending "need to rework how testing mount output works after this merge is complete"
+ # 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
- it "should call the 'mount' command to mount the filesystem"
+ @provider.stubs(:mountcmd).returns File.read(fake_mountoutput)
+ end
- it "should call the 'unmount' command to unmount the filesystem"
+ 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 specify the filesystem when remounting a filesystem"
+ 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 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