exit and show clean error message (no log) if docker connection fails

pull/779/head
Daniel Nüst 2019-09-07 12:07:34 +02:00
rodzic c8cd3269c0
commit b3f82db558
3 zmienionych plików z 15 dodań i 11 usunięć

Wyświetl plik

@ -612,9 +612,10 @@ class Repo2Docker(Application):
docker_client = docker.APIClient(version="auto", **kwargs_from_env())
except DockerException as e:
self.log.error(
"\nDocker client initialization error. Check if docker is running on the host.\n\n"
"\nDocker client initialization error: %s.\nCheck if docker is running on the host.\n",
e,
)
raise
self.exit(1)
# If the source to be executed is a directory, continue using the
# directory. In the case of a local directory, it is used as both the

Wyświetl plik

@ -127,22 +127,23 @@ def test_root_not_allowed():
builds.assert_called_once()
def test_dryrun_works_without_docker(tmpdir):
def test_dryrun_works_without_docker(tmpdir, capsys):
with chdir(tmpdir):
with patch.object(docker, "APIClient") as client:
client.side_effect = docker.errors.DockerException("Error: no Docker")
app = Repo2Docker(dry_run=True)
app.build()
captured = capsys.readouterr()
assert "Error: no Docker" not in captured.err
def test_error_log_without_docker(tmpdir, caplog):
def test_error_log_without_docker(tmpdir, capsys):
with chdir(tmpdir):
with patch.object(docker, "APIClient") as client:
client.side_effect = docker.errors.DockerException("Error: no Docker")
app = Repo2Docker()
with pytest.raises(docker.errors.DockerException):
with pytest.raises(SystemExit):
app.build()
captured = capsys.readouterr()
assert "Check if docker is running" in captured.err
assert "Error: no Docker" in captured.err

Wyświetl plik

@ -223,7 +223,6 @@ def test_invalid_container_port_protocol_mapping_fail(temp_cwd):
assert not validate_arguments(builddir, args_list, "Port specification")
@pytest.mark.xfail(reason="Regression in new arg parsing")
def test_docker_handle_fail(temp_cwd):
"""
Test to check if r2d fails with minimal error message on not being able to connect to docker daemon
@ -233,19 +232,22 @@ def test_docker_handle_fail(temp_cwd):
assert not validate_arguments(
builddir,
args_list,
"Docker client initialization error. Check if docker is running on the host.",
"Check if docker is running on the host.",
disable_dockerd=True,
)
def test_docker_handle_debug_fail(temp_cwd):
"""
Test to check if r2d fails with stack trace on not being able to connect to docker daemon and debug enabled
Test to check if r2d fails with helpful error message on not being able to connect to docker daemon and debug enabled
"""
args_list = ["--debug"]
assert not validate_arguments(
builddir, args_list, "docker.errors.DockerException", disable_dockerd=True
builddir,
args_list,
"Check if docker is running on the host.",
disable_dockerd=True,
)