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: Add spec and parser for 'crictl_logs' #3345

Merged
merged 6 commits into from
Mar 2, 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
3 changes: 3 additions & 0 deletions docs/shared_parsers_catalog/crictl_logs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. automodule:: insights.parsers.crictl_logs
:members:
:show-inheritance:
30 changes: 30 additions & 0 deletions insights/parsers/crictl_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
CrictlLogs - commands `crictl logs -t <container's_ID>``
========================================================
"""

from insights.core import LogFileOutput
from insights.core.plugins import parser
from insights.specs import Specs


@parser(Specs.crictl_logs)
class CrictlLogs(LogFileOutput):
"""
Class for parsing the output of commands ``crictl logs -t <container's_ID>``.

Sample input data looks like::

2021-12-21T11:12:45.854971114+01:00 Successfully copied files in /usr/src/multus-cni/rhel7/bin/ to /host/opt/cni/bin/
2021-12-21T11:12:45.995998017+01:00 2021-12-21T10:12:45+00:00 WARN: {unknown parameter "-"}
2021-12-21T11:12:46.008998978+01:00 2021-12-21T10:12:46+00:00 Entrypoint skipped copying Multus binary.
2021-12-21T11:12:46.081427544+01:00 2021-12-21T10:12:46+00:00 Attempting to find master plugin configuration, attempt 0

Note:
Please refer to its super-class :class:`insights.core.LogFileOutput`.

Examples:
>>> len(logs.get('skipped copying Multus binary'))
1
"""
pass
28 changes: 28 additions & 0 deletions insights/parsers/tests/test_crictl_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from insights.parsers import crictl_logs
from insights.parsers.crictl_logs import CrictlLogs
from insights.tests import context_wrap
import doctest

CRICTL_LOGS = """
2021-12-21T11:12:45.854971114+01:00 Successfully copied files in /usr/src/multus-cni/rhel7/bin/ to /host/opt/cni/bin/
2021-12-21T11:12:45.995998017+01:00 2021-12-21T10:12:45+00:00 WARN: {unknown parameter "-"}
2021-12-21T11:12:46.008998978+01:00 2021-12-21T10:12:46+00:00 Entrypoint skipped copying Multus binary.
2021-12-21T11:12:46.081427544+01:00 2021-12-21T10:12:46+00:00 Attempting to find master plugin configuration, attempt 0
""".strip()


def test_crictl_logs():
logs = CrictlLogs(context_wrap(CRICTL_LOGS))
test_1 = logs.get('skipped copying Multus binary')
assert 1 == len(test_1)
test_2 = logs.get('Attempting to find master plugin configuration')
assert 1 == len(test_2)
assert test_2[0]['raw_message'] == '2021-12-21T11:12:46.081427544+01:00 2021-12-21T10:12:46+00:00 Attempting to find master plugin configuration, attempt 0'


def test_crictl_logs_documentation():
failed_count, tests = doctest.testmod(
crictl_logs,
globs={'logs': CrictlLogs(context_wrap(CRICTL_LOGS))}
)
assert failed_count == 0
1 change: 1 addition & 0 deletions insights/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class Specs(SpecSet):
cpuinfo = RegistryPoint()
cpupower_frequency_info = RegistryPoint()
cpuset_cpus = RegistryPoint()
crictl_logs = RegistryPoint(multi_output=True, filterable=True)
crio_conf = RegistryPoint(multi_output=True)
cron_daily_rhsmd = RegistryPoint(filterable=True)
crypto_policies_config = RegistryPoint()
Expand Down
1 change: 1 addition & 0 deletions insights/specs/sos_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class SosSpecs(Specs):
cpu_vulns_spec_store_bypass = simple_file("sys/devices/system/cpu/vulnerabilities/spec_store_bypass")
cpuinfo_max_freq = simple_file("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq")
cpupower_frequency_info = simple_file("sos_commands/processor/cpupower_frequency-info")
crictl_logs = glob_file("sos_commands/crio/containers/crictl_logs_-t*")
crio_conf = glob_file([r"etc/crio/crio.conf", r"etc/crio/crio.conf.d/*"])
date = first_of([simple_file("sos_commands/general/date"), simple_file("sos_commands/date/date")])
df__al = first_file(["sos_commands/filesys/df_-al", "sos_commands/filesys/df_-al_-x_autofs"])
Expand Down