summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-10-10 11:47:28 -0700
committerGitHub <noreply@github.com>2018-10-10 11:47:28 -0700
commitb4bb7f239549b0499050c79f34d28894a6ef0bc5 (patch)
tree8ce31f8b75d8731435aec226c1249d5ec9e01126
parent1b96f8bfc8a5873984971d7634eb6e49db842a08 (diff)
parent8a82f7416502e3a312d822d9e0c56a4e0c44c217 (diff)
downloadohai-b4bb7f239549b0499050c79f34d28894a6ef0bc5.tar.gz
Merge pull request #1266 from jaymzh/finish_fs2_work
[filesystem] Convert rest of unix to fs2
-rw-r--r--lib/ohai/plugins/aix/filesystem.rb90
-rw-r--r--lib/ohai/plugins/filesystem.rb441
-rw-r--r--lib/ohai/plugins/solaris2/filesystem.rb106
-rw-r--r--spec/unit/plugins/aix/filesystem_spec.rb24
-rw-r--r--spec/unit/plugins/solaris2/filesystem.rb387
5 files changed, 704 insertions, 344 deletions
diff --git a/lib/ohai/plugins/aix/filesystem.rb b/lib/ohai/plugins/aix/filesystem.rb
deleted file mode 100644
index b044aeee..00000000
--- a/lib/ohai/plugins/aix/filesystem.rb
+++ /dev/null
@@ -1,90 +0,0 @@
-#
-# Author:: Deepali Jagtap (<deepali.jagtap@clogeny.com>)
-# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
-# Author:: Isa Farnik (<isa@chef.io>)
-# Copyright:: Copyright (c) 2013-2016 Chef Software, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-Ohai.plugin(:Filesystem) do
- provides "filesystem"
-
- def parse_df_or_mount(shell_out)
- oldie = Mash.new
-
- shell_out.lines.each do |line|
- fields = line.split
- case line
- # headers and horizontal rules to skip
- when /^\s*(node|---|^Filesystem\s+1024-blocks)/
- next
- # strictly a df entry
- when /^(.+?)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+\%*)\s+(.+)$/
- if $1 == "Global"
- key = "#{$1}:#{$6}"
- else
- key = $1
- end
- oldie[key] ||= Mash.new
- oldie[key][:kb_size] = $2
- oldie[key][:kb_used] = $3
- oldie[key][:kb_available] = $4
- oldie[key][:percent_used] = $5
- oldie[key][:mount] = $6
- # an entry starting with 'G' or / (E.G. /tmp or /var)
- when /^\s*(G.*?|\/\w)/
- if fields[0] == "Global"
- key = fields[0] + ":" + fields[1]
- else
- key = fields[0]
- end
- oldie[key] ||= Mash.new
- oldie[key][:mount] = fields[1]
- oldie[key][:fs_type] = fields[2]
- oldie[key][:mount_options] = fields[6].split(",")
- # entries occupying the 'Node' column parsed here
- else
- key = fields[0] + ":" + fields[1]
- oldie[key] ||= Mash.new
- oldie[key][:mount] = fields[2]
- oldie[key][:fs_type] = fields[3]
- oldie[key][:mount_options] = fields[7].split(",")
- end
- end
- oldie
- end
-
- def collect_old_version(shell_outs)
- mount_hash = parse_df_or_mount shell_outs[:mount]
- df_hash = parse_df_or_mount shell_outs[:df_Pk]
-
- mount_hash.each do |key, hash|
- df_hash[key].merge!(hash) if df_hash.key?(key)
- end
-
- mount_hash.merge(df_hash)
- end
-
- collect_data(:aix) do
-
- # Cache the command output
- shell_outs = Mash.new
- shell_outs[:mount] = shell_out("mount").stdout
- shell_outs[:df_Pk] = shell_out("df -Pk").stdout
-
- filesystem collect_old_version(shell_outs)
- end
-end
diff --git a/lib/ohai/plugins/filesystem.rb b/lib/ohai/plugins/filesystem.rb
index e2cc89bc..1a823f8b 100644
--- a/lib/ohai/plugins/filesystem.rb
+++ b/lib/ohai/plugins/filesystem.rb
@@ -1,6 +1,11 @@
#
# Author:: Phil Dibowitz <phil@ipom.com>
# Author:: Adam Jacob <adam@chef.io>
+# Author:: Kurt Yoder (ktyopscode@yoderhome.com)
+# Author:: Deepali Jagtap (<deepali.jagtap@clogeny.com>)
+# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
+# Author:: Isa Farnik (<isa@chef.io>)
+# Author:: James Gartrell (<jgartrel@gmail.com>)
# Copyright:: Copyright (c) 2008-2017 Chef Software, Inc.
# Copyright:: Copyright (c) 2015 Facebook, Inc.
# License:: Apache License, Version 2.0
@@ -99,27 +104,58 @@ Ohai.plugin(:Filesystem) do
view
end
+ def generate_deprecated_solaris_view(fs, old_zfs)
+ view = generate_deprecated_view(fs)
+ old_zfs.each do |fsname, attributes|
+ view[fsname] ||= Mash.new
+ view[fsname][:fs_type] = "zfs"
+ view[fsname][:mount] = attributes[:values][:mountpoint] if attributes[:values].key?("mountpoint")
+ view[fsname][:device] = fsname
+ view[fsname][:zfs_values] = attributes[:values]
+ view[fsname][:zfs_sources] = attributes[:sources]
+ # parents will already be here
+ # but we want to nuke "zfs_properties"
+ view[fsname].delete("zfs_properties")
+ end
+ view
+ end
+
+ def parse_common_df(out)
+ fs = {}
+ out.each_line do |line|
+ case line
+ when /^Filesystem\s+1024-blocks/
+ next
+ when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
+ key = "#{$1},#{$6}"
+ fs[key] = Mash.new
+ fs[key][:device] = $1
+ fs[key][:kb_size] = $2
+ fs[key][:kb_used] = $3
+ fs[key][:kb_available] = $4
+ fs[key][:percent_used] = $5
+ fs[key][:mount] = $6
+ end
+ end
+ fs
+ end
+
+ def run_with_check(bin, &block)
+ yield
+ rescue Ohai::Exceptions::Exec => e
+ unless Ohai.config[:plugin][:filesystem][:allow_partial_data]
+ raise e
+ end
+ logger.warn("Plugin Filesystem: #{bin} binary is not available. Some data will not be available.")
+ end
+
collect_data(:linux) do
fs = Mash.new
# Grab filesystem data from df
- begin
+ run_with_check("df") do
so = shell_out("df -P")
- so.stdout.each_line do |line|
- case line
- when /^Filesystem\s+1024-blocks/
- next
- when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
- key = "#{$1},#{$6}"
- fs[key] = Mash.new
- fs[key][:device] = $1
- fs[key][:kb_size] = $2
- fs[key][:kb_used] = $3
- fs[key][:kb_available] = $4
- fs[key][:percent_used] = $5
- fs[key][:mount] = $6
- end
- end
+ fs.merge!(parse_common_df(so.stdout))
# Grab filesystem inode data from df
so = shell_out("df -iP")
@@ -138,15 +174,10 @@ Ohai.plugin(:Filesystem) do
fs[key][:mount] = $6
end
end
- rescue Ohai::Exceptions::Exec => e
- unless Ohai.config[:plugin][:filesystem][:allow_partial_data]
- raise e
- end
- logger.warn("Plugin Filesystem: df binary is not available. Some data will not be available.")
end
# Grab mount information from /bin/mount
- begin
+ run_with_check("mount") do
so = shell_out("mount")
so.stdout.each_line do |line|
if line =~ /^(.+?) on (.+?) type (.+?) \((.+?)\)$/
@@ -158,11 +189,6 @@ Ohai.plugin(:Filesystem) do
fs[key][:mount_options] = $4.split(",")
end
end
- rescue Ohai::Exceptions::Exec
- unless Ohai.config[:plugin][:filesystem][:allow_partial_data]
- raise e
- end
- logger.warn("Plugin Filesystem: mount binary is not available. Some data will not be available.")
end
# We used to try to decide if we wanted to run lsblk or blkid
@@ -187,28 +213,30 @@ Ohai.plugin(:Filesystem) do
# setting the timeout here for `lsblk` and `blkid` commands to 60
# this is to allow machines with large amounts of attached LUNs
# to respond back to the command successfully
- so = shell_out(cmd, timeout: 60)
- so.stdout.each_line do |line|
- parsed = parse_line(line, cmdtype)
- next if parsed.nil?
- # lsblk lists each device once, so we need to update all entries
- # in the hash that are related to this device
- keys_to_update = []
- fs.each_key do |key|
- keys_to_update << key if key.start_with?("#{parsed[:dev]},")
- end
+ run_with_check(cmdtype) do
+ so = shell_out(cmd, timeout: 60)
+ so.stdout.each_line do |line|
+ parsed = parse_line(line, cmdtype)
+ next if parsed.nil?
+ # lsblk lists each device once, so we need to update all entries
+ # in the hash that are related to this device
+ keys_to_update = []
+ fs.each_key do |key|
+ keys_to_update << key if key.start_with?("#{parsed[:dev]},")
+ end
- if keys_to_update.empty?
- key = "#{parsed[:dev]},"
- fs[key] = Mash.new
- fs[key][:device] = parsed[:dev]
- keys_to_update << key
- end
+ if keys_to_update.empty?
+ key = "#{parsed[:dev]},"
+ fs[key] = Mash.new
+ fs[key][:device] = parsed[:dev]
+ keys_to_update << key
+ end
- keys_to_update.each do |k|
- [:fs_type, :uuid, :label].each do |subkey|
- if parsed[subkey] && !parsed[subkey].empty?
- fs[k][subkey] = parsed[subkey]
+ keys_to_update.each do |k|
+ [:fs_type, :uuid, :label].each do |subkey|
+ if parsed[subkey] && !parsed[subkey].empty?
+ fs[k][subkey] = parsed[subkey]
+ end
end
end
end
@@ -264,51 +292,40 @@ Ohai.plugin(:Filesystem) do
fs = Mash.new
# Grab filesystem data from df
- so = shell_out("df")
- so.stdout.lines do |line|
- case line
- when /^Filesystem/
- next
- when /^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(\S+)$/
- key = "#{$1},#{$6}"
- fs[key] = Mash.new
- fs[key][:device] = $1
- fs[key][:kb_size] = $2
- fs[key][:kb_used] = $3
- fs[key][:kb_available] = $4
- fs[key][:percent_used] = $5
- fs[key][:mount] = $6
- end
- end
+ run_with_check("df") do
+ so = shell_out("df")
+ fs.merge!(parse_common_df(so.stdout))
- # inode parsing from 'df -iP'
- so = shell_out("df -iP")
- so.stdout.lines do |line|
- case line
- when /^Filesystem/ # skip the header
- next
- when /^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\%\s+(\d+)\s+(\d+)\s+(\d+)%\s+(\S+)$/
- key = "#{$1},#{$9}"
- fs[key] ||= Mash.new
- fs[key][:device] = $1
- fs[key][:inodes_used] = $6
- fs[key][:inodes_available] = $7
- fs[key][:total_inodes] = ($6.to_i + $7.to_i).to_s
- fs[key][:inodes_percent_used] = $8
- fs[key][:mount] = $9
+ so = shell_out("df -iP")
+ so.stdout.lines do |line|
+ case line
+ when /^Filesystem/ # skip the header
+ next
+ when /^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\%\s+(\d+)\s+(\d+)\s+(\d+)%\s+(\S+)$/
+ key = "#{$1},#{$9}"
+ fs[key] ||= Mash.new
+ fs[key][:device] = $1
+ fs[key][:inodes_used] = $6
+ fs[key][:inodes_available] = $7
+ fs[key][:total_inodes] = ($6.to_i + $7.to_i).to_s
+ fs[key][:inodes_percent_used] = $8
+ fs[key][:mount] = $9
+ end
end
end
# Grab mount information from mount
- so = shell_out("mount -l")
- so.stdout.lines do |line|
- if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/
- key = "#{$1},#{$2}"
- fs[key] ||= Mash.new
- fs[key][:device] = $1
- fs[key][:mount] = $2
- fs[key][:fs_type] = $3
- fs[key][:mount_options] = $4.split(/,\s*/)
+ run_with_check("mount") do
+ so = shell_out("mount -l")
+ so.stdout.lines do |line|
+ if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/
+ key = "#{$1},#{$2}"
+ fs[key] ||= Mash.new
+ fs[key][:device] = $1
+ fs[key][:mount] = $2
+ fs[key][:fs_type] = $3
+ fs[key][:mount_options] = $4.split(/,\s*/)
+ end
end
end
@@ -333,37 +350,41 @@ Ohai.plugin(:Filesystem) do
block_size = 0
# on new versions of OSX, -i is default, on old versions it's not, so
# specifying it gets consistent output
- so = shell_out("df -i")
- so.stdout.each_line do |line|
- case line
- when /^Filesystem\s+(\d+)-/
- block_size = $1.to_i
- next
- when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(\d+)\s+(\d+)\s+(\d+%)\s+(.+)$/
- key = "#{$1},#{$9}"
- fs[key] = Mash.new
- fs[key][:block_size] = block_size
- fs[key][:device] = $1
- fs[key][:kb_size] = ($2.to_i / (1024 / block_size)).to_s
- fs[key][:kb_used] = ($3.to_i / (1024 / block_size)).to_s
- fs[key][:kb_available] = ($4.to_i / (1024 / block_size)).to_s
- fs[key][:percent_used] = $5
- fs[key][:inodes_used] = $6
- fs[key][:inodes_available] = $7
- fs[key][:total_inodes] = ($6.to_i + $7.to_i).to_s
- fs[key][:inodes_percent_used] = $8
- fs[key][:mount] = $9
+ run_with_check("df") do
+ so = shell_out("df -i")
+ so.stdout.each_line do |line|
+ case line
+ when /^Filesystem\s+(\d+)-/
+ block_size = $1.to_i
+ next
+ when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(\d+)\s+(\d+)\s+(\d+%)\s+(.+)$/
+ key = "#{$1},#{$9}"
+ fs[key] = Mash.new
+ fs[key][:block_size] = block_size
+ fs[key][:device] = $1
+ fs[key][:kb_size] = ($2.to_i / (1024 / block_size)).to_s
+ fs[key][:kb_used] = ($3.to_i / (1024 / block_size)).to_s
+ fs[key][:kb_available] = ($4.to_i / (1024 / block_size)).to_s
+ fs[key][:percent_used] = $5
+ fs[key][:inodes_used] = $6
+ fs[key][:inodes_available] = $7
+ fs[key][:total_inodes] = ($6.to_i + $7.to_i).to_s
+ fs[key][:inodes_percent_used] = $8
+ fs[key][:mount] = $9
+ end
end
end
- so = shell_out("mount")
- so.stdout.lines do |line|
- if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/
- key = "#{$1},#{$2}"
- fs[key] = Mash.new unless fs.key?(key)
- fs[key][:mount] = $2
- fs[key][:fs_type] = $3
- fs[key][:mount_options] = $4.split(/,\s*/)
+ run_with_check("mount") do
+ so = shell_out("mount")
+ so.stdout.lines do |line|
+ if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/
+ key = "#{$1},#{$2}"
+ fs[key] = Mash.new unless fs.key?(key)
+ fs[key][:mount] = $2
+ fs[key][:fs_type] = $3
+ fs[key][:mount_options] = $4.split(/,\s*/)
+ end
end
end
@@ -378,4 +399,194 @@ Ohai.plugin(:Filesystem) do
filesystem fs_data
end
+
+ collect_data(:solaris2) do
+ fs = Mash.new
+
+ # Grab filesystem data from df
+ run_with_check("df") do
+ so = shell_out("df -Pka")
+ fs.merge!(parse_common_df(so.stdout))
+
+ # Grab file system type from df (must be done separately)
+ so = shell_out("df -na")
+ so.stdout.lines do |line|
+ next unless line =~ /^(.+?)\s*: (\S+)\s*$/
+ mount = $1
+ fs.each do |key, fs_attributes|
+ next unless fs_attributes[:mount] == mount
+ fs[key][:fs_type] = $2
+ end
+ end
+ end
+
+ # Grab mount information from /bin/mount
+ run_with_check("mount") do
+ so = shell_out("mount")
+ so.stdout.lines do |line|
+ next unless line =~ /^(.+?) on (.+?) (.+?) on (.+?)$/
+ key = "#{$2},#{$1}"
+ fs[key] = Mash.new unless fs.key?(key)
+ fs[key][:mount] = $1
+ fs[key][:mount_time] = $4 # $4 must come before "split", else it becomes nil
+ fs[key][:mount_options] = $3.split("/")
+ end
+ end
+
+ # Grab any zfs data from "zfs get"
+ zfs = Mash.new
+ old_zfs = Mash.new
+ zfs_get = "zfs get -p -H all"
+ run_with_check("zfs") do
+ so = shell_out(zfs_get)
+ so.stdout.lines do |line|
+ next unless line =~ /^([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)$/
+ filesystem = $1
+ property = $2
+ value = $3
+ source = $4.chomp
+ zfs[filesystem] ||= Mash.new
+ # if this fs doesn't exist, put in the bare minimum
+ zfs[filesystem][property] = {
+ value: value,
+ source: source,
+ }
+ # needed for old v1 view
+ old_zfs[filesystem] ||= Mash.new
+ old_zfs[filesystem][:values] ||= Mash.new
+ old_zfs[filesystem][:sources] ||= Mash.new
+ old_zfs[filesystem][:values][property] = value
+ old_zfs[filesystem][:values][property] = value
+ old_zfs[filesystem][:sources][property] = source
+ end
+ end
+
+ zfs.each do |fsname, attributes|
+ mountpoint = attributes[:mountpoint][:value] if attributes[:mountpoint]
+ key = "#{fsname},#{mountpoint}"
+ fs[key] ||= Mash.new
+ fs[key][:fs_type] = "zfs"
+ fs[key][:mount] = mountpoint if mountpoint
+ fs[key][:device] = fsname
+ fs[key][:zfs_properties] = attributes
+ # find all zfs parents
+ parents = fsname.split("/")
+ zfs_parents = []
+ (0..parents.length - 1).to_a.each do |parent_index|
+ next_parent = parents[0..parent_index].join("/")
+ zfs_parents.push(next_parent)
+ end
+ zfs_parents.pop
+ fs[key][:zfs_parents] = zfs_parents
+ fs[key][:zfs_zpool] = (zfs_parents.length == 0)
+ end
+
+ # create views
+ by_pair = fs
+ by_device = generate_device_view(fs)
+ by_mountpoint = generate_mountpoint_view(fs)
+
+ fs_data = Mash.new
+ fs_data["by_device"] = by_device
+ fs_data["by_mountpoint"] = by_mountpoint
+ fs_data["by_pair"] = by_pair
+
+ # Set the filesystem data - Solaris didn't do the conversion when everyone
+ # else did, so 15 will have both be the new API and 16 will drop the old API
+ filesystem generate_deprecated_solaris_view(fs, old_zfs)
+ filesystem2 fs_data
+ end
+
+ collect_data(:aix) do
+ def parse_df_or_mount(shell_out)
+ oldie = Mash.new
+
+ shell_out.lines.each do |line|
+ fields = line.split
+ case line
+ # headers and horizontal rules to skip
+ when /^\s*(node|---|^Filesystem\s+1024-blocks)/
+ next
+ # strictly a df entry
+ when /^(.+?)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+\%*)\s+(.+)$/
+ if $1 == "Global"
+ dev = "#{$1}:#{$6}"
+ else
+ dev = $1
+ end
+ mountpoint = $6
+ key = "#{dev},#{mountpoint}"
+ oldie[key] ||= Mash.new
+ oldie[key][:kb_size] = $2
+ oldie[key][:kb_used] = $3
+ oldie[key][:kb_available] = $4
+ oldie[key][:percent_used] = $5
+ oldie[key][:mount] = mountpoint
+ oldie[key][:device] = dev
+ # an entry starting with 'G' or / (E.G. /tmp or /var)
+ when /^\s*(G.*?|\/\w)/
+ if fields[0] == "Global"
+ dev = fields[0] + ":" + fields[1]
+ else
+ dev = fields[0]
+ end
+ mountpoint = fields[1]
+ key = "#{dev},#{mountpoint}"
+ oldie[key] ||= Mash.new
+ oldie[key][:mount] = mountpoint
+ oldie[key][:fs_type] = fields[2]
+ oldie[key][:mount_options] = fields[6].split(",")
+ oldie[key][:device] = dev
+ # entries occupying the 'Node' column parsed here
+ else
+ dev = fields[0] + ":" + fields[1]
+ mountpoint = fields[2]
+ key = "#{dev},#{mountpoint}"
+ oldie[key] ||= Mash.new
+ oldie[key][:mount] = mountpoint
+ oldie[key][:device] = dev
+ oldie[key][:fs_type] = fields[3]
+ oldie[key][:mount_options] = fields[7].split(",")
+ end
+ end
+ oldie
+ end
+
+ def collect_old_version(shell_outs)
+ mount_hash = parse_df_or_mount shell_outs[:mount]
+ df_hash = parse_df_or_mount shell_outs[:df_Pk]
+
+ mount_hash.each do |key, hash|
+ df_hash[key].merge!(hash) if df_hash.key?(key)
+ end
+
+ mount_hash.merge(df_hash)
+ end
+
+ # Cache the command output
+ shell_outs = Mash.new
+
+ run_with_check("mount") do
+ shell_outs[:mount] = shell_out("mount").stdout
+ end
+
+ run_with_check("df") do
+ shell_outs[:df_Pk] = shell_out("df -Pk").stdout
+ end
+
+ fs = collect_old_version(shell_outs)
+ by_pair = fs
+ by_device = generate_device_view(fs)
+ by_mountpoint = generate_mountpoint_view(fs)
+
+ fs_data = Mash.new
+ fs_data["by_device"] = by_device
+ fs_data["by_mountpoint"] = by_mountpoint
+ fs_data["by_pair"] = by_pair
+
+ # Set the filesystem data - AIX didn't do the conversion when everyone
+ # else did, so 15 will have both be the new API and 16 will drop the old API
+ filesystem generate_deprecated_view(fs)
+ filesystem2 fs_data
+ end
end
diff --git a/lib/ohai/plugins/solaris2/filesystem.rb b/lib/ohai/plugins/solaris2/filesystem.rb
deleted file mode 100644
index d5e89a68..00000000
--- a/lib/ohai/plugins/solaris2/filesystem.rb
+++ /dev/null
@@ -1,106 +0,0 @@
-#
-# Author:: Kurt Yoder (ktyopscode@yoderhome.com)
-# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-Ohai.plugin(:Filesystem) do
- provides "filesystem"
-
- collect_data(:solaris2) do
- fs = Mash.new
-
- # Grab filesystem data from df
- so = shell_out("df -Pka")
- so.stdout.lines do |line|
- case line
- when /^Filesystem\s+kbytes/
- next
- when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
- filesystem = $1
- fs[filesystem] = Mash.new
- fs[filesystem][:kb_size] = $2
- fs[filesystem][:kb_used] = $3
- fs[filesystem][:kb_available] = $4
- fs[filesystem][:percent_used] = $5
- fs[filesystem][:mount] = $6
- end
- end
-
- # Grab file system type from df (must be done separately)
- so = shell_out("df -na")
- so.stdout.lines do |line|
- next unless line =~ /^(.+?)\s*: (\S+)\s*$/
- mount = $1
- fs.each do |filesystem, fs_attributes|
- next unless fs_attributes[:mount] == mount
- fs[filesystem][:fs_type] = $2
- end
- end
-
- # Grab mount information from /bin/mount
- so = shell_out("mount")
- so.stdout.lines do |line|
- next unless line =~ /^(.+?) on (.+?) (.+?) on (.+?)$/
- filesystem = $2
- fs[filesystem] = Mash.new unless fs.key?(filesystem)
- fs[filesystem][:mount] = $1
- fs[filesystem][:mount_time] = $4 # $4 must come before "split", else it becomes nil
- fs[filesystem][:mount_options] = $3.split("/")
- end
-
- # Grab any zfs data from "zfs get"
- zfs = Mash.new
- # ohai.plugin[:filesystem][:zfs_properties] = 'used'
- # ohai.plugin[:filesystem][:zfs_properties] = ['mountpoint', 'creation', 'available', 'used']
- zfs_get = "zfs get -p -H "
- if configuration(:zfs_properties).nil? || configuration(:zfs_properties).empty?
- zfs_get << "all"
- else
- zfs_get << [configuration(:zfs_properties)].join(",")
- end
- so = shell_out(zfs_get)
- so.stdout.lines do |line|
- next unless line =~ /^([^\t]+)\t([^\t]+)\t([^\t]+)\t([^\t]+)$/
- filesystem = $1
- zfs[filesystem] = Mash.new unless zfs.key?(filesystem)
- zfs[filesystem][:values] = Mash.new unless zfs[filesystem].key?("values")
- zfs[filesystem][:sources] = Mash.new unless zfs[filesystem].key?("sources")
- zfs[filesystem][:values][$2] = $3
- zfs[filesystem][:sources][$2] = $4.chomp
- end
-
- zfs.each do |filesystem, attributes|
- fs[filesystem] = Mash.new unless fs.key?(filesystem)
- fs[filesystem][:fs_type] = "zfs"
- fs[filesystem][:mount] = attributes[:values][:mountpoint] if attributes[:values].key?("mountpoint")
- fs[filesystem][:zfs_values] = attributes[:values]
- fs[filesystem][:zfs_sources] = attributes[:sources]
- # find all zfs parents
- parents = filesystem.split("/")
- zfs_parents = []
- (0..parents.length - 1).to_a.each do |parent_indexes|
- next_parent = parents[0..parent_indexes].join("/")
- zfs_parents.push(next_parent)
- end
- zfs_parents.pop
- fs[filesystem][:zfs_parents] = zfs_parents
- fs[filesystem][:zfs_zpool] = (zfs_parents.length == 0)
- end
-
- # Set the filesystem data
- filesystem fs
- end
-end
diff --git a/spec/unit/plugins/aix/filesystem_spec.rb b/spec/unit/plugins/aix/filesystem_spec.rb
index e729e01d..6502d618 100644
--- a/spec/unit/plugins/aix/filesystem_spec.rb
+++ b/spec/unit/plugins/aix/filesystem_spec.rb
@@ -85,7 +85,7 @@ MOUNT
192.168.1.11 /stage/middleware3 /stage/middleware4 nfs3 Jul 17 13:24 ro,bg,hard,intr,sec=sys
MOUNT
- @plugin = get_plugin("aix/filesystem")
+ @plugin = get_plugin("filesystem")
allow(@plugin).to receive(:collect_os).and_return(:aix)
@plugin[:filesystem] = Mash.new
end
@@ -101,22 +101,27 @@ MOUNT
it "returns the filesystem block size" do
expect(@plugin[:filesystem]["/dev/hd4"]["kb_size"]).to eq("2097152")
+ expect(@plugin[:filesystem2]["by_pair"]["/dev/hd4,/"]["kb_size"]).to eq("2097152")
end
it "returns the filesystem used space in kb" do
expect(@plugin[:filesystem]["/dev/hd4"]["kb_used"]).to eq("219796")
+ expect(@plugin[:filesystem2]["by_pair"]["/dev/hd4,/"]["kb_used"]).to eq("219796")
end
it "returns the filesystem available space in kb" do
expect(@plugin[:filesystem]["/dev/hd4"]["kb_available"]).to eq("1877356")
+ expect(@plugin[:filesystem2]["by_pair"]["/dev/hd4,/"]["kb_available"]).to eq("1877356")
end
it "returns the filesystem capacity in percentage" do
expect(@plugin[:filesystem]["/dev/hd4"]["percent_used"]).to eq("11%")
+ expect(@plugin[:filesystem2]["by_pair"]["/dev/hd4,/"]["percent_used"]).to eq("11%")
end
it "returns the filesystem mounted location" do
expect(@plugin[:filesystem]["/dev/hd4"]["mount"]).to eq("/")
+ expect(@plugin[:filesystem2]["by_pair"]["/dev/hd4,/"]["mount"]).to eq("/")
end
end
@@ -124,14 +129,17 @@ MOUNT
it "returns the filesystem mount location" do
expect(@plugin[:filesystem]["/dev/hd4"]["mount"]).to eq("/")
+ expect(@plugin[:filesystem2]["by_pair"]["/dev/hd4,/"]["mount"]).to eq("/")
end
it "returns the filesystem type" do
expect(@plugin[:filesystem]["/dev/hd4"]["fs_type"]).to eq("jfs2")
+ expect(@plugin[:filesystem2]["by_pair"]["/dev/hd4,/"]["fs_type"]).to eq("jfs2")
end
it "returns the filesystem mount options" do
expect(@plugin[:filesystem]["/dev/hd4"]["mount_options"]).to eq(["rw", "log=/dev/hd8"])
+ expect(@plugin[:filesystem2]["by_pair"]["/dev/hd4,/"]["mount_options"]).to eq(["rw", "log=/dev/hd8"])
end
# For entries like 192.168.1.11 /stage/middleware1 /stage/middleware2 nfs3 Jul 17 13:24 ro,bg,hard,intr,sec=sys
@@ -139,14 +147,17 @@ MOUNT
it "returns the filesystem mount location" do
expect(@plugin[:filesystem]["192.168.1.11:/stage/middleware1"]["mount"]).to eq("/stage/middleware2")
+ expect(@plugin[:filesystem2]["by_pair"]["192.168.1.11:/stage/middleware1,/stage/middleware2"]["mount"]).to eq("/stage/middleware2")
end
it "returns the filesystem type" do
expect(@plugin[:filesystem]["192.168.1.11:/stage/middleware1"]["fs_type"]).to eq("nfs3")
+ expect(@plugin[:filesystem2]["by_pair"]["192.168.1.11:/stage/middleware1,/stage/middleware2"]["fs_type"]).to eq("nfs3")
end
it "returns the filesystem mount options" do
expect(@plugin[:filesystem]["192.168.1.11:/stage/middleware1"]["mount_options"]).to eq(["ro", "bg", "hard", "intr", "sec=sys"])
+ expect(@plugin[:filesystem2]["by_pair"]["192.168.1.11:/stage/middleware1,/stage/middleware2"]["mount_options"]).to eq(["ro", "bg", "hard", "intr", "sec=sys"])
end
end
end
@@ -163,22 +174,27 @@ MOUNT
it "returns the filesystem block size" do
expect(@plugin[:filesystem]["Global:/"]["kb_size"]).to eq("10485760")
+ expect(@plugin[:filesystem2]["by_pair"]["Global:/,/"]["kb_size"]).to eq("10485760")
end
it "returns the filesystem used space in kb" do
expect(@plugin[:filesystem]["Global:/"]["kb_used"]).to eq("130872")
+ expect(@plugin[:filesystem2]["by_pair"]["Global:/,/"]["kb_used"]).to eq("130872")
end
it "returns the filesystem available space in kb" do
expect(@plugin[:filesystem]["Global:/"]["kb_available"]).to eq("10354888")
+ expect(@plugin[:filesystem2]["by_pair"]["Global:/,/"]["kb_available"]).to eq("10354888")
end
it "returns the filesystem capacity in percentage" do
expect(@plugin[:filesystem]["Global:/"]["percent_used"]).to eq("2%")
+ expect(@plugin[:filesystem2]["by_pair"]["Global:/,/"]["percent_used"]).to eq("2%")
end
it "returns the filesystem mounted location" do
expect(@plugin[:filesystem]["Global:/"]["mount"]).to eq("/")
+ expect(@plugin[:filesystem2]["by_pair"]["Global:/,/"]["mount"]).to eq("/")
end
end
@@ -186,14 +202,17 @@ MOUNT
it "returns the filesystem mount location" do
expect(@plugin[:filesystem]["Global:/"]["mount"]).to eq("/")
+ expect(@plugin[:filesystem2]["by_pair"]["Global:/,/"]["mount"]).to eq("/")
end
it "returns the filesystem type" do
expect(@plugin[:filesystem]["Global:/"]["fs_type"]).to eq("jfs2")
+ expect(@plugin[:filesystem2]["by_pair"]["Global:/,/"]["fs_type"]).to eq("jfs2")
end
it "returns the filesystem mount options" do
expect(@plugin[:filesystem]["Global:/"]["mount_options"]).to eq(["rw", "log=NULL"])
+ expect(@plugin[:filesystem2]["by_pair"]["Global:/,/"]["mount_options"]).to eq(["rw", "log=NULL"])
end
# For entries like 192.168.1.11 /stage/middleware3 /stage/middleware4 nfs3 Jul 17 13:24 ro,bg,hard,intr,sec=sys
@@ -201,14 +220,17 @@ MOUNT
it "returns the filesystem mount location" do
expect(@plugin[:filesystem]["192.168.1.11:/stage/middleware3"]["mount"]).to eq("/stage/middleware4")
+ expect(@plugin[:filesystem2]["by_pair"]["192.168.1.11:/stage/middleware3,/stage/middleware4"]["mount"]).to eq("/stage/middleware4")
end
it "returns the filesystem type" do
expect(@plugin[:filesystem]["192.168.1.11:/stage/middleware3"]["fs_type"]).to eq("nfs3")
+ expect(@plugin[:filesystem2]["by_pair"]["192.168.1.11:/stage/middleware3,/stage/middleware4"]["fs_type"]).to eq("nfs3")
end
it "returns the filesystem mount options" do
expect(@plugin[:filesystem]["192.168.1.11:/stage/middleware3"]["mount_options"]).to eq(["ro", "bg", "hard", "intr", "sec=sys"])
+ expect(@plugin[:filesystem2]["by_pair"]["192.168.1.11:/stage/middleware3,/stage/middleware4"]["mount_options"]).to eq(["ro", "bg", "hard", "intr", "sec=sys"])
end
end
end
diff --git a/spec/unit/plugins/solaris2/filesystem.rb b/spec/unit/plugins/solaris2/filesystem.rb
index af228a80..b48dd1db 100644
--- a/spec/unit/plugins/solaris2/filesystem.rb
+++ b/spec/unit/plugins/solaris2/filesystem.rb
@@ -18,7 +18,7 @@
require_relative "../../../spec_helper"
describe Ohai::System, "Solaris2.X filesystem plugin" do
- let(:plugin) { get_plugin("solaris2/filesystem") }
+ let(:plugin) { get_plugin("filesystem") }
before(:each) do
allow(plugin).to receive(:collect_os).and_return("solaris2")
@@ -33,51 +33,374 @@ describe Ohai::System, "Solaris2.X filesystem plugin" do
allow(plugin).to receive(:shell_out).with("df -Pka").and_return(mock_shell_out(0, "", ""))
allow(plugin).to receive(:shell_out).with("df -na").and_return(mock_shell_out(0, "", ""))
allow(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, "", ""))
+ allow(plugin).to receive(:shell_out).with("zfs get -p -H all").and_return(mock_shell_out(0, "", ""))
+
+ @df_pka = <<~DF_PKA
+ Filesystem 1024-blocks Used Available Capacity Mounted on
+ rpool/ROOT/solaris-0 730451045 2172071 727373448 1% /
+ rpool/ROOT/solaris-0/var 730451045 850302 727373448 1% /var
+ /dev 0 0 0 0% /dev
+ proc 0 0 0 0% /proc
+ ctfs 0 0 0 0% /system/contract
+ mnttab 0 0 0 0% /etc/mnttab
+ objfs 0 0 0 0% /system/object
+ swap 18544280 568 18543712 1% /system/volatile
+ sharefs 0 0 0 0% /etc/dfs/sharetab
+ fd 0 0 0 0% /dev/fd
+ swap 18666120 122408 18543712 1% /tmp
+ rpool/VARSHARE 730451045 1181 727373448 1% /var/share
+ rpool/export 730451045 32 727373448 1% /export
+ rpool/export/home 730451045 182277 727373448 1% /export/home
+ rpool 730451045 31 727373448 1% /rpool
+ rpool/VARSHARE/pkg 730451045 32 727373448 1% /var/share/pkg
+ rpool/VARSHARE/pkg/repositories 730451045 31 727373448 1% /var/share/pkg/repositories
+ rpool/export/home/shian 730451045 37 727373448 1% /export/home/shain
+ rpool/export/home/phild 730451045 38 727373448 1% /export/home/phild
+ r
+ -hosts 0 0 0 0% /net
+ auto_home 0 0 0 0% /home
+ -fedfs 0 0 0 0% /nfs4
+DF_PKA
+
+ @mount = <<~MOUNT
+ / on rpool/ROOT/solaris-0 read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/mountpoint=/zones/servername.chef.internal.dns/root//zone=servername.chef.internal.dns/nozonemod/sharezone=151/dev=4bd0b7e on Fri Feb 2 16:27:36 2018
+ /var on rpool/ROOT/solaris-0/var read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/mountpoint=/zones/servername.chef.internal.dns/root/var/zone=servername.chef.internal.dns/nozonemod/sharezone=151/dev=4bd0b7f on Fri Feb 2 16:27:36 2018
+ /dev on /dev read/write/setuid/devices/rstchown/zone=servername.chef.internal.dns/nozonemod/sharezone=151/dev=8f8003a on Fri Feb 2 16:27:36 2018
+ /proc on proc read/write/setuid/nodevices/rstchown/zone=servername.chef.internal.dns/sharezone=151/dev=8f40096 on Fri Feb 2 16:27:37 2018
+ /system/contract on ctfs read/write/setuid/nodevices/rstchown/zone=servername.chef.internal.dns/sharezone=151/dev=8fc0097 on Fri Feb 2 16:27:37 2018
+ /etc/mnttab on mnttab read/write/setuid/nodevices/rstchown/zone=servername.chef.internal.dns/sharezone=151/dev=9000097 on Fri Feb 2 16:27:37 2018
+ /system/object on objfs read/write/setuid/nodevices/rstchown/zone=servername.chef.internal.dns/sharezone=151/dev=9080097 on Fri Feb 2 16:27:37 2018
+ /system/volatile on swap read/write/setuid/nodevices/rstchown/xattr/zone=servername.chef.internal.dns/sharezone=151/dev=90406f0 on Fri Feb 2 16:27:37 2018
+ /etc/dfs/sharetab on sharefs read/write/setuid/nodevices/rstchown/zone=servername.chef.internal.dns/sharezone=151/dev=90c004d on Fri Feb 2 16:27:37 2018
+ /dev/fd on fd read/write/setuid/nodevices/rstchown/zone=servername.chef.internal.dns/sharezone=151/dev=91c007d on Fri Feb 2 16:27:44 2018
+ /tmp on swap read/write/setuid/nodevices/rstchown/xattr/zone=servername.chef.internal.dns/sharezone=151/dev=90406f1 on Fri Feb 2 16:27:45 2018
+ /var/share on rpool/VARSHARE read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/zone=servername.chef.internal.dns/sharezone=151/dev=4bd0b80 on Fri Feb 2 16:27:45 2018
+ /export on rpool/export read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/zone=servername.chef.internal.dns/sharezone=151/dev=4bd0b81 on Fri Feb 2 16:28:11 2018
+ /export/home on rpool/export/home read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/zone=servername.chef.internal.dns/sharezone=151/dev=4bd0b82 on Fri Feb 2 16:28:11 2018
+ /rpool on rpool read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/zone=servername.chef.internal.dns/sharezone=151/dev=4bd0b83 on Fri Feb 2 16:28:11 2018
+ /var/share/pkg on rpool/VARSHARE/pkg read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/zone=servername.chef.internal.dns/sharezone=151/dev=4bd0b84 on Fri Feb 2 16:28:12 2018
+ /var/share/pkg/repositories on rpool/VARSHARE/pkg/repositories read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/zone=servername.chef.internal.dns/sharezone=151/dev=4bd0b85 on Fri Feb 2 16:28:12 2018
+ /export/home/<usernameredacted> on rpool/export/home/<usernameredacted> read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/zone=servername.chef.internal.dns/sharezone=151/dev=4bd0b8a on Fri Feb 2 16:39:15 2018
+ /export/home/<usernameredacted> on rpool/export/home/<usernameredacted> read/write/setuid/nodevices/rstchown/nonbmand/exec/xattr/atime/zone=servername.chef.internal.dns/sharezone=151/dev=4bd0b8b on Fri Feb 2 16:39:16 2018
+MOUNT
+
+ @zfs_get = <<~ZFS_GET
+ data0 type filesystem -
+ data0 creation 1331514391 -
+ data0 used 7926803118480 -
+ data0 available 3666345412208 -
+ data0 referenced 60350619952 -
+ data0 compressratio 1.04x -
+ data0 mounted yes -
+ data0 quota 0 default
+ data0 reservation 0 default
+ data0 recordsize 131072 default
+ data0 mountpoint /data0 default
+ data0 sharenfs rw=192.168.130.0/24,rw=[2001:470:1f05:2c9::]/64,rw=[2001:470:8122:dd40::10] local
+ data0 checksum on default
+ data0 compression off local
+ data0 atime off local
+ data0 devices on default
+ data0 exec on default
+ data0 setuid on default
+ data0 readonly off default
+ data0 zoned off default
+ data0 snapdir hidden default
+ data0 aclinherit restricted default
+ data0 canmount on default
+ data0 xattr on default
+ data0 copies 1 default
+ data0 version 5 -
+ data0 utf8only off -
+ data0 normalization none -
+ data0 casesensitivity sensitive -
+ data0 vscan off default
+ data0 nbmand off default
+ data0 sharesmb off default
+ data0 refquota 0 default
+ data0 refreservation 0 default
+ data0 primarycache all default
+ data0 secondarycache all default
+ data0 usedbysnapshots 157243047152 -
+ data0 usedbydataset 60350619952 -
+ data0 usedbychildren 7709209451376 -
+ data0 usedbyrefreservation 0 -
+ data0 logbias latency default
+ data0 dedup off default
+ data0 mlslabel none default
+ data0 sync standard default
+ data0 refcompressratio 1.29x -
+ data0 written 4183965296 -
+ data0 logicalused 8240006744576 -
+ data0 logicalreferenced 75625359872 -
+ data0 filesystem_limit 18446744073709551615 default
+ data0 snapshot_limit 18446744073709551615 default
+ data0 filesystem_count 18446744073709551615 default
+ data0 snapshot_count 18446744073709551615 default
+ data0 snapdev hidden default
+ data0 acltype off default
+ data0 context none default
+ data0 fscontext none default
+ data0 defcontext none default
+ data0 rootcontext none default
+ data0 relatime off default
+ data0 redundant_metadata all default
+ data0 overlay off default
+ data0@20130228 type snapshot -
+ data0@20130228 creation 1362119670 -
+ data0@20130228 used 0 -
+ data0@20130228 referenced 57161787648 -
+ data0@20130228 compressratio 1.30x -
+ data0@20130228 devices on default
+ data0@20130228 exec on default
+ data0@20130228 setuid on default
+ data0@20130228 xattr on default
+ data0@20130228 version 5 -
+ data0@20130228 utf8only off -
+ data0@20130228 normalization none -
+ data0@20130228 casesensitivity sensitive -
+ data0@20130228 nbmand off default
+ data0@20130228 primarycache all default
+ data0@20130228 secondarycache all default
+ data0@20130228 defer_destroy off -
+ data0@20130228 userrefs 0 -
+ data0@20130228 mlslabel none default
+ data0@20130228 refcompressratio 1.30x -
+ data0@20130228 written 57161787648 -
+ data0@20130228 clones -
+ data0@20130228 logicalused 0 -
+ data0@20130228 logicalreferenced 72138856960 -
+ data0@20130228 acltype off default
+ data0@20130228 context none default
+ data0@20130228 fscontext none default
+ data0@20130228 defcontext none default
+ data0@20130228 rootcontext none default
+ data0@20130301 type snapshot -
+ data0@20130301 creation 1362122621 -
+ data0@20130301 used 0 -
+ data0@20130301 referenced 57161787648 -
+ data0@20130301 compressratio 1.30x -
+ data0@20130301 devices on default
+ data0@20130301 exec on default
+ data0@20130301 setuid on default
+ data0@20130301 xattr on default
+ data0@20130301 version 5 -
+ data0@20130301 utf8only off -
+ data0@20130301 normalization none -
+ data0@20130301 casesensitivity sensitive -
+ data0@20130301 nbmand off default
+ data0@20130301 primarycache all default
+ data0@20130301 secondarycache all default
+ data0@20130301 defer_destroy off -
+ data0@20130301 userrefs 0 -
+ data0@20130301 mlslabel none default
+ data0@20130301 refcompressratio 1.30x -
+ data0@20130301 written 0 -
+ data0@20130301 clones -
+ data0@20130301 logicalused 0 -
+ data0@20130301 logicalreferenced 72138856960 -
+ data0@20130301 acltype off default
+ data0@20130301 context none default
+ data0@20130301 fscontext none default
+ data0@20130301 defcontext none default
+ data0@20130301 rootcontext none default
+ data0@20130310 type snapshot -
+ data0@20130310 creation 1362955150 -
+ data0@20130310 used 281392 -
+ data0@20130310 referenced 57173475232 -
+ data0@20130310 compressratio 1.30x -
+ data0@20130310 devices on default
+ data0@20130310 exec on default
+ data0@20130310 setuid on default
+ data0@20130310 xattr on default
+ data0@20130310 version 5 -
+ data0@20130310 utf8only off -
+ data0@20130310 normalization none -
+ data0@20130310 casesensitivity sensitive -
+ data0@20130310 nbmand off default
+ data0@20130310 primarycache all default
+ data0@20130310 secondarycache all default
+ data0@20130310 defer_destroy off -
+ data0@20130310 userrefs 0 -
+ data0@20130310 mlslabel none default
+ data0@20130310 refcompressratio 1.30x -
+ data0@20130310 written 11968976 -
+ data0@20130310 clones -
+ data0@20130310 logicalused 0 -
+ data0@20130310 logicalreferenced 72164488192 -
+ data0@20130310 acltype off default
+ data0@20130310 context none default
+ data0@20130310 fscontext none default
+ data0@20130310 defcontext none default
+ data0@20130310 rootcontext none default
+ data0@20160311 type snapshot -
+ data0@20160311 creation 1457762233 -
+ data0@20160311 used 155723556528 -
+ data0@20160311 referenced 211890289712 -
+ data0@20160311 compressratio 1.24x -
+ data0@20160311 devices on default
+ data0@20160311 exec on default
+ data0@20160311 setuid on default
+ data0@20160311 xattr on default
+ data0@20160311 version 5 -
+ data0@20160311 utf8only off -
+ data0@20160311 normalization none -
+ data0@20160311 casesensitivity sensitive -
+ data0@20160311 nbmand off default
+ data0@20160311 primarycache all default
+ data0@20160311 secondarycache all default
+ data0@20160311 defer_destroy off -
+ data0@20160311 userrefs 0 -
+ data0@20160311 mlslabel none default
+ data0@20160311 refcompressratio 1.24x -
+ data0@20160311 written 156235945184 -
+ data0@20160311 clones -
+ data0@20160311 logicalused 0 -
+ data0@20160311 logicalreferenced 259598664192 -
+ data0@20160311 acltype off default
+ data0@20160311 context none default
+ data0@20160311 fscontext none default
+ data0@20160311 defcontext none default
+ data0@20160311 rootcontext none default
+ data0/Movies type filesystem -
+ data0/Movies creation 1331530217 -
+ data0/Movies used 642640700304 -
+ data0/Movies available 3666345412208 -
+ data0/Movies referenced 586525311344 -
+ data0/Movies compressratio 1.00x -
+ data0/Movies mounted yes -
+ data0/Movies quota 0 default
+ data0/Movies reservation 0 default
+ data0/Movies recordsize 131072 default
+ data0/Movies mountpoint /data0/Movies default
+ data0/Movies sharenfs sec=sys,rw=192.168.130.0/24,rw=192.168.135.0/24,rw=[2001:470:1f05:2c9::]/64,rw=[2001:470:8122::]/48,rw=[2001:470:8122:dd40::10]local
+ data0/Movies checksum on default
+ data0/Movies compression off inherited from data0
+ data0/Movies atime off local
+ data0/Movies devices on default
+ data0/Movies exec on default
+ data0/Movies setuid on default
+ data0/Movies readonly off default
+ data0/Movies zoned off default
+ data0/Movies snapdir hidden default
+ data0/Movies aclinherit restricted default
+ data0/Movies canmount on default
+ data0/Movies xattr on default
+ data0/Movies copies 1 default
+ data0/Movies version 5 -
+ data0/Movies utf8only off -
+ data0/Movies normalization none -
+ data0/Movies casesensitivity sensitive -
+ data0/Movies vscan off default
+ data0/Movies nbmand off default
+ data0/Movies sharesmb off local
+ data0/Movies refquota 0 default
+ data0/Movies refreservation 0 default
+ data0/Movies primarycache all default
+ data0/Movies secondarycache all default
+ data0/Movies usedbysnapshots 56115388960 -
+ data0/Movies usedbydataset 586525311344 -
+ data0/Movies usedbychildren 0 -
+ data0/Movies usedbyrefreservation 0 -
+ data0/Movies logbias latency default
+ data0/Movies dedup off default
+ data0/Movies mlslabel none default
+ data0/Movies sync standard default
+ data0/Movies refcompressratio 1.00x -
+ data0/Movies written 197038505024 -
+ data0/Movies logicalused 642795343360 -
+ data0/Movies logicalreferenced 586666194432 -
+ data0/Movies filesystem_limit 18446744073709551615 default
+ data0/Movies snapshot_limit 18446744073709551615 default
+ data0/Movies filesystem_count 18446744073709551615 default
+ data0/Movies snapshot_count 18446744073709551615 default
+ data0/Movies snapdev hidden default
+ data0/Movies acltype off default
+ data0/Movies context none default
+ data0/Movies fscontext none default
+ data0/Movies defcontext none default
+ data0/Movies rootcontext none default
+ data0/Movies relatime off default
+ data0/Movies redundant_metadata all default
+ data0/Movies overlay off default:
+ZFS_GET
end
after(:each) do
Ohai.config[:plugin] = @original_plugin_config
end
- context "when 'zfs get' properties are not configured" do
- it "collects all filesystem properties" do
- expect(plugin).to receive(:shell_out)
- .with("zfs get -p -H all")
- .and_return(mock_shell_out(0, "", ""))
+ context "reports filesystem data" do
+ before do
+ allow(plugin).to receive(:shell_out)
+ .with("mount")
+ .and_return(mock_shell_out(0, @mount, nil))
+ allow(plugin).to receive(:shell_out)
+ .with("df -Pka")
+ .and_return(mock_shell_out(0, @df_pka, nil))
+ # TODO: get this output
+ # allow(plugin).to receive(:shell_out)
+ # .with("df -na")
+ # .and_return(mock_shell_out(0, @df_na, nil))
plugin.run
end
+
+ it "returns kb_used" do
+ expect(plugin[:filesystem]["rpool/VARSHARE"]["kb_used"]).to eq("1181")
+ expect(plugin[:filesystem2]["by_pair"]["rpool/VARSHARE,/var/share"]["kb_used"]).to eq("1181")
+ end
+
+ it "returns mount" do
+ expect(plugin[:filesystem]["rpool/VARSHARE"]["mount"]).to eq("/var/share")
+ expect(plugin[:filesystem2]["by_pair"]["rpool/VARSHARE,/var/share"]["mount"]).to eq("/var/share")
+ end
+
+ it "returns mount_opts" do
+ opts = %w{
+ read
+ write
+ setuid
+ nodevices
+ rstchown
+ nonbmand
+ exec
+ xattr
+ atime
+ zone=servername.chef.internal.dns
+ sharezone=151
+ dev=4bd0b80
+ }
+ expect(plugin[:filesystem]["rpool/VARSHARE"]["mount_options"]).to eq(opts)
+ expect(plugin[:filesystem2]["by_pair"]["rpool/VARSHARE,/var/share"]["mount_options"]).to eq(opts)
+ end
end
- context "when 'zfs get' properties are configured" do
- shared_examples_for "configured zfs properties" do
- let(:plugin_config) do
- {
- filesystem: {
- zfs_properties: zfs_properties,
- },
- }
- end
-
- it "collects configured filesystem properties" do
- expect(plugin).to receive(:shell_out)
- .with("zfs get -p -H #{expected_cmd}")
- .and_return(mock_shell_out(0, "", ""))
- plugin.run
- end
+ context "handles zfs properties" do
+ before do
+ allow(plugin).to receive(:shell_out)
+ .with("zfs get -p -H all")
+ .and_return(mock_shell_out(0, @zfs_get, nil))
+ plugin.run
end
- context "as a String" do
- include_examples "configured zfs properties" do
- let(:zfs_properties) { "mountpoint,creation,available,used" }
- let(:expected_cmd) { "mountpoint,creation,available,used" }
- end
+ it "returns top-level stats" do
+ # old API
+ expect(plugin[:filesystem]["data0"]["fs_type"]).to eq("zfs")
+ expect(plugin[:filesystem]["data0"]["mount"]).to eq("/data0")
+
+ # new API
+ expect(plugin[:filesystem2]["by_pair"]["data0,/data0"]["fs_type"]).to eq("zfs")
+ expect(plugin[:filesystem2]["by_pair"]["data0,/data0"]["mount"]).to eq("/data0")
end
- context "as an Array" do
- include_examples "configured zfs properties" do
- let(:zfs_properties) { %w{mountpoint creation available used} }
- let(:expected_cmd) { "mountpoint,creation,available,used" }
- end
+ it "returns zfs-specific properties" do
+ # old API
+ expect(plugin[:filesystem]["data0"]["zfs_values"]["used"]).to eq("7926803118480")
+ expect(plugin[:filesystem]["data0"]["zfs_sources"]["used"]).to eq("-")
+
+ # new API
+ expect(plugin[:filesystem2]["by_pair"]["data0,/data0"]["zfs_properties"]["used"]["value"]).to eq("7926803118480")
+ expect(plugin[:filesystem2]["by_pair"]["data0,/data0"]["zfs_properties"]["used"]["source"]).to eq("-")
end
end
end