Skip to content

Commit

Permalink
Feat: Add spec and parser for 'crictl_logs' (#3345)
Browse files Browse the repository at this point in the history
* Feat: Add spec and parser for 'crictl_logs'

Signed-off-by: shlao <[email protected]>

* Updated the 'CrictlLogs' docstring

Signed-off-by: shlao <[email protected]>

* Used the Plurals

Signed-off-by: shlao <[email protected]>

* Updated the docstring

Signed-off-by: shlao <[email protected]>

* Use the singular form

Signed-off-by: shlao <[email protected]>

* Updated the docstring

Signed-off-by: shlao <[email protected]>
(cherry picked from commit 9989332)
  • Loading branch information
shlao authored and xiangce committed Mar 2, 2022
1 parent 2bafdc4 commit 7a1e1f3
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
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

0 comments on commit 7a1e1f3

Please sign in to comment.