diff options
author | Jay Mundrawala <jdmundrawala@gmail.com> | 2016-02-02 10:34:51 -0800 |
---|---|---|
committer | Jay Mundrawala <jdmundrawala@gmail.com> | 2016-02-02 12:03:38 -0800 |
commit | 0e58e8d2c3d8b70342463d0547f90ab01be28af2 (patch) | |
tree | 9910086c7578de8e369263fbbda423db66698aae | |
parent | 50e002ef9227318b89242803f647b6c51a1e1a74 (diff) | |
download | ohai-jdm/disable-packages-by-default.tar.gz |
Don't enable packages plugin by defaultjdm/disable-packages-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 | 76 | ||||
-rw-r--r-- | spec/unit/plugins/packages_spec.rb | 4 |
2 files changed, 46 insertions, 34 deletions
diff --git a/lib/ohai/plugins/packages.rb b/lib/ohai/plugins/packages.rb index de031b9e..5f25e1b4 100644 --- a/lib/ohai/plugins/packages.rb +++ b/lib/ohai/plugins/packages.rb @@ -25,24 +25,26 @@ Ohai.plugin(:Packages) do collect_data(:linux) do packages Mash.new - if %w(debian).include? platform_family - so = shell_out('dpkg-query -W') - pkgs = so.stdout.lines + if configuration(:enabled) + 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 @@ -50,31 +52,35 @@ Ohai.plugin(:Packages) do collect_data(:windows) do packages Mash.new - require 'wmi-lite' + if configuration(:enabled) + 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) + 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 +121,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| |