Skip to content

Commit

Permalink
Handle connection errors on project initialization
Browse files Browse the repository at this point in the history
Signed-off-by: Aanand Prasad <[email protected]>
  • Loading branch information
aanand committed Aug 2, 2016
1 parent 6ce0662 commit b3a4d76
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compose/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import six

from . import errors
from . import verbose_proxy
from .. import config
from ..config.environment import Environment
Expand Down Expand Up @@ -110,7 +111,8 @@ def get_project(project_dir, config_path=None, project_name=None, verbose=False,
host=host, environment=environment
)

return Project.from_config(project_name, config_data, client)
with errors.handle_connection_errors(client):
return Project.from_config(project_name, config_data, client)


def get_project_name(working_dir, project_name=None, environment=None):
Expand Down
13 changes: 13 additions & 0 deletions tests/acceptance/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ def test_shorthand_host_opt(self):
returncode=0
)

def test_host_not_reachable(self):
result = self.dispatch(['-H=tcp://doesnotexist:8000', 'ps'], returncode=1)
assert "Couldn't connect to Docker daemon" in result.stderr

def test_host_not_reachable_volumes_from_container(self):
self.base_dir = 'tests/fixtures/volumes-from-container'

container = self.client.create_container('busybox', 'true', name='composetest_data_container')
self.addCleanup(self.client.remove_container, container)

result = self.dispatch(['-H=tcp://doesnotexist:8000', 'ps'], returncode=1)
assert "Couldn't connect to Docker daemon" in result.stderr

def test_config_list_services(self):
self.base_dir = 'tests/fixtures/v2-full'
result = self.dispatch(['config', '--services'])
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/volumes-from-container/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: "2"
services:
test:
image: busybox
volumes_from: ["container:composetest_data_container"]

0 comments on commit b3a4d76

Please sign in to comment.