summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/provider/mount/mount.rb1
-rw-r--r--spec/unit/provider/mount/mount_spec.rb26
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb
index 593a09ecbe..2e98b7a69c 100644
--- a/lib/chef/provider/mount/mount.rb
+++ b/lib/chef/provider/mount/mount.rb
@@ -225,6 +225,7 @@ class Chef
# ignore trailing slash
Regexp.escape(device_real)+"/?"
elsif ::File.symlink?(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.
"(?:#{Regexp.escape(device_real)}|#{Regexp.escape(::File.readlink(device_real))})"
else
Regexp.escape(device_real)
diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb
index c497a08e40..f6c6c1b7d4 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