Fixed parsing yum output on centos8.

* Renamed and added extra test data to distinguish between centos 7 & centos 8.
* Renamed and added extra tests to cover centos 8.
* Fixed missing repo data by checking at the end if we were still in parse mode.

Fixes #4517

Signed-off-by: Ryan Davis <zenspider@chef.io>
Cc: Miah Johnson <miah@chia-pet.org>
This commit is contained in:
Ryan Davis 2019-10-04 17:20:36 -07:00
parent 201d98fd26
commit fc8ea79ad0
5 changed files with 75 additions and 7 deletions

View file

@ -70,6 +70,9 @@ module Inspec::Resources
repo[repo_key(strip(val[1]))] = strip(val[2])
end
end
@cache.push(repo) if in_repo
@cache
end

View file

@ -1,11 +1,12 @@
class MockLoader
# collects emulation operating systems
OPERATING_SYSTEMS = {
OPERATING_SYSTEMS = { # rubocop:disable Style/MutableConstant
alpine: { name: "alpine", family: "alpine", release: "3.6.2", arch: "x86_64" },
arch: { name: "arch", family: "arch", release: nil, arch: nil },
centos5: { name: "centos", family: "redhat", release: "5.11", arch: "x86_64" },
centos6: { name: "centos", family: "redhat", release: "6.6", arch: "x86_64" },
centos7: { name: "centos", family: "redhat", release: "7.1.1503", arch: "x86_64" },
centos8: { name: "centos", family: "redhat", release: "8.9.10", arch: "x86_64" },
cloudlinux: { name: "cloudlinux", family: "redhat", release: "7.4", arch: "x86_64" },
coreos: { name: "coreos", family: "coreos", release: "1437.0.0", arch: "x86_64" },
debian6: { name: "debian", family: "debian", release: "6", arch: "x86_64" },
@ -30,7 +31,9 @@ class MockLoader
amazon: { name: "amazon", family: "redhat", release: "2015.03", arch: "x86_64" },
amazon2: { name: "amazon", family: "redhat", release: "2", arch: "x86_64" },
undefined: { name: nil, family: nil, release: nil, arch: nil },
}.freeze
}
OPERATING_SYSTEMS[:linux] = OPERATING_SYSTEMS[:ubuntu1604]
# pass the os identifier to emulate a specific operating system
def initialize(os = :ubuntu1404)
@ -209,7 +212,6 @@ class MockLoader
"Auditpol /get /subcategory:'User Account Management' /r" => cmd.call("auditpol"),
"/sbin/auditctl -l" => cmd.call("auditctl"),
"/sbin/auditctl -s" => cmd.call("auditctl-s"),
"yum -v repolist all" => cmd.call("yum-repolist-all"),
"dpkg -s curl" => cmd.call("dpkg-s-curl"),
"dpkg -s held-package" => cmd.call("dpkg-s-held-package"),
"rpm -qi curl" => cmd.call("rpm-qi-curl"),

View file

@ -0,0 +1,50 @@
Config time: 0.006
Yum version: 3.4.3
base | 3.6 kB 00:00:00
epel/x86_64/metalink | 26 kB 00:00:00
epel | 4.3 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/3): epel/x86_64/group_gz | 169 kB 00:00:00
epel/x86_64/primary_db FAILED
https://ftp.fau.de/epel/7/x86_64/repodata/ccbc93c2ab37b82a6376c9562d2aec27b81112bc3c943e1871f7ed0318fe24b9-primary.sqlite.xz: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.
(2/3): epel/x86_64/updateinfo | 349 kB 00:00:00
(3/3): epel/x86_64/primary_db | 3.5 MB 00:00:04
Loading mirror speeds from cached hostfile
* base: ftp.hosteurope.de
* epel: ftp-stud.hs-esslingen.de
* extras: mirror.informatik.hs-fulda.de
* updates: mirror.softaculous.com
Setting up Package Sacks
pkgsack time: 0.005
Repo-id : base/7/x86_64
Repo-name : CentOS-7 - Base
Repo-status : enabled
Repo-revision: 1427842153
Repo-updated : Tue Mar 31 22:50:46 2015
Repo-pkgs : 8652
Repo-size : 6.3 G
Repo-mirrors : http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock
Repo-baseurl : http://ftp.hosteurope.de/mirror/centos.org/7.1.1503/os/x86_64/ (9 more)
Repo-expire : 21600 second(s) (last: Sun Sep 6 10:20:46 2015)
Repo-filename: /etc/yum.repos.d/CentOS-Base.repo
Repo-id : base-debuginfo/x86_64
Repo-name : CentOS-7 - Debuginfo
Repo-status : disabled
Repo-baseurl : http://debuginfo.centos.org/7/x86_64/
Repo-expire : 21600 second(s) (last: Unknown)
Repo-filename: /etc/yum.repos.d/CentOS-Debuginfo.repo
Repo-id : extras/7/x86_64
Repo-name : CentOS-7 - Extras
Repo-status : enabled
Repo-revision: 1441314199
Repo-updated : Thu Sep 3 21:03:33 2015
Repo-pkgs : 181
Repo-size : 742 M
Repo-mirrors : http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock
Repo-baseurl : http://mirror.informatik.hs-fulda.de/centos7.1.1503/extras/x86_64/ (9 more)
Repo-expire : 21600 second(s) (last: Sun Sep 6 10:20:48 2015)
Repo-filename: /etc/yum.repos.d/CentOS-Base.repo

View file

@ -4,13 +4,18 @@ require "inspec/resources/yum"
describe "Inspec::Resources::YumRepo" do
let(:centos7) do
quick_resource("yum") do |cmd|
stdout_file "./test/unit/mock/cmd/yum-repolist-all"
quick_resource("yum", :centos7) do |cmd|
stdout_file "./test/unit/mock/cmd/yum-centos7-repolist-all"
end
end
it "get repository details" do
resource = centos7
let(:centos8) do
quick_resource("yum", :centos8) do |cmd|
stdout_file "./test/unit/mock/cmd/yum-centos8-repolist-all"
end
end
def assert_repositories(resource)
_(resource.repositories).must_equal [{
"id" => "base/7/x86_64",
"name" => "CentOS-7 - Base",
@ -66,6 +71,14 @@ describe "Inspec::Resources::YumRepo" do
_(extras.to_s).must_equal "YumRepo base-debuginfo/x86_64"
end
it "get repository details centos7" do
assert_repositories centos7
end
it "get repository details centos8" do
assert_repositories centos8
end
it "provides methods for retrieving per-repo information" do
resource = centos7
repo = resource.repo("base/7/x86_64")