diff --git a/changelogs/fragments/ansible_test.yml b/changelogs/fragments/ansible_test.yml new file mode 100644 index 00000000000..ca4553f1826 --- /dev/null +++ b/changelogs/fragments/ansible_test.yml @@ -0,0 +1,3 @@ +--- +minor_changes: +- ansible-test - handle JSON decode error gracefully in podman environment. diff --git a/test/lib/ansible_test/_internal/docker_util.py b/test/lib/ansible_test/_internal/docker_util.py index 1e10f5ff585..12509076776 100644 --- a/test/lib/ansible_test/_internal/docker_util.py +++ b/test/lib/ansible_test/_internal/docker_util.py @@ -137,20 +137,22 @@ def get_podman_default_hostname(): # type: () -> str --format was added in podman 3.3.0, this functionality depends on it's availability """ + hostname = None try: stdout = raw_command(['podman', 'system', 'connection', 'list', '--format=json'], capture=True)[0] except SubprocessError: stdout = '[]' - connections = json.loads(stdout) + try: + connections = json.loads(stdout) + except json.decoder.JSONDecodeError: + return hostname for connection in connections: # A trailing indicates the default if connection['Name'][-1] == '*': hostname = connection['URI'] break - else: - hostname = None return hostname