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
# 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,6 +97,7 @@ module Inspec::Resources
# RedHat family
class Rpms < PkgsManagement
def build_package_list
# 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")