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>
pull/77327/head
Abhijeet Kasurde 3 years ago committed by GitHub
parent 68b5db328f
commit 1100289a45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
---
minor_changes:
- ansible-test - handle JSON decode error gracefully in podman environment.

@ -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 --format was added in podman 3.3.0, this functionality depends on it's availability
""" """
hostname = None
try: try:
stdout = raw_command(['podman', 'system', 'connection', 'list', '--format=json'], capture=True)[0] stdout = raw_command(['podman', 'system', 'connection', 'list', '--format=json'], capture=True)[0]
except SubprocessError: except SubprocessError:
stdout = '[]' stdout = '[]'
connections = json.loads(stdout) try:
connections = json.loads(stdout)
except json.decoder.JSONDecodeError:
return hostname
for connection in connections: for connection in connections:
# A trailing indicates the default # A trailing indicates the default
if connection['Name'][-1] == '*': if connection['Name'][-1] == '*':
hostname = connection['URI'] hostname = connection['URI']
break break
else:
hostname = None
return hostname return hostname

Loading…
Cancel
Save