summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@opscode.com>2013-04-12 11:51:57 -0700
committerBryan McLellan <btm@opscode.com>2013-04-12 11:51:57 -0700
commitf052f8affdc370d640382fc5b2e5f7ea112c1600 (patch)
tree8688f75485e2b38b5d41693f07f320738b17caaf
parente58ed68e8886f0f250d5f6ebd9f44a9425da66e6 (diff)
parent99a2ddf0daed2e8dfddaa0b9090af0f0c833d302 (diff)
downloadchef-f052f8affdc370d640382fc5b2e5f7ea112c1600.tar.gz
Merge branch 'CHEF-3804'
-rw-r--r--lib/chef/provider/mount/mount.rb6
-rw-r--r--spec/unit/provider/mount/mount_spec.rb26
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb
index 9a85a9058a..280513cddc 100644
--- a/lib/chef/provider/mount/mount.rb
+++ b/lib/chef/provider/mount/mount.rb
@@ -225,7 +225,11 @@ class Chef
# ignore trailing slash
Regexp.escape(device_real)+"/?"
elsif ::File.symlink?(device_real)
- "(?:#{Regexp.escape(device_real)})|(?:#{Regexp.escape(::File.readlink(device_real))})"
+ # This regular expression tries to match device_real. If that does not match it will try to match the target of device_real.
+ # 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))})"
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 c497a08e40..1e52124343 100644
--- a/spec/unit/provider/mount/mount_spec.rb
+++ b/spec/unit/provider/mount/mount_spec.rb
@@ -216,6 +216,32 @@ describe Chef::Provider::Mount::Mount do
@provider.load_current_resource
@provider.current_resource.enabled.should be_false
end
+
+ it "should not mangle the mount options if the device in fstab is a symlink" do
+ target = "/dev/mapper/target"
+ options = "rw,noexec,noauto"
+
+ ::File.stub!(:symlink?).with(@new_resource.device).and_return(true)
+ ::File.stub!(:readlink).with(@new_resource.device).and_return(target)
+
+ fstab = "#{@new_resource.device} #{@new_resource.mount_point} #{@new_resource.fstype} #{options} 1 2\n"
+ ::File.stub!(:foreach).with("/etc/fstab").and_yield fstab
+ @provider.load_current_resource
+ @provider.current_resource.options.should eq(options.split(','))
+ end
+
+ it "should not mangle the mount options if the symlink target is in fstab" do
+ target = "/dev/mapper/target"
+ options = "rw,noexec,noauto"
+
+ ::File.stub!(:symlink?).with(@new_resource.device).and_return(true)
+ ::File.stub!(:readlink).with(@new_resource.device).and_return(target)
+
+ fstab = "#{target} #{@new_resource.mount_point} #{@new_resource.fstype} #{options} 1 2\n"
+ ::File.stub!(:foreach).with("/etc/fstab").and_yield fstab
+ @provider.load_current_resource
+ @provider.current_resource.options.should eq(options.split(','))
+ end
end
context "after the mount's state has been discovered" do