diff options
author | John McCrae <john.mccrae@progress.com> | 2022-06-14 12:38:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-14 12:38:37 -0700 |
commit | d0e7070b9d084aca68c2540b75e5e10129a24988 (patch) | |
tree | 601b9645949b0836c2efdd77b464ed628924b8df | |
parent | 9d008caf0de5794cb8b0768b256afa60af6f1bb2 (diff) | |
parent | 20497ffa8bc97598510fdd385b39a058512d2acb (diff) | |
download | chef-d0e7070b9d084aca68c2540b75e5e10129a24988.tar.gz |
Merge pull request #11626 from MsysTechnologiesllc/smriti/3884_mounting_cifs_shares_with_spaces
-rw-r--r-- | cspell.json | 1 | ||||
-rw-r--r-- | lib/chef/provider/mount/linux.rb | 5 | ||||
-rw-r--r-- | lib/chef/provider/mount/mount.rb | 8 | ||||
-rw-r--r-- | spec/unit/provider/mount/linux_spec.rb | 10 |
4 files changed, 24 insertions, 0 deletions
diff --git a/cspell.json b/cspell.json index 9d19afa372..5d62456013 100644 --- a/cspell.json +++ b/cspell.json @@ -14,6 +14,7 @@ "dictionaries": ["chef"], // words - list of words to be always considered correct "words": [ + "CIFS", "abcz", "abdulin", "ABORTIFHUNG", diff --git a/lib/chef/provider/mount/linux.rb b/lib/chef/provider/mount/linux.rb index 83fbfab957..899053b613 100644 --- a/lib/chef/provider/mount/linux.rb +++ b/lib/chef/provider/mount/linux.rb @@ -71,6 +71,11 @@ class Chef when /\A#{Regexp.escape(real_mount_point)}\s+#{device_mount_regex}\[/ mounted = true logger.trace("Network device #{device_logstring} mounted as #{real_mount_point}") + # Permalink for network device mounted with a space in device name https://rubular.com/r/CK5zWWms96CRES + # See the comment in "device_with_space_escape" for an explanation what's going here. + when /\A#{Regexp.escape(real_mount_point)}\s+#{device_with_space_escape}\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 2bc9d2c78f..2021d6ece5 100644 --- a/lib/chef/provider/mount/mount.rb +++ b/lib/chef/provider/mount/mount.rb @@ -217,6 +217,14 @@ class Chef end end + def device_with_space_escape + # For CIFS (and perhaps other remote network mounts) when a space is in the "device name" + # It will appear with the space substituted with a special character. However, when mounting, + # The mount needs to be done with an actual space. This function provides the device name with + # The special character to determine if the device is mounted. + device_mount_regex.gsub(" ", "\\x20") + end + def device_mount_regex if network_device? # ignore trailing slash diff --git a/spec/unit/provider/mount/linux_spec.rb b/spec/unit/provider/mount/linux_spec.rb index 188777a19b..21f45d7fdd 100644 --- a/spec/unit/provider/mount/linux_spec.rb +++ b/spec/unit/provider/mount/linux_spec.rb @@ -25,6 +25,7 @@ describe Chef::Provider::Mount::Linux 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(:exists?).with("//192.168.11.102/Share/backup folder").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 @@ -103,6 +104,15 @@ describe Chef::Provider::Mount::Linux do provider.load_current_resource expect(provider.current_resource.mounted).to be_truthy end + + it "should set mounted true if device name has a space and the mount point is found in the mounts list" do + new_resource.device "//192.168.11.102/Share/backup folder" + new_resource.fstype "cifs" + mount = "/tmp/foo //192.168.11.102/Share/backup\x20folder cifs rw\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 context "to check if loop resource is mounted" do |