Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: New Parser for container_installed_rpms #3560

Merged
merged 5 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions insights/parsers/installed_rpms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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.
"""
xiangce marked this conversation as resolved.
Show resolved Hide resolved
pass
1 change: 1 addition & 0 deletions insights/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion insights/specs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
40 changes: 39 additions & 1 deletion insights/tests/parsers/test_installed_rpms.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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'
xiangce marked this conversation as resolved.
Show resolved Hide resolved

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"