summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantima-gupta <agupta@msystechnologies.com>2020-11-10 04:28:35 -0800
committerantima-gupta <agupta@msystechnologies.com>2020-11-11 03:45:31 -0800
commit2ca48d25ddfe4ccea309271a7831db971c7a603e (patch)
tree31f90f1c0a78d62e9a33f04cdb7761732a9618d4
parentf583db2d28bb78622d55e6c4b1a26a64b55b1e41 (diff)
downloadchef-2ca48d25ddfe4ccea309271a7831db971c7a603e.tar.gz
Fixes for CIFS mount not idempotent issue.
Added spec for network device found as mounted. Removed '/' from end of the device value. Signed-off-by: antima-gupta <agupta@msystechnologies.com>
-rw-r--r--lib/chef/provider/mount.rb8
-rw-r--r--lib/chef/provider/mount/linux.rb4
-rw-r--r--lib/chef/provider/mount/mount.rb3
-rw-r--r--spec/unit/provider/mount/linux_spec.rb10
4 files changed, 21 insertions, 4 deletions
diff --git a/lib/chef/provider/mount.rb b/lib/chef/provider/mount.rb
index 64c7bc3f29..e4592a810d 100644
--- a/lib/chef/provider/mount.rb
+++ b/lib/chef/provider/mount.rb
@@ -175,13 +175,15 @@ class Chef
# Returns the new_resource device as per device_type
def device_fstab
+ # Removed "/" from the end of str, because it was causing idempotency issues
+ device = @new_resource.device.chomp("/")
case @new_resource.device_type
when :device
- @new_resource.device
+ device
when :label
- "LABEL=#{@new_resource.device}"
+ "LABEL=#{device}"
when :uuid
- "UUID=#{@new_resource.device}"
+ "UUID=#{device}"
end
end
end
diff --git a/lib/chef/provider/mount/linux.rb b/lib/chef/provider/mount/linux.rb
index 3199024f1b..bd1844e717 100644
--- a/lib/chef/provider/mount/linux.rb
+++ b/lib/chef/provider/mount/linux.rb
@@ -53,6 +53,10 @@ class Chef
when %r{\A#{Regexp.escape(real_mount_point)}\s+([/\w])+\[#{device_mount_regex}\]\s}
mounted = true
logger.trace("Bind device #{device_logstring} mounted as #{real_mount_point}")
+ # Permalink for network device mounted to an existing mount point: https://rubular.com/r/HicK63SqchPLvk
+ when %r{\A#{Regexp.escape(real_mount_point)}\s+#{device_mount_regex}\[([\/\w])+\]\s}
+ mounted = true
+ logger.trace("Network device #{device_logstring} mounted as #{real_mount_point}")
end
end
@current_resource.mounted(mounted)
diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb
index f6a7519c06..e065ce09e5 100644
--- a/lib/chef/provider/mount/mount.rb
+++ b/lib/chef/provider/mount/mount.rb
@@ -223,7 +223,8 @@ class Chef
@real_device = device_line.chomp unless device_line.nil?
end
end
- @real_device
+ # Removed "/" from the end of str, because it was causing idempotency issue.
+ @real_device.chomp("/")
end
def device_logstring
diff --git a/spec/unit/provider/mount/linux_spec.rb b/spec/unit/provider/mount/linux_spec.rb
index 1141175780..3e41f895d1 100644
--- a/spec/unit/provider/mount/linux_spec.rb
+++ b/spec/unit/provider/mount/linux_spec.rb
@@ -24,6 +24,7 @@ describe Chef::Provider::Mount::Linux do
before(:each) do
allow(::File).to receive(:exists?).with("/dev/sdz1").and_return true
allow(::File).to receive(:exists?).with("/tmp/foo").and_return true
+ allow(::File).to receive(:exists?).with("//192.168.11.102/Share/backup").and_return true
allow(::File).to receive(:realpath).with("/dev/sdz1").and_return "/dev/sdz1"
allow(::File).to receive(:realpath).with("/tmp/foo").and_return "/tmp/foo"
end
@@ -92,6 +93,15 @@ describe Chef::Provider::Mount::Linux do
expect(provider.current_resource.mounted).to be_falsey
end
+ it "should set mounted true if network_device? is true and the mount point is found in the mounts list" do
+ new_resource.device "//192.168.11.102/Share/backup"
+ new_resource.fstype "cifs"
+ mount = "/tmp/foo //192.168.11.102/Share/backup[/backup] cifs rw\n"
+ mount << "#{new_resource.mount_point} #{new_resource.device} type #{new_resource.fstype}\n"
+ allow(provider).to receive(:shell_out!).and_return(double(stdout: mount))
+ provider.load_current_resource
+ expect(provider.current_resource.mounted).to be_truthy
+ end
end
end