summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShahul Khajamohideen <skhajamohid1@bloomberg.net>2015-12-23 17:59:36 -0500
committerShahul Khajamohideen <skhajamohid1@bloomberg.net>2015-12-28 11:05:48 -0500
commitb9c7f73a725ec9139540ba2305fc88647c596737 (patch)
tree1fee06aa5f34a291305e741a8539532c0e981058
parent8e50394485b9558d0996159a3d961d46c903c729 (diff)
downloadohai-b9c7f73a725ec9139540ba2305fc88647c596737.tar.gz
Implement packages plugin for AIX, Solaris
-rw-r--r--lib/ohai/plugins/packages.rb70
-rw-r--r--spec/data/plugins/lslpp.output49
-rw-r--r--spec/data/plugins/pkginfo.output50
-rw-r--r--spec/data/plugins/pkglist.output24
-rw-r--r--spec/unit/plugins/packages_spec.rb75
5 files changed, 261 insertions, 7 deletions
diff --git a/lib/ohai/plugins/packages.rb b/lib/ohai/plugins/packages.rb
index d6d3439c..ee8d032b 100644
--- a/lib/ohai/plugins/packages.rb
+++ b/lib/ohai/plugins/packages.rb
@@ -27,10 +27,10 @@ Ohai.plugin(:Packages) do
if %w(debian).include? platform_family
so = shell_out('dpkg-query -W')
- pkgs = so.stdout.split("\n")
+ pkgs = so.stdout.lines
pkgs.each do |pkg|
- name, version = pkg.split("\t")
+ name, version = pkg.split()
packages[name] = { 'version' => version }
end
@@ -38,10 +38,10 @@ Ohai.plugin(:Packages) do
require 'shellwords'
format = Shellwords.escape '%{NAME}\t%{VERSION}\t%{RELEASE}\n'
so = shell_out("rpm -qa --queryformat #{format}")
- pkgs = so.stdout.split("\n")
+ pkgs = so.stdout.lines
pkgs.each do |pkg|
- name, version, release = pkg.split("\t")
+ name, version, release = pkg.split()
packages[name] = { 'version' => version, 'release' => release }
end
end
@@ -63,4 +63,66 @@ Ohai.plugin(:Packages) do
end
end
end
+
+ collect_data(:aix) do
+ 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 }
+ end
+ end
+
+
+ def collect_ips_packages
+ so = shell_out('pkg list -H')
+ pkgs = so.stdout.lines
+
+ # Output format is
+ # NAME (PUBLISHER) VERSION IFO
+
+ pkgs.each do |pkg|
+ tokens = pkg.split()
+ if tokens.length == 3 # No publisher info
+ name, version, _ = tokens
+ else
+ name, publisher, version, _ = tokens
+ publisher = publisher[1..-2]
+ end
+ packages[name] = { 'version' => version }
+ packages[name]['publisher'] = publisher if publisher
+ end
+ end
+
+ def collect_sysv_packages
+ so = shell_out('pkginfo -l')
+ # Each package info is separated by a blank line
+ so.stdout.lines.map { |line| line.strip }.chunk { |line|
+ !line.empty? || nil
+ }.each { |_, lines|
+ puts "Conunt is #{lines.count} lines is #{lines}"
+ package = {}
+ lines.each do |line|
+ puts "line is #{line}"
+ key, value = line.split(':')
+ package[key.strip] = value.strip
+ end
+ packages[package['PKGINST']] = package.tap do |p|
+ p.delete['PKGINST']
+ end
+ }
+ end
+
+ collect_data(:solaris2) do
+ packages Mash.new
+ collect_ips_packages
+ collect_sysv_packages
+ end
+
+
end
diff --git a/spec/data/plugins/lslpp.output b/spec/data/plugins/lslpp.output
new file mode 100644
index 00000000..0175eacf
--- /dev/null
+++ b/spec/data/plugins/lslpp.output
@@ -0,0 +1,49 @@
+bos.sysmgt:bos.sysmgt.smit:7.1.1.15: : :C:F:System Management Interface Tool (SMIT): : : : : : :0:0:/:1216
+bos.sysmgt:bos.sysmgt.sysbr:7.1.1.17: : :C:F:System Backup and BOS Install Utilities: : : : : : :0:0:/:1228
+bos.sysmgt:bos.sysmgt.trace:7.1.1.15: : :C:F:Software Trace Service Aids: : : : : : :0:1:/:1216
+bos.terminfo:bos.terminfo.ansi.data:7.1.0.0: : :C: :Amer National Stds Institute Terminal Defs: : : : : : :0:1:/:1036
+bos.terminfo:bos.terminfo.com.data:7.1.0.0: : :C: :Common Terminal Definitions: : : : : : :0:1:/:1036
+bos.terminfo:bos.terminfo.dec.data:7.1.0.0: : :C: :Digital Equipment Corp. Terminal Definitions: : : : : : :0:1:/:1036
+bos.terminfo:bos.terminfo.ibm.data:7.1.0.0: : :C: :IBM Terminal Definitions: : : : : : :0:1:/:1036
+bos.terminfo:bos.terminfo.pc.data:7.1.0.0: : :C: :Personal Computer Terminal Definitions: : : : : : :0:1:/:1036
+bos.terminfo:bos.terminfo.print.data:7.1.0.0: : :C: :Generic Line Printer Terminal Definitions: : : : : : :0:1:/:1036
+bos.terminfo:bos.terminfo.rte:7.1.0.0: : :C: :Run-time Environment for AIX Terminals: : : : : : :0:0:/:1036
+bos.terminfo:bos.terminfo.svprint.data:7.1.0.0: : :C: :System V Printer Terminal Definitions: : : : : : :0:0:/:1036
+bos.terminfo:bos.terminfo.televideo.data:7.1.0.0: : :C: :Televideo Terminal Definitions: : : : : : :0:0:/:1036
+bos.terminfo:bos.terminfo.wyse.data:7.1.0.0: : :C: :Wyse Terminal Definitions: : : : : : :0:0:/:1036
+bos.txt:bos.txt.hplj.fnt:7.1.0.0: : :C: :Fonts for Hewlett Packard Laser Jet Printers : : : : : : :0:0:/:1115
+bos.txt:bos.txt.ibm3812.fnt:7.1.0.0: : :C: :Fonts for IBM 3812 Printer : : : : : : :0:0:/:1115
+bos.txt:bos.txt.ibm3816.fnt:7.1.0.0: : :C: :Fonts for IBM 3816 Printer : : : : : : :0:0:/:1115
+bos.txt:bos.txt.spell:7.1.0.0: : :C: :Writer's Tools Commands : : : : : : :0:0:/:1115
+bos.txt:bos.txt.spell.data:7.1.0.0: : :C: :Writer's Tools Data: : : : : : :0:0:/:1036
+bos.txt:bos.txt.tfs:7.1.1.15: : :C:F:Text Formatting Services Commands: : : : : : :0:0:/:1216
+bos.txt:bos.txt.tfs.data:7.1.0.0: : :C: :Text Formatting Services Data: : : : : : :0:0:/:1036
+bos.wpars:bos.wpars:7.1.1.15: : :C:F:AIX Workload Partitions: : : : : : :0:0:/:1216
+cdrtools.base:cdrtools.base:1.9.0.9: : :C: :CD/DVD recorder: : : : : : :0:0:/:
+cdrtools.man.en_US:cdrtools.man.en_US:1.9.0.9: : :C: :CD/DVD recorder man page documentation: : : : : : :0:0:/:
+chef:chef:12.5.1.1: : :C: :The full stack of chef: : : : : : :0:0:/:
+clic.rte:clic.rte.kernext:4.7.0.1: : :C: :CryptoLite for C Kernel: : : : : : :0:0:/:
+clic.rte:clic.rte.lib:4.7.0.1: : :C: :CryptoLite for C Library: : : : : : :0:0:/:
+devices.artic960:devices.artic960.diag:7.1.0.0: : :C: :IBM ARTIC960 Adapter Diagnostics : : : : : : :0:0:/:1115
+devices.artic960:devices.artic960.rte:7.1.1.15: : :C:F:IBM ARTIC960 Runtime Support: : : : : : :0:0:/:1216
+devices.artic960:devices.artic960.ucode:7.1.0.0: : :C: :IBM ARTIC960 Adapter Software : : : : : : :0:0:/:1115
+devices.chrp.AT97SC3201_r:devices.chrp.AT97SC3201_r.rte:7.1.0.0: : :C: :Trusted Platform Module Device Software: : : : : : :0:0:/:1036
+devices.chrp.IBM.lhca:devices.chrp.IBM.lhca.rte:7.1.1.16: : :C:F:Infiniband Logical HCA Runtime Environment: : : : : : :0:0:/:1228
+devices.chrp.IBM.lhea:devices.chrp.IBM.lhea.diag:7.1.0.0: : :C: :Host Ethernet Adapter Diagnostics : : : : : : :0:0:/:1115
+devices.chrp.IBM.lhea:devices.chrp.IBM.lhea.rte:7.1.1.16: : :C:F:Host Ethernet Adapter (HEA) Runtime Environment: : : : : : :0:0:/:1228
+devices.chrp.base:devices.chrp.base.ServiceRM:1.5.1.0: : :C:F:RSCT Service Resource Manager: : : : : : :0:0:/:
+devices.chrp.base:devices.chrp.base.diag:7.1.1.15: : :C:F:RISC CHRP Base System Device Diagnostics: : : : : : :0:0:/:1216
+devices.chrp.base:devices.chrp.base.rte:7.1.1.16: : :C:F:RISC PC Base System Device Software (CHRP): : : : : : :0:0:/:1228
+devices.chrp.pci:devices.chrp.pci.rte:7.1.1.16: : :C:F:PCI Bus Software (CHRP): : : : : : :0:0:/:1228
+devices.chrp.pciex:devices.chrp.pciex.rte:7.1.0.0: : :C: :PCI Express Bus Software (CHRP): : : : : : :0:0:/:1036
+devices.chrp.vdevice:devices.chrp.vdevice.rte:7.1.1.16: : :C:F:Virtual I/O Bus Support: : : : : : :0:0:/:1228
+devices.chrp_lpar.base:devices.chrp_lpar.base.ras:7.1.0.15: : :C: :CHRP LPAR RAS Support : : : : : : :0:0:/:1115
+devices.common.IBM.async:devices.common.IBM.async.diag:7.1.0.0: : :C: :Common Serial Adapter Diagnostics: : : : : : :0:0:/:1036
+devices.common.IBM.atm:devices.common.IBM.atm.rte:7.1.1.16: : :C:F:Common ATM Software: : : : : : :0:0:/:1228
+devices.common.IBM.crypt:devices.common.IBM.crypt.rte:7.1.0.0: : :C: :Cryptographic Common Runtime Environment: : : : : : :0:0:/:1036
+devices.common.IBM.cx:devices.common.IBM.cx.rte:7.1.1.15: : :C:F:CX Common Adapter Software: : : : : : :0:0:/:1216
+devices.common.IBM.disk:devices.common.IBM.disk.rte:7.1.1.15: : :C:F:Common IBM Disk Software: : : : : : :0:0:/:1216
+devices.common.IBM.ethernet:devices.common.IBM.ethernet.rte:7.1.1.16: : :C:F:Common Ethernet Software: : : : : : :0:1:/:1228
+devices.common.IBM.fc:devices.common.IBM.fc.hba-api:7.1.1.16: : :C:F:Common HBA API Library: : : : : : :0:0:/:1228
+devices.common.IBM.fc:devices.common.IBM.fc.rte:7.1.1.16: : :C:F:Common IBM FC Software: : : : : : :0:0:/:1228
+devices.common.IBM.fda:devices.common.IBM.fda.diag:7.1.0.0: : :C: :Common Diskette Adapter and Device Diagnostics: : : : : : :0:0:/:1036
diff --git a/spec/data/plugins/pkginfo.output b/spec/data/plugins/pkginfo.output
new file mode 100644
index 00000000..3b5db466
--- /dev/null
+++ b/spec/data/plugins/pkginfo.output
@@ -0,0 +1,50 @@
+ PKGINST: mqm
+ NAME: WebSphere MQ Client for Sun Solaris
+ CATEGORY: application
+ ARCH: sparcv9
+ VERSION: 7.0.1.4
+ BASEDIR: /
+ VENDOR: IBM
+ PSTAMP: src (packaged: January 14, 2011 - 11:44:27 PM)
+ INSTDATE: Dec 22 2015 17:10
+ VSTOCK: 5724-H72
+ STATUS: completely installed
+ FILES: 3303 installed pathnames
+ 88 directories
+ 158 executables
+ 20 setuid/setgid executables
+ 327903 blocks used (approx)
+
+ PKGINST: vasclnt
+ NAME: vasclnt 4.1.0.21853
+ CATEGORY: application
+ ARCH: sparcv9
+ VERSION: 4.1.0.21853
+ BASEDIR: /
+ VENDOR: Quest Software, Inc.
+ DESC: Quest Authentication System (QAS) provides centralized user and
+ PSTAMP: vassol8sparc20150701013812
+ INSTDATE: Dec 22 2015 16:58
+ STATUS: completely installed
+ FILES: 174 installed pathnames
+ 9 shared pathnames
+ 32 directories
+ 101 executables
+ 60402 blocks used (approx)
+
+ PKGINST: vasgp
+ NAME: vasgp 4.1.0.21853
+ CATEGORY: application
+ ARCH: sparcv9
+ VERSION: 4.1.0.21853
+ BASEDIR: /
+ VENDOR: Quest Software, Inc.
+ DESC: Quest Group Policy (QGP) provides Active Directory Group Policy
+ PSTAMP: vassol8sparc20150701013859
+ INSTDATE: Dec 22 2015 17:06
+ STATUS: completely installed
+ FILES: 50 installed pathnames
+ 9 shared pathnames
+ 18 directories
+ 25 executables
+ 11999 blocks used (approx)
diff --git a/spec/data/plugins/pkglist.output b/spec/data/plugins/pkglist.output
new file mode 100644
index 00000000..4e1980f1
--- /dev/null
+++ b/spec/data/plugins/pkglist.output
@@ -0,0 +1,24 @@
+chef 12.5.1 i--
+compatibility/ucb 0.5.11-0.175.2.0.0.42.2 i--
+compress/bzip2 1.0.6-0.175.2.0.0.42.1 i--
+compress/gzip 1.5-0.175.2.4.0.3.0 i--
+compress/p7zip 9.20.1-0.175.2.0.0.42.1 i--
+compress/pbzip2 1.1.6-0.175.2.0.0.42.1 i--
+compress/pixz 1.0-0.175.2.0.0.42.1 i--
+compress/unzip 6.0-0.175.2.3.0.4.0 i--
+compress/xz 5.0.1-0.175.2.0.0.42.1 i--
+compress/zip 3.0-0.175.2.0.0.42.1 i--
+consolidation/SunVTS/SunVTS-incorporation 7.18.2-0.175.2.1.0.5.1 i--
+consolidation/X/X-incorporation 0.5.11-0.175.2.1.0.3.1413 i--
+consolidation/admin/admin-incorporation 0.5.11-0.175.1.0.0.5.0 i--
+consolidation/cacao/cacao-incorporation 0.5.11-0.175.2.0.0.38.0 i--
+consolidation/cde/cde-incorporation 0.5.11-0.175.2.0.0.23.0 i--
+consolidation/cns/cns-incorporation 0.5.11-0.175.2.0.0.39.0 i--
+consolidation/dbtg/dbtg-incorporation 0.5.11-0.175.2.0.0.38.0 i--
+consolidation/ddt/ddt-incorporation 8.10.15.11.23 i--
+consolidation/desktop/desktop-incorporation 0.5.11-0.175.2.4.0.5.0 i--
+consolidation/desktop/gnome-incorporation 0.5.11-0.175.2.0.0.42.0 i--
+consolidation/gfx/gfx-incorporation 0.5.11-0.175.1.0.0.5.0 i--
+consolidation/ips/ips-incorporation 0.5.11-0.175.2.3.0.3.0 i--
+consolidation/java-7/java-7-incorporation 1.7.0.72.14-0 i--
+system/EMCpower (emc.com) 6.0.0.1.0-3 i--
diff --git a/spec/unit/plugins/packages_spec.rb b/spec/unit/plugins/packages_spec.rb
index 437121c0..bd535313 100644
--- a/spec/unit/plugins/packages_spec.rb
+++ b/spec/unit/plugins/packages_spec.rb
@@ -46,7 +46,7 @@ describe Ohai::System, 'plugin packages' do
plugin.run
end
- it 'gets the packages and versions' do
+ it 'gets packages and versions' do
expect(plugin[:packages]['vim-common'][:version]).to eq('2:7.4.052-1ubuntu3')
end
end
@@ -77,7 +77,7 @@ describe Ohai::System, 'plugin packages' do
plugin.run
end
- it 'gets the packages and versions/release' do
+ it 'gets packages and versions/release' do
expect(plugin[:packages]['vim-common'][:version]).to eq('7.2.411')
expect(plugin[:packages]['vim-common'][:release]).to eq('1.8.el6')
end
@@ -153,7 +153,7 @@ describe Ohai::System, 'plugin packages' do
plugin.run
end
- it 'gets the package info' do
+ it 'gets package info' do
expect(plugin[:packages]['Chef Development Kit v0.7.0'][:version]).to eq('0.7.0.1')
expect(plugin[:packages]['Chef Development Kit v0.7.0'][:vendor]).to eq("\"Chef Software, Inc. <maintainers@chef.io>\"")
expect(plugin[:packages]['Chef Development Kit v0.7.0'][:installdate]).to eq('20150925')
@@ -163,4 +163,73 @@ describe Ohai::System, 'plugin packages' do
expect(plugin[:packages]['NXLOG-CE'][:installdate]).to eq('20150511')
end
end
+
+ context 'on aix' do
+ let(:plugin) { get_plugin('packages') }
+
+ let(:stdout) do
+ File.read(File.join(SPEC_PLUGIN_PATH, 'lslpp.output'))
+ end
+
+ before(:each) do
+ allow(plugin).to receive(:collect_os).and_return(:aix)
+ allow(plugin).to receive(:shell_out).with('lslpp -L -q -c').and_return(mock_shell_out(0, stdout, ''))
+ plugin.run
+ end
+
+ it 'calls lslpp -L -q -c' do
+ expect(plugin).to receive(:shell_out)
+ .with('lslpp -L -q -c')
+ .and_return(mock_shell_out(0, stdout, ''))
+ plugin.run
+ end
+
+ it 'gets packages with version' do
+ expect(plugin[:packages]['chef'][:version]).to eq('12.5.1.1')
+ end
+ end
+
+ context 'on solaris2' do
+ let(:plugin) { get_plugin('packages') }
+
+ let(:pkglist_output) do
+ File.read(File.join(SPEC_PLUGIN_PATH, 'pkglist.output'))
+ end
+
+ let(:pkginfo_output) do
+ File.read(File.join(SPEC_PLUGIN_PATH, 'pkginfo.output'))
+ end
+
+ before(:each) do
+ allow(plugin).to receive(:collect_os).and_return(:solaris2)
+ allow(plugin).to receive(:shell_out).with('pkg list -H').and_return(mock_shell_out(0, pkglist_output, ''))
+ allow(plugin).to receive(:shell_out).with('pkginfo -l').and_return(mock_shell_out(0, pkginfo_output, ''))
+ plugin.run
+ end
+
+ it 'calls pkg list -H' do
+ expect(plugin).to receive(:shell_out)
+ .with('pkg list -H')
+ .and_return(mock_shell_out(0, pkglist_output, ''))
+ plugin.run
+ end
+
+ it 'calls pkginfo -l' do
+ expect(plugin).to receive(:shell_out)
+ .with('pkginfo -l')
+ .and_return(mock_shell_out(0, pkginfo_output, ''))
+ plugin.run
+ end
+
+ it 'gets packages with version' do
+ puts plugin[:packages]
+ expect(plugin[:packages]['chef'][:version]).to eq('12.5.1')
+ end
+
+ it 'gets packages with version and publisher' do
+ expect(plugin[:packages]['system/EMCpower'][:version]).to eq('6.0.0.1.0-3')
+ expect(plugin[:packages]['system/EMCpower'][:publisher]).to eq('emc.com')
+ end
+ end
+
end