summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire McQuin <claire@getchef.com>2015-10-05 12:31:25 -0700
committerClaire McQuin <claire@getchef.com>2015-10-05 12:45:44 -0700
commit8f65feb6e69631db95875204510398b4680e557d (patch)
tree38deefa56e411976d7f3a436652cdc7b80f53304
parent7cac8904c8a45a39a7f740c03696fc11b8ea8fd1 (diff)
downloadohai-8f65feb6e69631db95875204510398b4680e557d.tar.gz
Configurable filesystem properties collected for Solaris2.x
-rw-r--r--lib/ohai/plugins/solaris2/filesystem.rb10
-rw-r--r--spec/unit/plugins/solaris2/filesystem.rb68
2 files changed, 77 insertions, 1 deletions
diff --git a/lib/ohai/plugins/solaris2/filesystem.rb b/lib/ohai/plugins/solaris2/filesystem.rb
index c640898f..20ffc303 100644
--- a/lib/ohai/plugins/solaris2/filesystem.rb
+++ b/lib/ohai/plugins/solaris2/filesystem.rb
@@ -63,7 +63,15 @@ Ohai.plugin(:Filesystem) do
# Grab any zfs data from "zfs get"
zfs = Mash.new
- so = shell_out("zfs get -p -H all")
+ # 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
diff --git a/spec/unit/plugins/solaris2/filesystem.rb b/spec/unit/plugins/solaris2/filesystem.rb
new file mode 100644
index 00000000..9455d6bf
--- /dev/null
+++ b/spec/unit/plugins/solaris2/filesystem.rb
@@ -0,0 +1,68 @@
+#
+# Copyright:: Copyright (c) 2015 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.
+#
+
+require_relative '../../../spec_helper'
+
+describe Ohai::System, "Solaris2.X filesystem plugin" do
+ let(:plugin) { get_plugin("solaris2/filesystem") }
+
+ before(:each) do
+ allow(plugin).to receive(:collect_os).and_return("solaris2")
+ end
+
+ describe "filesystem properties" do
+ let(:plugin_config) { {} }
+
+ before(:each) do
+ @original_plugin_config = Ohai.config[:plugin]
+ Ohai.config[:plugin] = plugin_config
+ 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, "", ""))
+ 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, "", ""))
+ plugin.run
+ end
+ end
+
+ context "when 'zfs get' properties are configured" do
+ let(:plugin_config) do
+ {
+ :filesystem => {
+ :zfs_properties => ['mountpoint', 'creation', 'available', 'used']
+ }
+ }
+ end
+
+ it "collects configured filesystem properties" do
+ expect(plugin).to receive(:shell_out).
+ with("zfs get -p -H mountpoint,creation,available,used").
+ and_return(mock_shell_out(0, "", ""))
+ plugin.run
+ end
+ end
+ end
+end