Skip to content

Commit

Permalink
docker_util: Handle error in JSON parsing (#77298)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Akasurde committed Mar 21, 2022
1 parent 68b5db3 commit 1100289
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/ansible_test.yml
@@ -0,0 +1,3 @@
---
minor_changes:
- ansible-test - handle JSON decode error gracefully in podman environment.
8 changes: 5 additions & 3 deletions test/lib/ansible_test/_internal/docker_util.py
Expand Up @@ -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

Expand Down

0 comments on commit 1100289

Please sign in to comment.