Switch package resource to os.redhat detection and use two spaces as fileds delimited

Signed-off-by: Alex Pop <apop@chef.io>
This commit is contained in:
Alex Pop 2017-02-14 13:24:48 +00:00
parent fae96f6249
commit 88975bff2a
5 changed files with 32 additions and 30 deletions

View file

@ -29,7 +29,7 @@ module Inspec::Resources
os = inspec.os
if os.debian?
@pkgman = Deb.new(inspec)
elsif %w{redhat suse amazon fedora}.include?(os[:family])
elsif os.redhat? || %w{suse amazon fedora}.include?(os[:family])
@pkgman = Rpm.new(inspec)
elsif ['arch'].include?(os[:family])
@pkgman = Pacman.new(inspec)

View file

@ -26,7 +26,7 @@ module Inspec::Resources
os = inspec.os
if os.debian?
@pkgs = Debs.new(inspec)
elsif %w{redhat suse amazon fedora}.include?(os[:family])
elsif os.redhat? || %w{suse amazon fedora}.include?(os[:family])
@pkgs = Rpms.new(inspec)
else
return skip_resource "The packages resource is not yet supported on OS #{inspec.os.name}"
@ -80,12 +80,13 @@ module Inspec::Resources
# Debian / Ubuntu
class Debs < PkgsManagement
def build_package_list
command = "dpkg-query -W -f='${db:Status-Abbrev} ${Package} ${Version}\\n'"
# use two spaces as delimiter in case any of the fields has a space in it
command = "dpkg-query -W -f='${db:Status-Abbrev} ${Package} ${Version}\\n'"
cmd = inspec.command(command)
all = cmd.stdout.split("\n")
return [] if all.nil?
all.map do |m|
a = m.split
a = m.split(/ {2,}/)
a[0] = 'installed' if a[0] =~ /^.i/
a[2] = a[2].split(':').last
PackageStruct.new(*a)
@ -96,12 +97,13 @@ module Inspec::Resources
# RedHat family
class Rpms < PkgsManagement
def build_package_list
command = "rpm -qa --queryformat '%{NAME} %{VERSION}-%{RELEASE}\\n'"
# use two spaces as delimiter in case any of the fields has a space in it
command = "rpm -qa --queryformat '%{NAME} %{VERSION}-%{RELEASE}\\n'"
cmd = inspec.command(command)
all = cmd.stdout.split("\n")
return [] if all.nil?
all.map do |m|
a = m.split(' ')
a = m.split(' ')
a.unshift('installed')
PackageStruct.new(*a)
end

View file

@ -251,9 +251,9 @@ class MockLoader
# solaris 11 package manager
'pkg info system/file-system/zfs' => cmd.call('pkg-info-system-file-system-zfs'),
# dpkg-query all packages
"dpkg-query -W -f='${db:Status-Abbrev} ${Package} ${Version}\\n'" => cmd.call('dpkg-query-W'),
"dpkg-query -W -f='${db:Status-Abbrev} ${Package} ${Version}\\n'" => cmd.call('dpkg-query-W'),
# rpm query all packages
"rpm -qa --queryformat '%{NAME} %{VERSION}-%{RELEASE}\\n'" => cmd.call('rpm-qa-queryformat'),
"rpm -qa --queryformat '%{NAME} %{VERSION}-%{RELEASE}\\n'" => cmd.call('rpm-qa-queryformat'),
# port netstat on solaris 10 & 11
'netstat -an -f inet -f inet6' => cmd.call('s11-netstat-an-finet-finet6'),
# xinetd configuration

View file

@ -1,12 +1,12 @@
ii bash 4.3-14ubuntu1.1
rc fakeroot 1.20.2-1ubuntu1
rc libfakeroot 1.20.2-1ubuntu1
ii overlayroot 0.27ubuntu1.2
ii vim 2:7.4.1689-3ubuntu1.2
ii vim-common 2:7.4.1689-3ubuntu1.2
ii xorg 1:7.7+13ubuntu3
ii xorg-docs-core 1:1.7.1-1ubuntu1
ii xserver-common 2:1.18.4-0ubuntu0.2
ii xserver-xorg 1:7.7+13ubuntu3
ii xserver-xorg-core 2:1.18.4-0ubuntu0.2
ii xserver-xorg-input-all 1:7.7+13ubuntu3
ii bash 4.3-14ubuntu1.1
rc fakeroot 1.20.2-1ubuntu1
rc libfakeroot 1.20.2-1ubuntu1
ii overlayroot 0.27ubuntu1.2
ii vim 2:7.4.1689-3ubuntu1.2
ii vim-common 2:7.4.1689-3ubuntu1.2
ii xorg 1:7.7+13ubuntu3
ii xorg-docs-core 1:1.7.1-1ubuntu1
ii xserver-common 2:1.18.4-0ubuntu0.2
ii xserver-xorg 1:7.7+13ubuntu3
ii xserver-xorg-core 2:1.18.4-0ubuntu0.2
ii xserver-xorg-input-all 1:7.7+13ubuntu3

View file

@ -1,10 +1,10 @@
attr 2.4.44-7.el6
perl-Pod-Escapes 1.04-141.el6_7.1
perl-version 0.77-141.el6_7.1
perl-Pod-Simple 3.13-141.el6_7.1
vim-filesystem 7.4.629-5.el6
gpm-libs 1.20.6-12.el6
mlocate 0.22.2-6.el6
ntpdate 4.2.6p5-10.el6.centos.1
chef-compliance 1.3.1-1.el6
nc 1.84-24.el6
attr 2.4.44-7.el6
perl-Pod-Escapes 1.04-141.el6_7.1
perl-version 0.77-141.el6_7.1
perl-Pod-Simple 3.13-141.el6_7.1
vim-filesystem 7.4.629-5.el6
gpm-libs 1.20.6-12.el6
mlocate 0.22.2-6.el6
ntpdate 4.2.6p5-10.el6.centos.1
chef-compliance 1.3.1-1.el6
nc 1.84-24.el6