summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/provider/mount.rb17
-rw-r--r--lib/chef/provider/mount/mount.rb11
-rw-r--r--spec/unit/provider/mount_spec.rb30
3 files changed, 46 insertions, 12 deletions
diff --git a/lib/chef/provider/mount.rb b/lib/chef/provider/mount.rb
index 013b8a67b3..64c7bc3f29 100644
--- a/lib/chef/provider/mount.rb
+++ b/lib/chef/provider/mount.rb
@@ -122,8 +122,11 @@ class Chef
# we need to be able to update fstab to conform with their wishes
# without necessarily needing to remount the device.
# See #6851 for more.
+ # We have to compare current resource device with device_fstab value
+ # because entry in /etc/fstab will be as per device_type.
+ # For Ex: 'LABEL=/tmp/ /mnt ext3 defaults 0 2', where 'device_type' is :label.
def device_unchanged?
- @current_resource.device == @new_resource.device
+ @current_resource.device == device_fstab
end
#
@@ -169,6 +172,18 @@ class Chef
sleep 0.1
end
end
+
+ # Returns the new_resource device as per device_type
+ def device_fstab
+ case @new_resource.device_type
+ when :device
+ @new_resource.device
+ when :label
+ "LABEL=#{@new_resource.device}"
+ when :uuid
+ "UUID=#{@new_resource.device}"
+ end
+ end
end
end
end
diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb
index e3aa7e6d1c..f6a7519c06 100644
--- a/lib/chef/provider/mount/mount.rb
+++ b/lib/chef/provider/mount/mount.rb
@@ -212,17 +212,6 @@ class Chef
private
- def device_fstab
- case @new_resource.device_type
- when :device
- @new_resource.device
- when :label
- "LABEL=#{@new_resource.device}"
- when :uuid
- "UUID=#{@new_resource.device}"
- end
- end
-
def device_real
if @real_device.nil?
if @new_resource.device_type == :device
diff --git a/spec/unit/provider/mount_spec.rb b/spec/unit/provider/mount_spec.rb
index f41be7bd3b..47bab39e66 100644
--- a/spec/unit/provider/mount_spec.rb
+++ b/spec/unit/provider/mount_spec.rb
@@ -151,6 +151,24 @@ describe Chef::Provider::Mount do
provider.run_action(:enable)
expect(new_resource).not_to be_updated_by_last_action
end
+
+ it "should enable the mount if device changed" do
+ allow(current_resource).to receive(:enabled).and_return(true)
+ expect(provider).to receive(:mount_options_unchanged?).and_return(true)
+ expect(provider).to receive(:device_unchanged?).and_return(false)
+ expect(provider).to receive(:enable_fs).and_return(true)
+ provider.run_action(:enable)
+ expect(new_resource).to be_updated_by_last_action
+ end
+
+ it "should not enable the mount if device not changed" do
+ allow(current_resource).to receive(:enabled).and_return(true)
+ expect(provider).to receive(:mount_options_unchanged?).and_return(true)
+ expect(provider).to receive(:device_unchanged?).and_return(true)
+ expect(provider).not_to receive(:enable_fs)
+ provider.run_action(:enable)
+ expect(new_resource).not_to be_updated_by_last_action
+ end
end
describe "when the target state is to disable the mount" do
@@ -188,4 +206,16 @@ describe Chef::Provider::Mount do
it "should delegates the disable implementation to subclasses" do
expect { provider.disable_fs }.to raise_error(Chef::Exceptions::UnsupportedAction)
end
+
+ describe "#device_unchanged?" do
+ it "should be true when device_type not changed" do
+ expect(provider.device_unchanged?).to be_truthy
+ end
+
+ it "should be false when device_type changed" do
+ new_resource.device_type :label
+ current_resource.device_type :device
+ expect(provider.device_unchanged?).to be_falsey
+ end
+ end
end