diff options
author | Thom May <thom@may.lt> | 2018-03-15 18:04:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-15 18:04:09 +0000 |
commit | fdd3511a1107bf5cea50ca139a604206485b3f1c (patch) | |
tree | 24bccf48873d9c06ba556d143f82103041547724 /spec | |
parent | 3522c00ad457fd7caf6b5f80a29ab0c4a25ff253 (diff) | |
parent | c4ce9d9393d88f1f441f588fed70720b747cfd72 (diff) | |
download | chef-fdd3511a1107bf5cea50ca139a604206485b3f1c.tar.gz |
Merge pull request #6969 from chef/tm/6851
update mount to use properties and fix 6851
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/provider/mount/mount_spec.rb | 33 | ||||
-rw-r--r-- | spec/unit/provider/mount/solaris_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/resource/mount_spec.rb | 45 |
3 files changed, 37 insertions, 45 deletions
diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb index b61dc65800..cd663b9684 100644 --- a/spec/unit/provider/mount/mount_spec.rb +++ b/spec/unit/provider/mount/mount_spec.rb @@ -53,13 +53,13 @@ describe Chef::Provider::Mount::Mount do expect(@provider.current_resource.device).to eq("/dev/sdz1") end - it "should accecpt device_type :uuid", :not_supported_on_solaris do + it "should accept device_type :uuid", :not_supported_on_solaris do @status = double(:stdout => "/dev/sdz1\n", :exitstatus => 1) @new_resource.device_type :uuid @new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a" @stdout_findfs = double("STDOUT", :first => "/dev/sdz1") expect(@provider).to receive(:shell_out).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(@status) - @provider.load_current_resource() + @provider.load_current_resource @provider.mountable? end @@ -492,5 +492,34 @@ describe Chef::Provider::Mount::Mount do @provider.disable_fs end end + + # the fstab might contain the mount with the device as a device but the resource has a label. + # we should not create two mount lines, but update the existing one + context "when the device is described differently" do + it "should update the existing line" do + @current_resource.enabled(true) + status = double(:stdout => "/dev/sdz1\n", :exitstatus => 1) + expect(@provider).to receive(:shell_out).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_return(status) + + filesystems = [%q{/dev/sdy1 /tmp/foo ext3 defaults 1 2}, + %q{/dev/sdz1 /tmp/foo ext3 defaults 1 2}].join("\n") + fstab = StringIO.new filesystems + + fstab_write = StringIO.new + + allow(::File).to receive(:readlines).with("/etc/fstab").and_return(fstab.readlines) + allow(::File).to receive(:open).with("/etc/fstab", "w").and_yield(fstab_write) + allow(::File).to receive(:open).with("/etc/fstab", "a").and_yield(fstab_write) + + @new_resource.device_type :uuid + @new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a" + @new_resource.dump 1 + + @provider.enable_fs + expect(fstab_write.string).to match(%r{/dev/sdy1\s+/tmp/foo\s+ext3\s+defaults\s+1\s+2}) + expect(fstab_write.string).to match(%r{UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a\s+/tmp/foo\s+ext3\s+defaults\s+1\s+2}) + expect(fstab_write.string).not_to match(%r{/dev/sdz1\s+/tmp/foo\s+ext3\s+defaults\s+1\s+2}) + end + end end end diff --git a/spec/unit/provider/mount/solaris_spec.rb b/spec/unit/provider/mount/solaris_spec.rb index 264c8b9b36..2ec9feaf3b 100644 --- a/spec/unit/provider/mount/solaris_spec.rb +++ b/spec/unit/provider/mount/solaris_spec.rb @@ -538,7 +538,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "after the mount's state has been discovered" do describe "mount_fs" do it "should mount the filesystem" do - expect(provider).to receive(:shell_out!).with("mount -F #{fstype} -o defaults #{device} #{mountpoint}") + expect(provider).to receive(:shell_out!).with("mount -F #{fstype} #{device} #{mountpoint}") provider.mount_fs() end @@ -600,7 +600,7 @@ describe Chef::Provider::Mount::Solaris, :unix_only do context "in the typical case" do let(:other_mount) { "/dev/dsk/c0t2d0s0 /dev/rdsk/c0t2d0s0 / ufs 2 yes -" } - let(:this_mount) { "/dev/dsk/c0t2d0s7\t/dev/rdsk/c0t2d0s7\t/mnt/foo\tufs\t2\tyes\tdefaults\n" } + let(:this_mount) { "/dev/dsk/c0t2d0s7\t/dev/rdsk/c0t2d0s7\t/mnt/foo\tufs\t2\tyes\t-\n" } let(:vfstab_file_contents) { [other_mount].join("\n") } diff --git a/spec/unit/resource/mount_spec.rb b/spec/unit/resource/mount_spec.rb index 41eb9c221f..2fdad43f3f 100644 --- a/spec/unit/resource/mount_spec.rb +++ b/spec/unit/resource/mount_spec.rb @@ -61,6 +61,10 @@ describe Chef::Resource::Mount do expect(resource.fstype).to eql("nfs") end + it "sets fstype to 'auto' by default" do + expect(resource.fstype).to eql("auto") + end + it "allows you to set the dump attribute" do resource.dump 1 expect(resource.dump).to eql(1) @@ -164,45 +168,4 @@ describe Chef::Resource::Mount do resource.domain("TEST_DOMAIN") expect(resource.domain).to eq("TEST_DOMAIN") end - - describe "when it has mount point, device type, and fstype" do - before do - resource.device("charmander") - resource.mount_point("123.456") - resource.device_type(:device) - resource.fstype("ranked") - end - - it "describes its state" do - state = resource.state_for_resource_reporter - expect(state[:mount_point]).to eq("123.456") - expect(state[:device_type]).to eql(:device) - expect(state[:fstype]).to eq("ranked") - end - - it "returns the device as its identity" do - expect(resource.identity).to eq("charmander") - end - end - - describe "when it has username, password and domain" do - before do - resource.mount_point("T:") - resource.device("charmander") - resource.username("Administrator") - resource.password("Jetstream123!") - resource.domain("TEST_DOMAIN") - end - - it "describes its state" do - state = resource.state_for_resource_reporter - expect(state[:mount_point]).to eq("T:") - expect(state[:username]).to eq("Administrator") - expect(state[:password]).to eq("*sensitive value suppressed*") - expect(state[:domain]).to eq("TEST_DOMAIN") - expect(state[:device_type]).to eql(:device) - expect(state[:fstype]).to eq("auto") - end - - end end |