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 'dotnet --version' Command for Containers #3581

Merged
merged 6 commits into from
Nov 9, 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
38 changes: 37 additions & 1 deletion insights/parsers/dotnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
<class 'insights.parsers.dotnet.ContainerDotNetVersion'>
>>> 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
1 change: 1 addition & 0 deletions insights/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions insights/specs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
42 changes: 40 additions & 2 deletions insights/tests/parsers/test_dotnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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