diff options
-rw-r--r-- | lib/chef/provider/mount/mount.rb | 2 | ||||
-rw-r--r-- | spec/unit/provider/mount/mount_spec.rb | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb index 25dfd42725..22d61a9236 100644 --- a/lib/chef/provider/mount/mount.rb +++ b/lib/chef/provider/mount/mount.rb @@ -244,7 +244,7 @@ class Chef # So given a symlink like this: # /dev/mapper/vgroot-tmp.vol -> /dev/dm-9 # First it will try to match "/dev/mapper/vgroot-tmp.vol". If there is no match it will try matching for "/dev/dm-9". - "(?:#{Regexp.escape(device_real)}|#{Regexp.escape(::File.readlink(device_real))})" + "(?:#{Regexp.escape(device_real)}|#{Regexp.escape(::File.expand_path(::File.readlink(device_real),::File.dirname(device_real)))})" else Regexp.escape(device_real) end diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb index 99e78590f1..e27cf71e01 100644 --- a/spec/unit/provider/mount/mount_spec.rb +++ b/spec/unit/provider/mount/mount_spec.rb @@ -141,6 +141,17 @@ describe Chef::Provider::Mount::Mount do @provider.current_resource.mounted.should be_true end + it "should set mounted true if the symlink target of the device is relative and is found in the mounts list - CHEF-4957" do + target = "xsdz1" + + ::File.stub(:symlink?).with("#{@new_resource.device}").and_return(true) + ::File.stub(:readlink).with("#{@new_resource.device}").and_return(target) + + @provider.stub(:shell_out!).and_return(OpenStruct.new(:stdout => "/dev/xsdz1 on /tmp/foo type ext3 (rw)\n")) + @provider.load_current_resource() + @provider.current_resource.mounted.should be_true + end + it "should set mounted true if the mount point is found last in the mounts list" do mount = "/dev/sdy1 on #{@new_resource.mount_point} type ext3 (rw)\n" mount << "#{@new_resource.device} on #{@new_resource.mount_point} type ext3 (rw)\n" @@ -199,6 +210,20 @@ describe Chef::Provider::Mount::Mount do @provider.current_resource.enabled.should be_true end + it "should set enabled to true if the symlink target is relative and is in fstab - CHEF-4957" do + target = "xsdz1" + + ::File.stub(:symlink?).with("#{@new_resource.device}").and_return(true) + ::File.stub(:readlink).with("#{@new_resource.device}").and_return(target) + + fstab = "/dev/sdz1 /tmp/foo ext3 defaults 1 2\n" + + ::File.stub(:foreach).with("/etc/fstab").and_yield fstab + + @provider.load_current_resource + @provider.current_resource.enabled.should be_true + end + it "should set enabled to false if the mount point is not in fstab" do fstab = "/dev/sdy1 #{@new_resource.mount_point} ext3 defaults 1 2\n" ::File.stub(:foreach).with("/etc/fstab").and_yield fstab |