summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantima-gupta <agupta@msystechnologies.com>2020-10-28 17:32:29 +0530
committerantima-gupta <agupta@msystechnologies.com>2020-10-28 17:32:29 +0530
commit7fe69a2a865e24314540e2c8a9c0d28375b22eed (patch)
tree4d23df7aeb6bd0f70b795edfea5818db1140d3fc
parenta8ead1a6bbbbda2eae75bc1fdc4c9858d15c81cb (diff)
downloadchef-7fe69a2a865e24314540e2c8a9c0d28375b22eed.tar.gz
Moved device_fstab method from provider/mount/mount.rb to provider/mount.rb.
Compare current resource device with new resource device_fstab value. Added specs for device_unchaged? method changes. Signed-off-by: antima-gupta <agupta@msystechnologies.com>
-rw-r--r--lib/chef/provider/mount.rb19
-rw-r--r--lib/chef/provider/mount/mount.rb11
-rw-r--r--spec/unit/provider/mount_spec.rb30
3 files changed, 47 insertions, 13 deletions
diff --git a/lib/chef/provider/mount.rb b/lib/chef/provider/mount.rb
index 013b8a67b3..a417ef4ecc 100644
--- a/lib/chef/provider/mount.rb
+++ b/lib/chef/provider/mount.rb
@@ -121,9 +121,12 @@ class Chef
# It's entirely plausible that a site might prefer UUIDs or labels, so
# we need to be able to update fstab to conform with their wishes
# without necessarily needing to remount the device.
- # See #6851 for more.
+ # 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,nofail 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
+
+ # Retruns 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