Skip to content

Commit

Permalink
Raise SkipException when no packages are found in installed_rpms
Browse files Browse the repository at this point in the history
Signed-off-by: Xiangce Liu <[email protected]>
  • Loading branch information
xiangce committed Jul 7, 2020
1 parent 9034541 commit b105e87
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions insights/parsers/installed_rpms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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)

Expand Down
16 changes: 16 additions & 0 deletions insights/parsers/tests/test_installed_rpms.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit b105e87

Please sign in to comment.