mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-07-22 02:03:01 +02:00
raise ValueError if json decode fails when getting the container ip
This commit is contained in:
@@ -64,7 +64,10 @@ def get_ip_from_container(container):
|
||||
logger.debug(f"Could not find container '{container}' with engine '{engine}'")
|
||||
continue # Container does not exist
|
||||
|
||||
network_data = json.loads(output.strip())
|
||||
try:
|
||||
network_data = json.loads(output.strip())
|
||||
except json.JSONDecodeError as e:
|
||||
raise ValueError(f'Could not decode JSON output from {engine}') from e
|
||||
main_ip = network_data.get('IPAddress')
|
||||
if main_ip:
|
||||
return main_ip
|
||||
|
||||
@@ -91,3 +91,13 @@ def test_get_container_ip_container_no_network():
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
config.get_ip_from_container('yolo')
|
||||
assert 'Could not determine ip address for container' in str(exc_info.value)
|
||||
|
||||
|
||||
def test_get_container_ip_broken_output():
|
||||
flexmock(config.shutil).should_receive('which').and_return(None).and_return('/usr/bin/podman')
|
||||
|
||||
flexmock(config).should_receive('execute_command_and_capture_output').and_return('abc')
|
||||
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
config.get_ip_from_container('yolo')
|
||||
assert 'Could not decode JSON output' in str(exc_info.value)
|
||||
|
||||
Reference in New Issue
Block a user