summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmriti <sgarg@msystechnologies.com>2021-04-15 12:38:23 +0530
committersmriti <sgarg@msystechnologies.com>2021-04-22 10:22:55 +0530
commit1d0ad75f33e74f1b9248f19c6f940deeaa3f5af7 (patch)
tree2362e417a0490c475307c31e12a828f97a578a3d
parent672fd930d5eafb1c38b02eabf396655b05fb0135 (diff)
downloadchef-1d0ad75f33e74f1b9248f19c6f940deeaa3f5af7.tar.gz
Kept a check in pattern matching for a mount of type loop
Signed-off-by: smriti <sgarg@msystechnologies.com>
-rw-r--r--cspell.json1
-rw-r--r--lib/chef/provider/mount/linux.rb8
-rw-r--r--lib/chef/provider/mount/mount.rb5
-rw-r--r--spec/unit/provider/mount/linux_spec.rb14
4 files changed, 27 insertions, 1 deletions
diff --git a/cspell.json b/cspell.json
index a54071a0db..67994b53c2 100644
--- a/cspell.json
+++ b/cspell.json
@@ -861,6 +861,7 @@
"logstring",
"LONGLONG",
"loopback",
+ "losetup",
"lowercased",
"LOWORD",
"lpar",
diff --git a/lib/chef/provider/mount/linux.rb b/lib/chef/provider/mount/linux.rb
index 382e37d41a..6b07ec9d32 100644
--- a/lib/chef/provider/mount/linux.rb
+++ b/lib/chef/provider/mount/linux.rb
@@ -45,6 +45,14 @@ class Chef
when /\A#{Regexp.escape(real_mount_point)}\s+#{device_mount_regex}\s/
mounted = true
logger.trace("Special device #{device_logstring} mounted as #{real_mount_point}")
+ # Permalink for loop type devices mount points https://rubular.com/r/a0bS4p2RvXsGxx
+ when %r{\A#{Regexp.escape(real_mount_point)}\s+\/dev\/loop+[0-9]+\s}
+ @loop_mount_points.each_line do |mount_point|
+ if mount_point.include? device_real
+ mounted = true
+ break
+ end
+ end
# Permalink for multiple devices mounted to the same mount point(i.e. '/proc') https://rubular.com/r/a356yzspU7N9TY
when %r{\A#{Regexp.escape(real_mount_point)}\s+([/\w])+\s}
mounted = false
diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb
index 802ee11c23..cd42c79aa8 100644
--- a/lib/chef/provider/mount/mount.rb
+++ b/lib/chef/provider/mount/mount.rb
@@ -29,6 +29,7 @@ class Chef
def initialize(new_resource, run_context)
super
@real_device = nil
+ initialize_loop_mounts
end
attr_accessor :real_device
@@ -40,6 +41,10 @@ class Chef
enabled?
end
+ def initialize_loop_mounts
+ @loop_mount_points = shell_out!("losetup --list").stdout
+ end
+
def mountable?
# only check for existence of non-remote devices
if device_should_exist? && !::File.exists?(device_real)
diff --git a/spec/unit/provider/mount/linux_spec.rb b/spec/unit/provider/mount/linux_spec.rb
index 3e41f895d1..3e1ce1ace1 100644
--- a/spec/unit/provider/mount/linux_spec.rb
+++ b/spec/unit/provider/mount/linux_spec.rb
@@ -12,7 +12,7 @@ describe Chef::Provider::Mount::Linux do
new_resource = Chef::Resource::Mount.new("/tmp/foo")
new_resource.device "/dev/sdz1"
new_resource.device_type :device
- new_resource.fstype "ext3"
+ new_resource.fstype "ext3"
new_resource.supports remount: false
new_resource
end
@@ -104,4 +104,16 @@ describe Chef::Provider::Mount::Linux do
end
end
+ context "to check if loop resource is mounted" do
+ it "should set mounted true in case of loop resource" do
+ new_resource.options "loop"
+ mount = "/tmp/foo /dev/loop16 iso660 cifs ro\n"
+ losetup = "/dev/loop16 0 0 1 1 /dev/sdz1 \n"
+ allow(provider).to receive(:shell_out!).with("findmnt -rn").and_return(double(stdout: mount))
+ allow(provider).to receive(:shell_out!).with("losetup --list").and_return(double(stdout: losetup))
+ provider.load_current_resource
+ expect(provider.current_resource.mounted).to be_truthy
+ end
+ end
+
end