diff --git a/insights/parsers/installed_rpms.py b/insights/parsers/installed_rpms.py index b8c1d486be..cfa7e51075 100644 --- a/insights/parsers/installed_rpms.py +++ b/insights/parsers/installed_rpms.py @@ -79,6 +79,7 @@ from .. import parser, get_active_lines, CommandParser from .rpm_vercmp import rpm_version_compare from insights.specs import Specs +from insights import ContainerParser # This list of architectures is taken from PDC (Product Definition Center): # https://pdc.fedoraproject.org/rest_api/v1/arches/ @@ -628,3 +629,12 @@ def __hash__(self): from_package = InstalledRpm.from_package Rpm = InstalledRpm Installed = InstalledRpms + + +@parser(Specs.container_installed_rpms) +class ContainerInstalledRpms(ContainerParser, InstalledRpms): + """ + Parses the data for list of installed rpms of the running + containers which are based on RHEL images. + """ + pass diff --git a/insights/specs/__init__.py b/insights/specs/__init__.py index 8e7772ba9f..262de96c05 100644 --- a/insights/specs/__init__.py +++ b/insights/specs/__init__.py @@ -792,3 +792,4 @@ class Specs(SpecSet): # container_specs container_redhat_release = RegistryPoint(multi_output=True) container_nginx_conf = RegistryPoint(multi_output=True) + container_installed_rpms = RegistryPoint(multi_output=True) diff --git a/insights/specs/default.py b/insights/specs/default.py index 453ec533a1..ae41f64368 100644 --- a/insights/specs/default.py +++ b/insights/specs/default.py @@ -16,7 +16,7 @@ from insights.core.spec_factory import simple_file, simple_command, glob_file from insights.core.spec_factory import first_of, command_with_args from insights.core.spec_factory import foreach_collect, foreach_execute -from insights.core.spec_factory import container_collect +from insights.core.spec_factory import container_collect, container_execute from insights.core.spec_factory import first_file, listdir from insights.components.cloud_provider import IsAzure, IsGCP from insights.components.ceph import IsCephMonitor @@ -678,3 +678,4 @@ class DefaultSpecs(Specs): # container_specs container_redhat_release = container_collect(running_rhel_containers, "/etc/redhat-release") container_nginx_conf = container_collect(container_nginx_conf_ds) + container_installed_rpms = container_execute(running_rhel_containers, "rpm -qa --qf '%s'" % rpm_format, context=HostContext, signum=signal.SIGTERM) diff --git a/insights/tests/parsers/test_installed_rpms.py b/insights/tests/parsers/test_installed_rpms.py index a6f0636cdc..f87c4fff06 100644 --- a/insights/tests/parsers/test_installed_rpms.py +++ b/insights/tests/parsers/test_installed_rpms.py @@ -1,5 +1,5 @@ import pytest -from insights.parsers.installed_rpms import InstalledRpms, InstalledRpm, pad_version +from insights.parsers.installed_rpms import InstalledRpms, InstalledRpm, pad_version, ContainerInstalledRpms from insights.tests import context_wrap @@ -539,3 +539,41 @@ def test_vmaas(): assert isinstance(rpm, InstalledRpm) assert rpm.version == "5.2.2" assert rpm.release == "1.el7" + + +def test_container_installed_rpms(): + rpms = ContainerInstalledRpms( + context_wrap( + RPMS_PACKAGE, + container_id='39310f3ccc12', + image='registry.access.redhat.com/rhel9', + engine='podman', + path='insights_containers/39310f3ccc12/insights_commands/rpm_-qa_--qf_name_NAME_epoch_EPOCH_version_VERSION_release_RELEASE_arch_ARCH_installtime_INSTALLTIME_date_buildtime_BUILDTIME_vendor_VENDOR_buildhost_BUILDHOST_sigpgp_SIGPGP_pgpsig' + ) + ) + assert rpms.image == "registry.access.redhat.com/rhel9" + assert rpms.engine == "podman" + assert rpms.container_id == "39310f3ccc12" + assert rpms.get_min('openldap').package == 'openldap-2.4.23-31.el6' + pkg_rpm = rpms.packages['openssh-server'][0] + rpm = InstalledRpm.from_package(pkg_rpm.package) + assert rpm.package == 'openssh-server-5.3p1-104.el6' + assert pkg_rpm.package == 'openssh-server-5.3p1-104.el6' + assert rpm == pkg_rpm + assert rpm.epoch == '0' + + rpms_json = ContainerInstalledRpms( + context_wrap( + RPMS_JSON, + container_id='cc2883a1a369', + image='quay.io/rhel8', + engine='podman', + path='insights_containers/cc2883a1a369/insights_commands/rpm_-qa_--qf_name_NAME_epoch_EPOCH_version_VERSION_release_RELEASE_arch_ARCH_installtime_INSTALLTIME_date_buildtime_BUILDTIME_vendor_VENDOR_buildhost_BUILDHOST_sigpgp_SIGPGP_pgpsig' + ) + ) + assert rpms_json.image == "quay.io/rhel8" + assert rpms_json.engine == "podman" + assert rpms_json.container_id == "cc2883a1a369" + assert isinstance(rpms_json.get_max("log4j").source, InstalledRpm) + assert rpms_json.get_max("libteam").source.name == "libteam" + assert rpms_json.get_max("libteam").source.version == "1.17"