-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add spec and parser for 'crictl_logs' (#3345)
* 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
Showing
5 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.. automodule:: insights.parsers.crictl_logs | ||
:members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters