diff --git a/insights/parsers/dotnet.py b/insights/parsers/dotnet.py index bbc91d10d3..ef11575db0 100644 --- a/insights/parsers/dotnet.py +++ b/insights/parsers/dotnet.py @@ -2,13 +2,19 @@ DotNet- Comand ``/usr/bin/dotnet`` ================================== -The parser for ``/usr/bin/dotnet --version`` is included in this module.. +The parsers related ``/usr/bin/dotnet --version`` is included in this module. +DotNetVersion - command ``dotnet --version`` +-------------------------------------------- + +ContainerDotNetVersion - command ``dotnet --version`` for containers +-------------------------------------------------------------------- """ from insights import parser, CommandParser from insights.parsers import SkipException, ParseException from insights.specs import Specs +from insights import ContainerParser @parser(Specs.dotnet_version) @@ -44,3 +50,33 @@ def parse_content(self, content): if self.major is None: raise ParseException("Unrecognized version: {0}", self.raw) + + +@parser(Specs.container_dotnet_version) +class ContainerDotNetVersion(ContainerParser, DotNetVersion): + """ + Parses the output of the ``/usr/bin/dotnet --version`` command of the running + containers which are based on RHEL images. + + Sample output:: + + 3.1.108 + + Examples: + >>> type(con_dotnet_ver) + + >>> con_dotnet_ver.container_id + 'cc2883a1a369' + >>> con_dotnet_ver.image + 'quay.io/rhel8' + >>> con_dotnet_ver.engine + 'podman' + >>> con_dotnet_ver.major + 3 + >>> con_dotnet_ver.minor + 1 + >>> con_dotnet_ver.raw + '3.1.108' + """ + + pass diff --git a/insights/specs/__init__.py b/insights/specs/__init__.py index 21ae94d7e2..4941fd5fde 100644 --- a/insights/specs/__init__.py +++ b/insights/specs/__init__.py @@ -790,6 +790,7 @@ class Specs(SpecSet): zipl_conf = RegistryPoint() # container_specs + container_dotnet_version = RegistryPoint(multi_output=True) 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 8df436d858..3b1e349f88 100644 --- a/insights/specs/default.py +++ b/insights/specs/default.py @@ -673,6 +673,7 @@ class DefaultSpecs(Specs): zipl_conf = simple_file("/etc/zipl.conf") # Container collection specs + container_dotnet_version = container_execute(running_rhel_containers, "/usr/bin/dotnet --version") container_installed_rpms = container_execute(running_rhel_containers, "rpm -qa --qf '%s'" % _rpm_format, context=HostContext, signum=signal.SIGTERM) container_nginx_conf = container_collect(container_nginx_conf_ds) container_redhat_release = container_collect(running_rhel_containers, "/etc/redhat-release") diff --git a/insights/tests/parsers/test_dotnet.py b/insights/tests/parsers/test_dotnet.py index 0afefe1b9f..f6044c39f0 100644 --- a/insights/tests/parsers/test_dotnet.py +++ b/insights/tests/parsers/test_dotnet.py @@ -3,7 +3,7 @@ from insights.parsers import dotnet from insights.core.plugins import ContentException from insights.parsers import SkipException, ParseException -from insights.parsers.dotnet import DotNetVersion +from insights.parsers.dotnet import DotNetVersion, ContainerDotNetVersion from insights.tests import context_wrap dotnet_version_1 = "3.1.108" @@ -45,9 +45,47 @@ def test_dotnet_version_ab(): assert ret is None +def test_container_dotnet_version(): + ret = ContainerDotNetVersion( + context_wrap( + dotnet_version_1, + container_id='cc2883a1a369', + image='quay.io/rhel8', + engine='podman' + ) + ) + assert ret.major == 3 + assert ret.minor == 1 + assert ret.raw == dotnet_version_1 + assert ret.image == "quay.io/rhel8" + assert ret.engine == "podman" + assert ret.container_id == "cc2883a1a369" + + +def test_container_dotnet_version_error(): + with pytest.raises(ContentException): + ret = ContainerDotNetVersion( + context_wrap( + dotnet_version_3, + container_id='cc2883a1a369', + image='quay.io/rhel8', + engine='podman' + ) + ) + assert ret is None + + def test_doc_examples(): env = { - 'dotnet_ver': DotNetVersion(context_wrap(dotnet_version_1)) + 'dotnet_ver': DotNetVersion(context_wrap(dotnet_version_1)), + 'con_dotnet_ver': ContainerDotNetVersion( + context_wrap( + dotnet_version_1, + container_id='cc2883a1a369', + image='quay.io/rhel8', + engine='podman' + ) + ) } failed, total = doctest.testmod(dotnet, globs=env) assert failed == 0