summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire McQuin <mcquin@users.noreply.github.com>2015-10-09 11:37:07 -0700
committerClaire McQuin <mcquin@users.noreply.github.com>2015-10-09 11:37:07 -0700
commit400d875fe211f5d39b4682e57a568948eec2bd29 (patch)
tree2ef4be013d92a623ea279870fbff1219c149feed
parent32e378236ccf98398d65aa6fe0cc4c88c1c2f979 (diff)
parent64ae29d400d23ab31db66e92318ff8eb01faf38d (diff)
downloadohai-400d875fe211f5d39b4682e57a568948eec2bd29.tar.gz
Merge pull request #630 from chef/mcquin/ohai-629
Configurable filesystem properties collected for Solaris2.x
-rw-r--r--lib/ohai/plugins/solaris2/filesystem.rb10
-rw-r--r--spec/unit/plugins/solaris2/filesystem.rb84
2 files changed, 93 insertions, 1 deletions
diff --git a/lib/ohai/plugins/solaris2/filesystem.rb b/lib/ohai/plugins/solaris2/filesystem.rb
index c640898f..4b8042fc 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..e0ff7b8a
--- /dev/null
+++ b/spec/unit/plugins/solaris2/filesystem.rb
@@ -0,0 +1,84 @@
+#
+# 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
+ 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
+ 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
+ end
+
+ context "as an Array" do
+ include_examples "configured zfs properties" do
+ let(:zfs_properties) { ['mountpoint', 'creation', 'available', 'used'] }
+ let(:expected_cmd) { 'mountpoint,creation,available,used' }
+ end
+ end
+ end
+ end
+end