Merge pull request #779 from nuest/docker_daemon_logmessage

add explicit log message on failing Docker connection
pull/784/head
Min RK 2019-09-07 14:07:03 +02:00 zatwierdzone przez GitHub
commit 8ef5faa2ab
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 36 dodań i 7 usunięć

Wyświetl plik

@ -626,8 +626,12 @@ class Repo2Docker(Application):
try:
docker_client = docker.APIClient(version="auto", **kwargs_from_env())
except DockerException as e:
self.log.exception(e)
raise
self.log.error(
"\nDocker client initialization error: %s.\nCheck if docker is running on the host.\n",
e,
)
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
# source and target. Reusing a local directory seems better than

Wyświetl plik

@ -8,6 +8,7 @@ import escapism
from repo2docker.app import Repo2Docker
from repo2docker.__main__ import make_r2d
from repo2docker.utils import chdir
def test_find_image():
@ -124,3 +125,25 @@ def test_root_not_allowed():
builds.return_value = []
app.build()
builds.assert_called_once()
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, 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(SystemExit):
app.build()
captured = capsys.readouterr()
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,
)

Wyświetl plik

@ -33,7 +33,7 @@ def test_subdir_in_image_name():
assert escaped_dirname in app.output_image_spec
def test_subdir_invalid(caplog):
def test_subdir_invalid():
# test an error is raised when requesting a non existent subdir
app = Repo2Docker(repo=TEST_REPO, subdir="invalid-sub-dir")
app.initialize()