diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2016-02-02 10:34:51 -0800 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2016-02-02 13:39:24 -0800 |
commit | 9d19d918dd130f3badff67df2a82a04639c44b59 (patch) | |
tree | b4467cfdf7c1b265ad0da20d4606e73cebd3621d | |
parent | 50e002ef9227318b89242803f647b6c51a1e1a74 (diff) | |
download | ohai-9d19d918dd130f3badff67df2a82a04639c44b59.tar.gz |
Don't enable packages plugin by default
This is a hack. We can make this into a proper
DSL thing where specifying something like `default_enabled false`.
For now, this could be enabled through
```ruby
ohai[:plugins][:packages][:enabled] = true
```
-rw-r--r-- | lib/ohai/plugins/packages.rb | 84 | ||||
-rw-r--r-- | spec/unit/plugins/packages_spec.rb | 4 |
2 files changed, 49 insertions, 39 deletions
diff --git a/lib/ohai/plugins/packages.rb b/lib/ohai/plugins/packages.rb index de031b9e..95b6955f 100644 --- a/lib/ohai/plugins/packages.rb +++ b/lib/ohai/plugins/packages.rb @@ -23,58 +23,62 @@ Ohai.plugin(:Packages) do depends 'platform_family' collect_data(:linux) do - packages Mash.new + if configuration(:enabled) + packages Mash.new + if %w(debian).include? platform_family + so = shell_out('dpkg-query -W') + pkgs = so.stdout.lines - if %w(debian).include? platform_family - so = shell_out('dpkg-query -W') - pkgs = so.stdout.lines - - pkgs.each do |pkg| - name, version = pkg.split - packages[name] = { 'version' => version } - end + pkgs.each do |pkg| + name, version = pkg.split + packages[name] = { 'version' => version } + end - elsif %w(rhel fedora suse).include? platform_family - require 'shellwords' - format = Shellwords.escape '%{NAME}\t%{VERSION}\t%{RELEASE}\n' - so = shell_out("rpm -qa --queryformat #{format}") - pkgs = so.stdout.lines + elsif %w(rhel fedora suse).include? platform_family + require 'shellwords' + format = Shellwords.escape '%{NAME}\t%{VERSION}\t%{RELEASE}\n' + so = shell_out("rpm -qa --queryformat #{format}") + pkgs = so.stdout.lines - pkgs.each do |pkg| - name, version, release = pkg.split - packages[name] = { 'version' => version, 'release' => release } + pkgs.each do |pkg| + name, version, release = pkg.split + packages[name] = { 'version' => version, 'release' => release } + end end end end collect_data(:windows) do - packages Mash.new - - require 'wmi-lite' + if configuration(:enabled) + packages Mash.new + require 'wmi-lite' - wmi = WmiLite::Wmi.new - w32_product = wmi.instances_of('Win32_Product') + wmi = WmiLite::Wmi.new + w32_product = wmi.instances_of('Win32_Product') - w32_product.find_all.each do |product| - name = product['name'] - package = packages[name] = Mash.new - %w(version vendor installdate).each do |attr| - package[attr] = product[attr] + w32_product.find_all.each do |product| + name = product['name'] + package = packages[name] = Mash.new + %w(version vendor installdate).each do |attr| + package[attr] = product[attr] + end end end end collect_data(:aix) do - packages Mash.new - so = shell_out('lslpp -L -q -c') - pkgs = so.stdout.lines + if configuration(:enabled) + packages Mash.new + so = shell_out('lslpp -L -q -c') + pkgs = so.stdout.lines - # Output format is - # Package Name:Fileset:Level - # On aix, filesets are packages and levels are versions - pkgs.each do |pkg| - _, name, version = pkg.split(':') - packages[name] = { 'version' => version } + # Output format is + # Package Name:Fileset:Level + # On aix, filesets are packages and levels are versions + pkgs.each do |pkg| + _, name, version = pkg.split(':') + packages[name] = { 'version' => version } + end end end @@ -115,8 +119,10 @@ Ohai.plugin(:Packages) do end collect_data(:solaris2) do - packages Mash.new - collect_ips_packages - collect_sysv_packages + if configuration(:enabled) + packages Mash.new + collect_ips_packages + collect_sysv_packages + end end end diff --git a/spec/unit/plugins/packages_spec.rb b/spec/unit/plugins/packages_spec.rb index 7f5e63ab..47831811 100644 --- a/spec/unit/plugins/packages_spec.rb +++ b/spec/unit/plugins/packages_spec.rb @@ -20,6 +20,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, 'plugin packages' do + before do + Ohai.config[:plugin][:packages][:enabled] = true + end + context 'on debian' do let(:plugin) do get_plugin('packages').tap do |plugin| |