diff options
Diffstat (limited to 'test/lib/ansible_test/_internal/docker_util.py')
-rw-r--r-- | test/lib/ansible_test/_internal/docker_util.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/test/lib/ansible_test/_internal/docker_util.py b/test/lib/ansible_test/_internal/docker_util.py index 54007d1c90..1b47364def 100644 --- a/test/lib/ansible_test/_internal/docker_util.py +++ b/test/lib/ansible_test/_internal/docker_util.py @@ -271,11 +271,21 @@ def docker_images(args, image): stdout, _dummy = docker_command(args, ['images', image, '--format', '{{json .}}'], capture=True, always=True) except SubprocessError as ex: if 'no such image' in ex.stderr: - stdout = '' # podman does not handle this gracefully, exits 125 + return [] # podman does not handle this gracefully, exits 125 + + if 'function "json" not defined' in ex.stderr: + # podman > 2 && < 2.2.0 breaks with --format {{json .}}, and requires --format json + # So we try this as a fallback. If it fails again, we just raise the exception and bail. + stdout, _dummy = docker_command(args, ['images', image, '--format', 'json'], capture=True, always=True) else: raise ex - results = [json.loads(line) for line in stdout.splitlines()] - return results + + if stdout.startswith('['): + # modern podman outputs a pretty-printed json list. Just load the whole thing. + return json.loads(stdout) + + # docker outputs one json object per line (jsonl) + return [json.loads(line) for line in stdout.splitlines()] def docker_rm(args, container_id): |