diff options
author | Tim Smith <tsmith@chef.io> | 2021-05-10 12:38:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-10 12:38:02 -0700 |
commit | c2aaf67304a10e292476d5ab64099ee495b0a3e9 (patch) | |
tree | f1a7c25a8bc2163624cb4bb0d45c8a5442e7af28 | |
parent | 9a431747e0ca8a43f78e1fe343750871254631e8 (diff) | |
parent | 1d0ad75f33e74f1b9248f19c6f940deeaa3f5af7 (diff) | |
download | chef-c2aaf67304a10e292476d5ab64099ee495b0a3e9.tar.gz |
Merge pull request #11376 from MsysTechnologiesllc/smriti/10918_mount_resource_not_idempotent
mount: Fix idempotentency for loopback mounts
-rw-r--r-- | cspell.json | 1 | ||||
-rw-r--r-- | lib/chef/provider/mount/linux.rb | 8 | ||||
-rw-r--r-- | lib/chef/provider/mount/mount.rb | 5 | ||||
-rw-r--r-- | spec/unit/provider/mount/linux_spec.rb | 14 |
4 files changed, 27 insertions, 1 deletions
diff --git a/cspell.json b/cspell.json index 35f0bd8f24..5e14fa0c4a 100644 --- a/cspell.json +++ b/cspell.json @@ -837,6 +837,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 |