summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAbhijeet Kasurde <akasurde@redhat.com>2022-03-21 19:15:45 +0530
committerGitHub <noreply@github.com>2022-03-21 08:45:45 -0500
commit1100289a45e5b5444bc5af59052fc2d63452eff6 (patch)
tree2e42856fdc2f3b23f5ff57f4ee463273ea0c16b5 /test
parent68b5db328fd4ccfe84e221fb404c12ed6d27afc5 (diff)
downloadansible-1100289a45e5b5444bc5af59052fc2d63452eff6.tar.gz
docker_util: Handle error in JSON parsing (#77298)
While getting hostname from container, podman command fails to return JSON so wrap exception and return hostname as 'None' Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Diffstat (limited to 'test')
-rw-r--r--test/lib/ansible_test/_internal/docker_util.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/test/lib/ansible_test/_internal/docker_util.py b/test/lib/ansible_test/_internal/docker_util.py
index 1e10f5ff58..1250907677 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