Blame SOURCES/sos-bz2097674-openshift-ovn-disabled.patch

4b82b4
From c2e66fa4dae51f03c7310ba5278897ddecac1aad Mon Sep 17 00:00:00 2001
4b82b4
From: Nadia Pinaeva <npinaeva@redhat.com>
4b82b4
Date: Thu, 2 Jun 2022 15:43:09 +0200
4b82b4
Subject: [PATCH] crio: switch from parsing output in table format to json
4b82b4
4b82b4
Signed-off-by: Nadia Pinaeva <npinaeva@redhat.com>
4b82b4
---
4b82b4
 sos/policies/runtimes/crio.py | 30 ++++++++++++++++++++----------
4b82b4
 1 file changed, 20 insertions(+), 10 deletions(-)
4b82b4
4b82b4
diff --git a/sos/policies/runtimes/crio.py b/sos/policies/runtimes/crio.py
4b82b4
index 55082d07..4cae1ecc 100644
4b82b4
--- a/sos/policies/runtimes/crio.py
4b82b4
+++ b/sos/policies/runtimes/crio.py
4b82b4
@@ -7,6 +7,7 @@
4b82b4
 # version 2 of the GNU General Public License.
4b82b4
 #
4b82b4
 # See the LICENSE file in the source distribution for further information.
4b82b4
+import json
4b82b4
 
4b82b4
 from sos.policies.runtimes import ContainerRuntime
4b82b4
 from sos.utilities import sos_get_command_output
4b82b4
@@ -29,14 +30,15 @@ class CrioContainerRuntime(ContainerRuntime):
4b82b4
         :type get_all: ``bool``
4b82b4
         """
4b82b4
         containers = []
4b82b4
-        _cmd = "%s ps %s" % (self.binary, '-a' if get_all else '')
4b82b4
+        _cmd = "%s ps %s -o json" % (self.binary, '-a' if get_all else '')
4b82b4
         if self.active:
4b82b4
             out = sos_get_command_output(_cmd, chroot=self.policy.sysroot)
4b82b4
-            if out['status'] == 0:
4b82b4
-                for ent in out['output'].splitlines()[1:]:
4b82b4
-                    ent = ent.split()
4b82b4
+            if out["status"] == 0:
4b82b4
+                out_json = json.loads(out["output"])
4b82b4
+                for container in out_json["containers"]:
4b82b4
                     # takes the form (container_id, container_name)
4b82b4
-                    containers.append((ent[0], ent[-3]))
4b82b4
+                    containers.append(
4b82b4
+                        (container["id"], container["metadata"]["name"]))
4b82b4
         return containers
4b82b4
 
4b82b4
     def get_images(self):
4b82b4
@@ -47,13 +49,21 @@ class CrioContainerRuntime(ContainerRuntime):
4b82b4
         """
4b82b4
         images = []
4b82b4
         if self.active:
4b82b4
-            out = sos_get_command_output("%s images" % self.binary,
4b82b4
+            out = sos_get_command_output("%s images -o json" % self.binary,
4b82b4
                                          chroot=self.policy.sysroot)
4b82b4
             if out['status'] == 0:
4b82b4
-                for ent in out['output'].splitlines():
4b82b4
-                    ent = ent.split()
4b82b4
-                    # takes the form (image_name, image_id)
4b82b4
-                    images.append((ent[0] + ':' + ent[1], ent[2]))
4b82b4
+                out_json = json.loads(out["output"])
4b82b4
+                for image in out_json["images"]:
4b82b4
+                    # takes the form (repository:tag, image_id)
4b82b4
+                    if len(image["repoTags"]) > 0:
4b82b4
+                        for repo_tag in image["repoTags"]:
4b82b4
+                            images.append((repo_tag, image["id"]))
4b82b4
+                    else:
4b82b4
+                        if len(image["repoDigests"]) == 0:
4b82b4
+                            image_name = "<none>"
4b82b4
+                        else:
4b82b4
+                            image_name = image["repoDigests"][0].split("@")[0]
4b82b4
+                        images.append((image_name + ":<none>", image["id"]))
4b82b4
         return images
4b82b4
 
4b82b4
     def fmt_container_cmd(self, container, cmd, quotecmd):
4b82b4
-- 
4b82b4
2.34.3
4b82b4