diff options
author | Gonéri Le Bouder <goneri@lebouder.net> | 2021-03-07 23:41:43 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-07 22:41:43 -0600 |
commit | cf53554cf58def991c71862ae853c65d9d0da34c (patch) | |
tree | ae3f414560271a1478f6c02f3ab5ea4c292f5d15 /test/lib/ansible_test | |
parent | 462edf003ef6954a9b5dc58cbb793e3d7bab2116 (diff) | |
download | ansible-cf53554cf58def991c71862ae853c65d9d0da34c.tar.gz |
[ansible-test] attempt to work around podman (#72096) (#73570)
Change:
- podman > 2 && < 2.2 does not support "images --format {{json .}}"
- podman also now outputs images JSON differently than docker
- Work around both of the above.
Test Plan:
- Tested with podman 2.0.6 in Fedora 31.
Signed-off-by: Rick Elrod <rick@elrod.me>
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
(cherry picked from commit 03320466995a91f8a4d311e66cdf3eaee3f44934)
Diffstat (limited to 'test/lib/ansible_test')
-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 a34d8d4dbd..047dec9f1b 100644 --- a/test/lib/ansible_test/_internal/docker_util.py +++ b/test/lib/ansible_test/_internal/docker_util.py @@ -264,11 +264,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): |