summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2016-05-31 18:41:18 +0100
committerThom May <thom@may.lt>2016-05-31 18:41:18 +0100
commit34cad7a9b3fbc9552b1ee930fc9337d06603374e (patch)
treebec6ddf0ed9e81e3ff056280429495c4049753ef
parentdae2bd55cc1540e770e858e1f6e9637c3cb3ec6e (diff)
parent8a4e1248610bbc52f8a1d33553e6878e6721cb04 (diff)
downloadohai-34cad7a9b3fbc9552b1ee930fc9337d06603374e.tar.gz
Merge pull request #814 from vr/freebsd_packages
Add freebsd support in packages plugin
-rw-r--r--lib/ohai/plugins/packages.rb11
-rw-r--r--spec/data/plugins/pkg-query.output58
-rw-r--r--spec/unit/plugins/packages_spec.rb25
3 files changed, 94 insertions, 0 deletions
diff --git a/lib/ohai/plugins/packages.rb b/lib/ohai/plugins/packages.rb
index 44874944..bae69402 100644
--- a/lib/ohai/plugins/packages.rb
+++ b/lib/ohai/plugins/packages.rb
@@ -97,6 +97,17 @@ Ohai.plugin(:Packages) do
end
end
+ collect_data(:freebsd) do
+ packages Mash.new
+ so = shell_out('pkg query -a "%n %v"')
+ # Output format is
+ # name version
+ so.stdout.lines do |pkg|
+ name, version = pkg.split(" ")
+ packages[name] = { "version" => version }
+ end
+ end
+
def collect_ips_packages
so = shell_out("pkg list -H")
# Output format is
diff --git a/spec/data/plugins/pkg-query.output b/spec/data/plugins/pkg-query.output
new file mode 100644
index 00000000..6c37824a
--- /dev/null
+++ b/spec/data/plugins/pkg-query.output
@@ -0,0 +1,58 @@
+rubygem-chef 12.6.0_1
+rubygem-chef-config 12.6.0_1
+rubygem-chef-zero 4.4.2_1
+rubygem-coderay 1.1.1
+rubygem-diff-lcs 1.2.5_1
+rubygem-domain_name 0.5.24
+rubygem-erubis 2.7.0_1
+rubygem-ffi 1.9.10
+rubygem-ffi-yajl 2.2.3
+rubygem-hashie 3.4.3
+rubygem-hashie2 2.1.2
+rubygem-highline 1.7.8
+rubygem-http-cookie 1.0.2
+rubygem-ipaddress 0.8.3
+rubygem-json 1.8.3
+rubygem-json_pure 1.8.3
+rubygem-libyajl2 1.2.0
+rubygem-method_source 0.8.2
+rubygem-mime-types 2.99
+rubygem-mime-types1 1.25.1
+rubygem-mixlib-authentication 1.3.0
+rubygem-mixlib-cli 1.4.0
+rubygem-mixlib-config 2.1.0
+rubygem-mixlib-log 1.6.0
+rubygem-mixlib-shellout 2.2.5_1
+rubygem-multi_json 1.11.2
+rubygem-net-scp 1.2.1
+rubygem-net-ssh 3.0.2,2
+rubygem-net-ssh-gateway 1.2.0
+rubygem-net-ssh-multi 1.2.1
+rubygem-net-ssh2 2.9.2,1
+rubygem-net-telnet 0.1.1
+rubygem-netrc 0.7.7
+rubygem-ohai 8.8.1
+rubygem-plist 3.1.0
+rubygem-proxifier 1.0.3
+rubygem-pry 0.10.3_2
+rubygem-rack 1.4.7,3
+rubygem-rake 10.5.0
+rubygem-rest-client 1.8.0
+rubygem-rspec 3.4.0
+rubygem-rspec-core 3.4.4
+rubygem-rspec-expectations 3.4.0
+rubygem-rspec-its 1.2.0_1
+rubygem-rspec-mocks 3.4.1
+rubygem-rspec-support 3.4.1
+rubygem-rspec_junit_formatter 0.2.3_1
+rubygem-ruby-termios 0.9.6
+rubygem-serverspec 2.29.1_1
+rubygem-sfl 2.2_1
+rubygem-slop3 3.6.0
+rubygem-specinfra 2.50.2_1
+rubygem-syslog-logger 1.6.8
+rubygem-systemu 2.6.4
+rubygem-unf 0.1.4
+rubygem-unf_ext 0.0.7.1
+rubygem-uuidtools 2.1.5
+rubygem-wmi-lite 1.0.0
diff --git a/spec/unit/plugins/packages_spec.rb b/spec/unit/plugins/packages_spec.rb
index 62f3117e..85fcc4cc 100644
--- a/spec/unit/plugins/packages_spec.rb
+++ b/spec/unit/plugins/packages_spec.rb
@@ -193,6 +193,31 @@ describe Ohai::System, "plugin packages" do
end
end
+ context "on freebsd" do
+ let(:plugin) { get_plugin("packages") }
+
+ let(:stdout) do
+ File.read(File.join(SPEC_PLUGIN_PATH, "pkg-query.output"))
+ end
+
+ before(:each) do
+ allow(plugin).to receive(:collect_os).and_return(:freebsd)
+ allow(plugin).to receive(:shell_out).with('pkg query -a "%n %v"').and_return(mock_shell_out(0, stdout, ""))
+ plugin.run
+ end
+
+ it 'calls pkg query -a "%n %v"' do
+ expect(plugin).to receive(:shell_out)
+ .with('pkg query -a "%n %v"')
+ .and_return(mock_shell_out(0, stdout, ""))
+ plugin.run
+ end
+
+ it "gets packages with version" do
+ expect(plugin[:packages]["rubygem-chef"][:version]).to eq("12.6.0_1")
+ end
+ end
+
context "on solaris2" do
let(:plugin) { get_plugin("packages") }