From d5e8ed5685f610c7a4f91af1077d367e153bb2be Mon Sep 17 00:00:00 2001
From: shlao <shlao@redhat.com>
Date: Mon, 28 Feb 2022 15:47:26 +0800
Subject: [PATCH 1/6] Feat: Add spec and parser for 'crictl_logs'

Signed-off-by: shlao <shlao@redhat.com>
---
 docs/shared_parsers_catalog/crictl_logs.rst |  3 +++
 insights/parsers/crictl_logs.py             | 30 +++++++++++++++++++++
 insights/parsers/tests/test_crictl_logs.py  | 28 +++++++++++++++++++
 insights/specs/__init__.py                  |  1 +
 insights/specs/sos_archive.py               |  1 +
 5 files changed, 63 insertions(+)
 create mode 100644 docs/shared_parsers_catalog/crictl_logs.rst
 create mode 100644 insights/parsers/crictl_logs.py
 create mode 100644 insights/parsers/tests/test_crictl_logs.py

diff --git a/docs/shared_parsers_catalog/crictl_logs.rst b/docs/shared_parsers_catalog/crictl_logs.rst
new file mode 100644
index 0000000000..68a8466194
--- /dev/null
+++ b/docs/shared_parsers_catalog/crictl_logs.rst
@@ -0,0 +1,3 @@
+.. automodule:: insights.parsers.crictl_logs
+   :members:
+   :show-inheritance:
diff --git a/insights/parsers/crictl_logs.py b/insights/parsers/crictl_logs.py
new file mode 100644
index 0000000000..843f6179f4
--- /dev/null
+++ b/insights/parsers/crictl_logs.py
@@ -0,0 +1,30 @@
+"""
+CrictlLogs - files ``sos_commands/crio/containers/crictl_logs_-t*``
+===================================================================
+"""
+
+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 ``sos_commands/crio/containers/crictl_logs_-t*`` files.
+
+    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
diff --git a/insights/parsers/tests/test_crictl_logs.py b/insights/parsers/tests/test_crictl_logs.py
new file mode 100644
index 0000000000..1dd752efda
--- /dev/null
+++ b/insights/parsers/tests/test_crictl_logs.py
@@ -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
diff --git a/insights/specs/__init__.py b/insights/specs/__init__.py
index 71d90538ac..96fb860e41 100644
--- a/insights/specs/__init__.py
+++ b/insights/specs/__init__.py
@@ -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()
diff --git a/insights/specs/sos_archive.py b/insights/specs/sos_archive.py
index 479d27bc0a..b7ecb8a6f7 100644
--- a/insights/specs/sos_archive.py
+++ b/insights/specs/sos_archive.py
@@ -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"])

From 5ee97fb58b1cc060a663dedfa11ffb8673a5dfee Mon Sep 17 00:00:00 2001
From: shlao <shlao@redhat.com>
Date: Mon, 28 Feb 2022 17:18:03 +0800
Subject: [PATCH 2/6] Updated the 'CrictlLogs' docstring

Signed-off-by: shlao <shlao@redhat.com>
---
 insights/parsers/crictl_logs.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/insights/parsers/crictl_logs.py b/insights/parsers/crictl_logs.py
index 843f6179f4..8b503a41b3 100644
--- a/insights/parsers/crictl_logs.py
+++ b/insights/parsers/crictl_logs.py
@@ -1,6 +1,6 @@
 """
-CrictlLogs - files ``sos_commands/crio/containers/crictl_logs_-t*``
-===================================================================
+CrictlLogs - files ``/usr/bin/crictl logs -t <list_of_containers'_id>``
+=======================================================================
 """
 
 from insights.core import LogFileOutput
@@ -11,7 +11,7 @@
 @parser(Specs.crictl_logs)
 class CrictlLogs(LogFileOutput):
     """
-    Class for parsing ``sos_commands/crio/containers/crictl_logs_-t*`` files.
+    Class for parsing ``/usr/bin/crictl logs -t <list_of_containers'_id>`` files.
 
     Sample input data looks like::
 

From d503a4a8a8e9dac86fd8fd01cbb46493c43d6d4e Mon Sep 17 00:00:00 2001
From: shlao <shlao@redhat.com>
Date: Mon, 28 Feb 2022 17:20:48 +0800
Subject: [PATCH 3/6] Used the Plurals

Signed-off-by: shlao <shlao@redhat.com>
---
 insights/parsers/crictl_logs.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/insights/parsers/crictl_logs.py b/insights/parsers/crictl_logs.py
index 8b503a41b3..b0de1ca506 100644
--- a/insights/parsers/crictl_logs.py
+++ b/insights/parsers/crictl_logs.py
@@ -1,5 +1,5 @@
 """
