From b105e872c55f56f1e0544a0355c8b7514c80d157 Mon Sep 17 00:00:00 2001 From: Xiangce Liu Date: Tue, 7 Jul 2020 10:39:58 +0800 Subject: [PATCH] Raise SkipException when no packages are found in installed_rpms Signed-off-by: Xiangce Liu --- insights/parsers/installed_rpms.py | 6 ++++++ insights/parsers/tests/test_installed_rpms.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/insights/parsers/installed_rpms.py b/insights/parsers/installed_rpms.py index cd7010026d..45f15cbf85 100644 --- a/insights/parsers/installed_rpms.py +++ b/insights/parsers/installed_rpms.py @@ -78,6 +78,7 @@ from ..util import rsplit from .. import parser, get_active_lines, CommandParser from .rpm_vercmp import rpm_version_compare +from insights.parsers import SkipException from insights.specs import Specs # This list of architectures is taken from PDC (Product Definition Center): @@ -215,6 +216,9 @@ class InstalledRpms(CommandParser, RpmList): """ A parser for working with data containing a list of installed RPM files on the system and related information. + + Raises: + SkipException: When no packages are found. """ def __init__(self, *args, **kwargs): self.errors = [] @@ -244,6 +248,8 @@ def parse_content(self, content): except Exception: # Both ways failed self.unparsed.append(line) + if not self.packages: + raise SkipException() # Don't want defaultdict's behavior after parsing is complete self.packages = dict(self.packages) diff --git a/insights/parsers/tests/test_installed_rpms.py b/insights/parsers/tests/test_installed_rpms.py index fb6643c113..53851cf14f 100644 --- a/insights/parsers/tests/test_installed_rpms.py +++ b/insights/parsers/tests/test_installed_rpms.py @@ -1,5 +1,6 @@ import pytest from insights.parsers.installed_rpms import InstalledRpms, InstalledRpm, pad_version +from insights.parsers import SkipException from insights.tests import context_wrap @@ -80,6 +81,18 @@ yum-security-1.1.16-21.el5.noarch '''.strip() +ERROR_DB_NO_PKG = """ +error: rpmdb: BDB0113 Thread/process 20263/140251984590912 failed: BDB1507 Thread died in Berkeley DB library +error: db5 error(-30973) from dbenv->failchk: BDB0087 DB_RUNRECOVERY: Fatal +error, run database recovery +error: cannot open Packages index using db5 - (-30973) +error: cannot open Packages database in /var/lib/rpm +error: rpmdb: BDB0113 Thread/process 20263/140251984590912 failed: BDB1507 Thread died in Berkeley DB library +error: db5 error(-30973) from dbenv->failchk: BDB0087 DB_RUNRECOVERY: Fatal +error, run database recovery +error: cannot open Packages database in /var/lib/rpm +""".strip() + ORACLEASM_RPMS = ''' oracleasm-2.6.18-164.el5-2.0.5-1.el5.x86_64 oracleasmlib-2.0.4-1.el5.x86_64 @@ -198,6 +211,9 @@ def test_corrupt_db(): assert "yum-security" in rpms.packages assert rpms.corrupt is True + with pytest.raises(SkipException): + InstalledRpms(context_wrap(ERROR_DB_NO_PKG)) + def test_rpm_manifest(): rpms = InstalledRpms(context_wrap(RPM_MANIFEST))