diff options
author | NAshwini <ashwini.nehate@msystechnologies.com> | 2017-07-06 01:40:48 +0530 |
---|---|---|
committer | Bryan McLellan <btm@loftninjas.org> | 2017-07-05 16:10:48 -0400 |
commit | ae4d04bbe366199e4597b375b43c254d0117c989 (patch) | |
tree | 98c553435578d40b9e272bd3dbfbf08be717bec3 | |
parent | e419d7f0eb0c494a0a2f5d5963eac6fb35153bac (diff) | |
download | chef-ae4d04bbe366199e4597b375b43c254d0117c989.tar.gz |
[MSYS-590] Make mount idempotent on Aix (#6213)
* Make mount idempotent on Aix
Signed-off-by: NAshwini <ashwini.nehate@msystechnologies.com>
-rw-r--r-- | lib/chef/provider/mount/aix.rb | 57 | ||||
-rw-r--r-- | spec/unit/provider/mount/aix_spec.rb | 34 |
2 files changed, 82 insertions, 9 deletions
diff --git a/lib/chef/provider/mount/aix.rb b/lib/chef/provider/mount/aix.rb index 73460e84a1..ef760b0ba6 100644 --- a/lib/chef/provider/mount/aix.rb +++ b/lib/chef/provider/mount/aix.rb @@ -40,30 +40,60 @@ class Chef # Check to see if there is an entry in /etc/filesystems. Last entry for a volume wins. Using command "lsfs" to fetch entries. enabled = false + regex_arr = device_fstab_regex.split(":") + if regex_arr.size.eql?(2) + nodename = regex_arr[0] + devicename = regex_arr[1] + else + devicename = regex_arr[0] + end # lsfs o/p = #MountPoint:Device:Vfs:Nodename:Type:Size:Options:AutoMount:Acct # search only for current mount point shell_out("lsfs -c #{@new_resource.mount_point}").stdout.each_line do |line| case line when /^#\s/ next - when /^#{Regexp.escape(@new_resource.mount_point)}:#{device_fstab_regex}:(\S+):(\[\S+\])?:(\S+)?:(\S+):(\S+):(\S+):(\S+)/ + when /^#{Regexp.escape(@new_resource.mount_point)}:#{devicename}:(\S+):#{nodename}:(\S+)?:(\S+):(\S+):(\S+):(\S+)/ # mount point entry with ipv6 address for nodename (ipv6 address use ':') enabled = true @current_resource.fstype($1) - @current_resource.options($5) - Chef::Log.debug("Found mount #{device_fstab} to #{@new_resource.mount_point} in /etc/filesystems") + @current_resource.options($4) + Chef::Log.debug("Found mount point #{@new_resource.mount_point} :: device_type #{@current_resource.device_type} in /etc/filesystems") next - when /^#{Regexp.escape(@new_resource.mount_point)}:#{device_fstab_regex}::(\S+):(\S+)?:(\S+)?:(\S+):(\S+):(\S+):(\S+)/ + when /^#{Regexp.escape(@new_resource.mount_point)}:#{nodename}:(\S+)::(\S+)?:(\S+):(\S+):(\S+):(\S+)/ # mount point entry with hostname or ipv4 address enabled = true @current_resource.fstype($1) + @current_resource.options($4) + @current_resource.device("") + Chef::Log.debug("Found mount point #{@new_resource.mount_point} :: device_type #{@current_resource.device_type} in /etc/filesystems") + next + when /^#{Regexp.escape(@new_resource.mount_point)}:(\S+)?:(\S+):#{devicename}:(\S+)?:(\S+):(\S+):(\S+):(\S+)/ + # mount point entry with hostname or ipv4 address + enabled = true + @current_resource.fstype($2) @current_resource.options($5) - Chef::Log.debug("Found mount #{device_fstab} to #{@new_resource.mount_point} in /etc/filesystems") + @current_resource.device(devicename + "/") + Chef::Log.debug("Found mount point #{@new_resource.mount_point} :: device_type #{@current_resource.device_type} in /etc/filesystems") next - when /^#{Regexp.escape(@new_resource.mount_point)}/ - enabled = false - Chef::Log.debug("Found conflicting mount point #{@new_resource.mount_point} in /etc/filesystems") + when /^#{Regexp.escape(@new_resource.mount_point)}:(.*?):(.*?):(.*?):(.*?):(.*?):(.*?):(.*?):(.*?)/ + if $3.split("=")[0].eql?("LABEL") || $1.split("=")[0].eql?("LABEL") + @current_resource.device_type("label") + elsif $3.split("=")[0].eql?("UUID") || $1.split("=")[0].eql?("UUID") + @current_resource.device_type("uuid") + else + @current_resource.device_type("device") + end + + if @current_resource.device_type != @new_resource.device_type + enabled = true + Chef::Log.debug("Found mount point #{@new_resource.mount_point} :: device_type #{@current_resource.device_type} in /etc/filesystems") + else + enabled = false + Chef::Log.debug("Found conflicting mount point #{@new_resource.mount_point} in /etc/filesystems") + end end + end @current_resource.enabled(enabled) end @@ -149,6 +179,17 @@ class Chef end end + def mount_options_unchanged? + current_resource_options = @current_resource.options.delete_if { |x| x == "rw" } + + @current_resource.device == @new_resource.device && + @current_resource.fsck_device == @new_resource.fsck_device && + @current_resource.fstype == @new_resource.fstype && + current_resource_options == @new_resource.options && + @current_resource.dump == @new_resource.dump && + @current_resource.pass == @new_resource.pass + end + def disable_fs contents = [] if @current_resource.enabled diff --git a/spec/unit/provider/mount/aix_spec.rb b/spec/unit/provider/mount/aix_spec.rb index 3371c270c5..615f3c3304 100644 --- a/spec/unit/provider/mount/aix_spec.rb +++ b/spec/unit/provider/mount/aix_spec.rb @@ -44,6 +44,11 @@ MOUNT #MountPoint:Device:Vfs:Nodename:Type:Size:Options:AutoMount:Acct /tmp/foo:/dev/sdz1:jfs2::bootfs:10485760:rw:yes:no ENABLED + + @test_wrong_output = <<-WRONG +#MountPoint:Device:Vfs:Nodename:Type:Size:Options:AutoMount:Acct +/tmp/foo::/dev/sdz1:jfs2:bootfs:10485760:rw:yes:no +WRONG end before(:each) do @@ -102,6 +107,25 @@ ENABLED expect(@provider.current_resource.mounted).to be_falsey end + + context "mount_options_unchanged?" do + it "should return true if mounted device is the same" do + stub_mounted_enabled(@provider, @mounted_output, @enabled_output) + @provider.load_current_resource + + allow(@provider.current_resource).to receive(:fstype).and_return("jfs2") + expect(@provider.send :mount_options_unchanged?).to be true + end + + it "should return false if mounted device has changed" do + stub_mounted_enabled(@provider, @mounted_output, @enabled_output) + @provider.load_current_resource + + allow(@provider.current_resource).to receive(:fstype).and_return("XXXX") + expect(@provider.send :mount_options_unchanged?).to be false + end + end + end # tests for #enabled? @@ -188,12 +212,20 @@ ENABLED it "should not enable mount if it is mounted and already enabled and mount options are unchanged" do stub_mounted_enabled(@provider, @mounted_output, @enabled_output) - @new_resource.options "rw" expect(@provider).not_to receive(:enable_fs) @provider.run_action(:enable) end + + it "should return false if enabled_output is given in wrong syntax" do + stub_mounted_enabled(@provider, @mounted_output, @test_wrong_output) + + expect(@provider).to receive(:enable_fs) + + @provider.run_action(:enable) + end + end describe "disable_fs" do |