diff options
author | Shahul Khajamohideen <skhajamohid1@bloomberg.net> | 2015-12-28 10:56:18 -0500 |
---|---|---|
committer | Shahul Khajamohideen <skhajamohid1@bloomberg.net> | 2015-12-28 11:05:48 -0500 |
commit | 35740cfad4b52d2f3a54f17932ce341ee2e80f76 (patch) | |
tree | 0320604adfc49dac2427917ab4e857601ff0161a | |
parent | b9c7f73a725ec9139540ba2305fc88647c596737 (diff) | |
download | ohai-35740cfad4b52d2f3a54f17932ce341ee2e80f76.tar.gz |
Add tests for sysv packages on solaris
-rw-r--r-- | lib/ohai/plugins/packages.rb | 36 | ||||
-rw-r--r-- | spec/unit/plugins/packages_spec.rb | 14 |
2 files changed, 25 insertions, 25 deletions
diff --git a/lib/ohai/plugins/packages.rb b/lib/ohai/plugins/packages.rb index ee8d032b..de031b9e 100644 --- a/lib/ohai/plugins/packages.rb +++ b/lib/ohai/plugins/packages.rb @@ -30,7 +30,7 @@ Ohai.plugin(:Packages) do pkgs = so.stdout.lines pkgs.each do |pkg| - name, version = pkg.split() + name, version = pkg.split packages[name] = { 'version' => version } end @@ -41,7 +41,7 @@ Ohai.plugin(:Packages) do pkgs = so.stdout.lines pkgs.each do |pkg| - name, version, release = pkg.split() + name, version, release = pkg.split packages[name] = { 'version' => version, 'release' => release } end end @@ -78,20 +78,16 @@ Ohai.plugin(:Packages) do 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() + so.stdout.lines.each do |pkg| + tokens = pkg.split if tokens.length == 3 # No publisher info - name, version, _ = tokens + name, version, = tokens else - name, publisher, version, _ = tokens + name, publisher, version, = tokens publisher = publisher[1..-2] end packages[name] = { 'version' => version } @@ -102,20 +98,20 @@ Ohai.plugin(:Packages) do 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| + chunked_lines = so.stdout.lines.map(&:strip).chunk do |line| !line.empty? || nil - }.each { |_, lines| - puts "Conunt is #{lines.count} lines is #{lines}" + end + chunked_lines.each do |_, lines| package = {} lines.each do |line| - puts "line is #{line}" - key, value = line.split(':') - package[key.strip] = value.strip + key, value = line.split(':', 2) + package[key.strip.downcase] = value.strip unless value.nil? end - packages[package['PKGINST']] = package.tap do |p| - p.delete['PKGINST'] + # pkginst is the installed package name + packages[package['pkginst']] = package.tap do |p| + p.delete('pkginst') end - } + end end collect_data(:solaris2) do @@ -123,6 +119,4 @@ Ohai.plugin(:Packages) do collect_ips_packages collect_sysv_packages end - - end diff --git a/spec/unit/plugins/packages_spec.rb b/spec/unit/plugins/packages_spec.rb index bd535313..7f5e63ab 100644 --- a/spec/unit/plugins/packages_spec.rb +++ b/spec/unit/plugins/packages_spec.rb @@ -221,15 +221,21 @@ describe Ohai::System, 'plugin packages' do plugin.run end - it 'gets packages with version' do - puts plugin[:packages] + it 'gets ips packages with version' do expect(plugin[:packages]['chef'][:version]).to eq('12.5.1') end - it 'gets packages with version and publisher' do + it 'gets ips 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 + it 'gets sysv packages with version' do + expect(plugin[:packages]['chef'][:version]).to eq('12.5.1') + end + + it 'gets sysv packages with version' do + expect(plugin[:packages]['mqm'][:version]).to eq('7.0.1.4') + end + end end |