Skip to content

Commit

Permalink
podman pod info: handle return being list in Podman 5
Browse files Browse the repository at this point in the history
Fixes #712

Podman 5 changed the output of `podman pod info` (when run on a
single pod) from being a dict to being a list of dicts:

containers/podman#21514

this should handle both ways. Unfortunately not sure how to add
a test for this as I can't see a unit test that mocks the output
of the command, only the integration test that gets real live
output, and I'm not sure how to get that test run with Podman 5.

Signed-off-by: Adam Williamson <[email protected]>
  • Loading branch information
AdamWill committed Feb 16, 2024
1 parent efbfba7 commit bba2d99
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion plugins/module_utils/podman/podman_pod_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,16 @@ def get_info(self):
# pylint: disable=unused-variable
rc, out, err = self.module.run_command(
[self.module_params['executable'], b'pod', b'inspect', self.name])
return json.loads(out) if rc == 0 else {}
if rc == 0:
info = json.loads(out)
# from podman 5 onwards, this is a list of dicts,
# before it was just a single dict when querying
# a single pod
if isinstance(info, list):
return info[0]
else:
return info
return {}

def get_ps(self):
"""Inspect pod process and gather info about it."""
Expand Down

0 comments on commit bba2d99

Please sign in to comment.