-CrictlLogs - files ``/usr/bin/crictl logs -t <list_of_containers'_id>``
+CrictlLogs - files ``/usr/bin/crictl logs -t <list_of_containers'_IDs>``
 =======================================================================
 """
 
@@ -11,7 +11,7 @@
 @parser(Specs.crictl_logs)
 class CrictlLogs(LogFileOutput):
     """
-    Class for parsing ``/usr/bin/crictl logs -t <list_of_containers'_id>`` files.
+    Class for parsing ``/usr/bin/crictl logs -t <list_of_containers'_IDs>`` files.
 
     Sample input data looks like::
 

From 6724e7af3a15720398b40a7d9fe2e317ceade34b Mon Sep 17 00:00:00 2001
From: shlao <shlao@redhat.com>
Date: Mon, 28 Feb 2022 19:08:33 +0800
Subject: [PATCH 4/6] Updated the docstring

Signed-off-by: shlao <shlao@redhat.com>
---
 insights/parsers/crictl_logs.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/insights/parsers/crictl_logs.py b/insights/parsers/crictl_logs.py
index b0de1ca506..c4e02cc352 100644
--- a/insights/parsers/crictl_logs.py
+++ b/insights/parsers/crictl_logs.py
@@ -1,6 +1,6 @@
 """
-CrictlLogs - files ``/usr/bin/crictl logs -t <list_of_containers'_IDs>``
-=======================================================================
+CrictlLogs - command ``/usr/bin/crictl logs -t <list_of_containers'_IDs>``
+==========================================================================
 """
 
 from insights.core import LogFileOutput
@@ -11,7 +11,7 @@
 @parser(Specs.crictl_logs)
 class CrictlLogs(LogFileOutput):
     """
-    Class for parsing ``/usr/bin/crictl logs -t <list_of_containers'_IDs>`` files.
+    Class for parsing the output of command ``/usr/bin/crictl logs -t <list_of_containers'_IDs>``.
 
     Sample input data looks like::
 

From d11a3d46025e039c0b6b3908f3997ada627b3028 Mon Sep 17 00:00:00 2001
From: shlao <shlao@redhat.com>
Date: Mon, 28 Feb 2022 19:23:42 +0800
Subject: [PATCH 5/6] Use the singular form

Signed-off-by: shlao <shlao@redhat.com>
---
 insights/parsers/crictl_logs.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/insights/parsers/crictl_logs.py b/insights/parsers/crictl_logs.py
index c4e02cc352..13dfedab04 100644
--- a/insights/parsers/crictl_logs.py
+++ b/insights/parsers/crictl_logs.py
@@ -1,6 +1,6 @@
 """
-CrictlLogs - command ``/usr/bin/crictl logs -t <list_of_containers'_IDs>``
-==========================================================================
+CrictlLogs - command ``/usr/bin/crictl logs -t <container's_ID>``
+=================================================================
 """
 
 from insights.core import LogFileOutput
@@ -11,7 +11,7 @@
 @parser(Specs.crictl_logs)
 class CrictlLogs(LogFileOutput):
     """
-    Class for parsing the output of command ``/usr/bin/crictl logs -t <list_of_containers'_IDs>``.
+    Class for parsing the output of command ``/usr/bin/crictl logs -t <container's_ID>``.
 
     Sample input data looks like::
 

From cd7f8c1ea8e96cf6d5df63bce15605f6acef6987 Mon Sep 17 00:00:00 2001
From: shlao <shlao@redhat.com>
Date: Mon, 28 Feb 2022 21:37:04 +0800
Subject: [PATCH 6/6] Updated the docstring

Signed-off-by: shlao <shlao@redhat.com>
---
 insights/parsers/crictl_logs.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/insights/parsers/crictl_logs.py b/insights/parsers/crictl_logs.py
index 13dfedab04..823a8696ae 100644
--- a/insights/parsers/crictl_logs.py
+++ b/insights/parsers/crictl_logs.py
@@ -1,6 +1,6 @@
 """
-CrictlLogs - command ``/usr/bin/crictl logs -t <container's_ID>``
-=================================================================
+CrictlLogs - commands `crictl logs -t <container's_ID>``
+========================================================
 """
 
 from insights.core import LogFileOutput
@@ -11,7 +11,7 @@
 @parser(Specs.crictl_logs)
 class CrictlLogs(LogFileOutput):
     """
-    Class for parsing the output of command ``/usr/bin/crictl logs -t <container's_ID>``.
+    Class for parsing the output of commands ``crictl logs -t <container's_ID>``.
 
     Sample input data looks like::