From e9149a9a0b0b17e0c1ad38ec60d82ac07269d9df Mon Sep 17 00:00:00 2001 From: Chibuikem Amaechi Date: Wed, 24 Jan 2018 05:07:46 -0600 Subject: Update /etc/fstab on FreeBSD #4959 /etc/fstab contains: /source /destination nullfs defaults 0 0 This does not mount after reboot. It should be: /source /destination nullfs rw 0 0 So "defaults" does not work on FreeBSD and must be replaced. Signed-off-by: Chibuikem Amaechi --- lib/chef/provider/mount/mount.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb index c3b1cc0141..9913916abc 100644 --- a/lib/chef/provider/mount/mount.rb +++ b/lib/chef/provider/mount/mount.rb @@ -158,7 +158,7 @@ class Chef disable_fs end ::File.open("/etc/fstab", "a") do |fstab| - fstab.puts("#{device_fstab} #{@new_resource.mount_point} #{@new_resource.fstype} #{@new_resource.options.nil? ? "defaults" : @new_resource.options.join(",")} #{@new_resource.dump} #{@new_resource.pass}") + fstab.puts("#{device_fstab} #{@new_resource.mount_point} #{@new_resource.fstype} #{@new_resource.options.nil? ? "rw" : @new_resource.options.join(",")} #{@new_resource.dump} #{@new_resource.pass}") Chef::Log.debug("#{@new_resource} is enabled at #{@new_resource.mount_point}") end end -- cgit v1.2.1 From fd39b4371fa22ce0569f35cb2503b7e2d176a8bb Mon Sep 17 00:00:00 2001 From: Chibuikem Amaechi Date: Sun, 28 Jan 2018 06:31:58 -0600 Subject: Improve handling of default mount options Signed-off-by: Chibuikem Amaechi --- lib/chef/provider/mount/mount.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb index 9913916abc..35336b4b4c 100644 --- a/lib/chef/provider/mount/mount.rb +++ b/lib/chef/provider/mount/mount.rb @@ -146,6 +146,15 @@ class Chef end end + # Return appropriate default mount options according to the input os. + def default_mount_options(os) + if os == "freebsd" + "rw" + else + "defaults" + end + end + def enable_fs if @current_resource.enabled && mount_options_unchanged? Chef::Log.debug("#{@new_resource} is already enabled - nothing to do") @@ -158,7 +167,7 @@ class Chef disable_fs end ::File.open("/etc/fstab", "a") do |fstab| - fstab.puts("#{device_fstab} #{@new_resource.mount_point} #{@new_resource.fstype} #{@new_resource.options.nil? ? "rw" : @new_resource.options.join(",")} #{@new_resource.dump} #{@new_resource.pass}") + fstab.puts("#{device_fstab} #{@new_resource.mount_point} #{@new_resource.fstype} #{@new_resource.options.nil? ? default_mount_options(node[:os]) : @new_resource.options.join(",")} #{@new_resource.dump} #{@new_resource.pass}") Chef::Log.debug("#{@new_resource} is enabled at #{@new_resource.mount_point}") end end -- cgit v1.2.1 From 0f45f8e107980a2cd49d4786fe5abd77b8085713 Mon Sep 17 00:00:00 2001 From: Chibuikem Amaechi Date: Sun, 28 Jan 2018 06:37:28 -0600 Subject: Update .../mount/mount_spec.rb Signed-off-by: Chibuikem Amaechi --- spec/unit/provider/mount/mount_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb index 20a4fd88dd..908635e958 100644 --- a/spec/unit/provider/mount/mount_spec.rb +++ b/spec/unit/provider/mount/mount_spec.rb @@ -374,6 +374,16 @@ describe Chef::Provider::Mount::Mount do end end + describe "default_mount_options" do + it "should return the correct default mount options for FreeBSD" do + expect(@provider.default_mount_options("freebsd")).to eq("rw") + end + + it "should return the correct default mount options for Linux" do + expect(@provider.default_mount_options("linux")).to eq("defaults") + end + end + describe "when enabling the fs" do it "should enable if enabled isn't true" do @current_resource.enabled(false) -- cgit v1.2.1 From 4f394f02120882f41909e742d763ab382f88682e Mon Sep 17 00:00:00 2001 From: Chibuikem Amaechi Date: Mon, 29 Jan 2018 23:09:24 -0600 Subject: Update logic in mount/mount.rb and mount/mount_spec.rb Signed-off-by: Chibuikem Amaechi --- lib/chef/provider/mount/mount.rb | 12 ++++-------- spec/unit/provider/mount/mount_spec.rb | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/chef/provider/mount/mount.rb b/lib/chef/provider/mount/mount.rb index 35336b4b4c..0be45e80da 100644 --- a/lib/chef/provider/mount/mount.rb +++ b/lib/chef/provider/mount/mount.rb @@ -146,13 +146,9 @@ class Chef end end - # Return appropriate default mount options according to the input os. - def default_mount_options(os) - if os == "freebsd" - "rw" - else - "defaults" - end + # Return appropriate default mount options according to the given os. + def default_mount_options + node[:os] == "linux" ? "defaults" : "rw" end def enable_fs @@ -167,7 +163,7 @@ class Chef disable_fs end ::File.open("/etc/fstab", "a") do |fstab| - fstab.puts("#{device_fstab} #{@new_resource.mount_point} #{@new_resource.fstype} #{@new_resource.options.nil? ? default_mount_options(node[:os]) : @new_resource.options.join(",")} #{@new_resource.dump} #{@new_resource.pass}") + fstab.puts("#{device_fstab} #{@new_resource.mount_point} #{@new_resource.fstype} #{@new_resource.options.nil? ? default_mount_options : @new_resource.options.join(",")} #{@new_resource.dump} #{@new_resource.pass}") Chef::Log.debug("#{@new_resource} is enabled at #{@new_resource.mount_point}") end end diff --git a/spec/unit/provider/mount/mount_spec.rb b/spec/unit/provider/mount/mount_spec.rb index 908635e958..b61dc65800 100644 --- a/spec/unit/provider/mount/mount_spec.rb +++ b/spec/unit/provider/mount/mount_spec.rb @@ -375,12 +375,24 @@ describe Chef::Provider::Mount::Mount do end describe "default_mount_options" do - it "should return the correct default mount options for FreeBSD" do - expect(@provider.default_mount_options("freebsd")).to eq("rw") + it "should return the correct default mount options for Linux" do + @provider.node.override[:os] = "linux" + expect(@provider.default_mount_options).to eq("defaults") end - it "should return the correct default mount options for Linux" do - expect(@provider.default_mount_options("linux")).to eq("defaults") + it "should return the correct default mount options for AIX" do + @provider.node.override[:os] = "aix" + expect(@provider.default_mount_options).to eq("rw") + end + + it "should return the correct default mount options for Darwin" do + @provider.node.override[:os] = "darwin" + expect(@provider.default_mount_options).to eq("rw") + end + + it "should return the correct default mount options for FreeBSD" do + @provider.node.override[:os] = "freebsd" + expect(@provider.default_mount_options).to eq("rw") end end -- cgit v1.2.1