diff options
author | Rick Elrod <rick@elrod.me> | 2020-10-06 03:13:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-06 03:13:52 +0200 |
commit | 03320466995a91f8a4d311e66cdf3eaee3f44934 (patch) | |
tree | 65519f05415346d9148f83886d32b7104eba93e8 /test/lib | |
parent | Add explicit coverage of required_together (#72107) (diff) | |
download | ansible-03320466995a91f8a4d311e66cdf3eaee3f44934.tar.xz ansible-03320466995a91f8a4d311e66cdf3eaee3f44934.zip |
[ansible-test] attempt to work around podman (#72096)
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>
Diffstat (limited to 'test/lib')
-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 1807d063f6..dad07ba43b 100644 --- a/test/lib/ansible_test/_internal/docker_util.py +++ b/test/lib/ansible_test/_internal/docker_util.py @@ -194,11 +194,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): |