cd40823
From bba2d99318ca6dbd567dadaf4be8db8a05e74b9b Mon Sep 17 00:00:00 2001
cd40823
From: Adam Williamson <awilliam@redhat.com>
cd40823
Date: Thu, 15 Feb 2024 17:25:22 -0800
cd40823
Subject: [PATCH] podman pod info: handle return being list in Podman 5
cd40823
cd40823
Fixes #712
cd40823
cd40823
Podman 5 changed the output of `podman pod info` (when run on a
cd40823
single pod) from being a dict to being a list of dicts:
cd40823
cd40823
https://github.com/containers/podman/pull/21514
cd40823
cd40823
this should handle both ways. Unfortunately not sure how to add
cd40823
a test for this as I can't see a unit test that mocks the output
cd40823
of the command, only the integration test that gets real live
cd40823
output, and I'm not sure how to get that test run with Podman 5.
cd40823
cd40823
Signed-off-by: Adam Williamson <awilliam@redhat.com>
cd40823
---
cd40823
 plugins/module_utils/podman/podman_pod_lib.py | 11 ++++++++++-
cd40823
 1 file changed, 10 insertions(+), 1 deletion(-)
cd40823
cd40823
diff --git a/plugins/module_utils/podman/podman_pod_lib.py b/plugins/module_utils/podman/podman_pod_lib.py
cd40823
index 4106136e..0ed30dbd 100644
cd40823
--- a/plugins/module_utils/podman/podman_pod_lib.py
cd40823
+++ b/plugins/module_utils/podman/podman_pod_lib.py
cd40823
@@ -658,7 +658,16 @@ def get_info(self):
cd40823
         # pylint: disable=unused-variable
cd40823
         rc, out, err = self.module.run_command(
cd40823
             [self.module_params['executable'], b'pod', b'inspect', self.name])
cd40823
-        return json.loads(out) if rc == 0 else {}
cd40823
+        if rc == 0:
cd40823
+            info = json.loads(out)
cd40823
+            # from podman 5 onwards, this is a list of dicts,
cd40823
+            # before it was just a single dict when querying
cd40823
+            # a single pod
cd40823
+            if isinstance(info, list):
cd40823
+                return info[0]
cd40823
+            else:
cd40823
+                return info
cd40823
+        return {}
cd40823
 
cd40823
     def get_ps(self):
cd40823
         """Inspect pod process and gather info about it."""