Skip to content

Commit

Permalink
Add logs to DeadDockerContainerException message + raise NotADirector…
Browse files Browse the repository at this point in the history
…yError when input dir does not exist

Refs #50
  • Loading branch information
sverhoeven committed Jan 27, 2020
1 parent ecedb40 commit eabae8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion grpc4bmi/bmi_client_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def __init__(self, image, image_port=55555, host=None,
self.input_dir = None
if input_dir is not None:
self.input_dir = os.path.abspath(input_dir)
if not os.path.isdir(self.input_dir):
raise NotADirectoryError(input_dir)
volumes[self.input_dir] = {"bind": BmiClientDocker.input_mount_point, "mode": "rw"}
self.output_dir = None
if output_dir is not None:
Expand All @@ -99,7 +101,7 @@ def __init__(self, image, image_port=55555, host=None,
if self.container.status == 'exited':
exitcode = self.container.attrs["State"]["ExitCode"]
logs = self.container.logs()
msg = f'Failed to start Docker container with image {image}'
msg = f'Failed to start Docker container with image {image}, Container log: {logs}'
raise DeadDockerContainerException(msg, exitcode, logs)

super(BmiClientDocker, self).__init__(BmiClient.create_grpc_channel(port=port, host=host))
Expand Down
6 changes: 6 additions & 0 deletions test/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def test_logs(self, walrus_model):
lg = walrus_model.logs()
assert b"Loading required package:" in lg

def test_inputdir_absent(self, tmp_path):
dirthatdoesnotexist = 'dirthatdoesnotexist'
input_dir = tmp_path / dirthatdoesnotexist
with pytest.raises(NotADirectoryError, match=dirthatdoesnotexist):
BmiClientDocker(image=walrus_docker_image, image_port=55555, input_dir=str(input_dir))

def test_container_start_failure(self, exit_container):
expected = r"Failed to start Docker container with image"
with pytest.raises(DeadDockerContainerException, match=expected) as excinfo:
Expand Down

0 comments on commit eabae8e

Please sign in to comment.