summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2021-03-29 17:45:52 -0700
committerGitHub <noreply@github.com>2021-03-29 17:45:52 -0700
commit4da86eac281c88aaeb4df8e0c1b5bbb7f50922d5 (patch)
treeeb071747c62e817f04dc090ac434813b1fb4eebe
parenta0ecc1fea80f1e8fe0170442e86478953f93a4b5 (diff)
parent86ed1f1485da3fa0351cc755f1040e05e8d7387d (diff)
downloadchef-4da86eac281c88aaeb4df8e0c1b5bbb7f50922d5.tar.gz
Merge pull request #11263 from ramereth/chef-16-issue-11255
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/provider/mount.rb9
-rw-r--r--spec/unit/provider/mount/mount_spec.rb51
2 files changed, 58 insertions, 2 deletions
diff --git a/lib/chef/provider/mount.rb b/lib/chef/provider/mount.rb
index 44fb94ca01..7a85652a80 100644
--- a/lib/chef/provider/mount.rb
+++ b/lib/chef/provider/mount.rb
@@ -175,8 +175,13 @@ 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 issue.
- device = @new_resource.device == "/" ? @new_resource.device : @new_resource.device.chomp("/")
+ # Removed "/" from the end of str unless it's a network mount, because it was causing idempotency issue.
+ device =
+ if @new_resource.device == "/" || @new_resource.device.match?(":/$")
+ @new_resource.device
+ else
+ @new_resource.device.chomp("/")
+ end
case @new_resource.device_type
when :device
device
diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb
index 015e0038c8..13b2443b8f 100644
--- a/spec/unit/provider/mount/mount_spec.rb
+++ b/spec/unit/provider/mount/mount_spec.rb
@@ -506,6 +506,57 @@ describe Chef::Provider::Mount::Mount do
end
end
+ context "network mount" do
+ before(:each) do
+ @node = Chef::Node.new
+ @events = Chef::EventDispatch::Dispatcher.new
+ @run_context = Chef::RunContext.new(@node, {}, @events)
+
+ @new_resource = Chef::Resource::Mount.new("/tmp/bar")
+ @new_resource.device "cephserver:6789:/"
+ @new_resource.device_type :device
+ @new_resource.fstype "cephfs"
+
+ @new_resource.supports remount: false
+
+ @provider = Chef::Provider::Mount::Mount.new(@new_resource, @run_context)
+
+ allow(::File).to receive(:exists?).with("cephserver:6789:/").and_return true
+ allow(::File).to receive(:exists?).with("/tmp/bar").and_return true
+ allow(::File).to receive(:realpath).with("cephserver:6789:/").and_return "cephserver:6789:/"
+ allow(::File).to receive(:realpath).with("/tmp/bar").and_return "/tmp/foo"
+ end
+
+ before do
+ @current_resource = Chef::Resource::Mount.new("/tmp/foo")
+ @current_resource.device "cephserver:6789:/"
+ @current_resource.device_type :device
+ @current_resource.fstype "cephfs"
+
+ @provider.current_resource = @current_resource
+ end
+
+ it "should enable network mount if enabled isn't true" do
+ @current_resource.enabled(false)
+
+ @fstab = StringIO.new
+ allow(::File).to receive(:open).with("/etc/fstab", "a").and_yield(@fstab)
+ @provider.enable_fs
+ expect(@fstab.string).to match(%r{^cephserver:6789:/\s+/tmp/bar\s+cephfs\s+defaults\s+0\s+2\s*$})
+ end
+
+ it "should not enable network if enabled is true and resources match" do
+ @current_resource.enabled(true)
+ @current_resource.fstype("cephfs")
+ @current_resource.options(["defaults"])
+ @current_resource.dump(0)
+ @current_resource.pass(2)
+ expect(::File).not_to receive(:open).with("/etc/fstab", "a")
+
+ @provider.enable_fs
+ end
+ end
+
# the fstab might contain the mount with the device as a device but the resource has a label.
# we should not create two mount lines, but update the existing one
# not supported on solaris because it can't cope with a UUID device type