Skip to content

Commit

Permalink
Configurable filesystem properties collected for Solaris2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Claire McQuin committed Oct 5, 2015
1 parent 7cac890 commit 8f65feb
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/ohai/plugins/solaris2/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@

# 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
Expand Down
68 changes: 68 additions & 0 deletions spec/unit/plugins/solaris2/filesystem.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8f65feb

Please sign in to comment.