mirror of https://github.com/docker/compose.git
Properly handle APIError failures in Project.up
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
c41f30c3ff
commit
310b3d9441
|
@ -24,6 +24,7 @@ from ..const import IS_WINDOWS_PLATFORM
|
|||
from ..progress_stream import StreamOutputError
|
||||
from ..project import NoSuchService
|
||||
from ..project import OneOffFilter
|
||||
from ..project import ProjectError
|
||||
from ..service import BuildAction
|
||||
from ..service import BuildError
|
||||
from ..service import ConvergenceStrategy
|
||||
|
@ -58,7 +59,7 @@ def main():
|
|||
except (KeyboardInterrupt, signals.ShutdownException):
|
||||
log.error("Aborting.")
|
||||
sys.exit(1)
|
||||
except (UserError, NoSuchService, ConfigurationError) as e:
|
||||
except (UserError, NoSuchService, ConfigurationError, ProjectError) as e:
|
||||
log.error(e.msg)
|
||||
sys.exit(1)
|
||||
except BuildError as e:
|
||||
|
|
|
@ -59,7 +59,7 @@ def parallel_execute(objects, func, get_name, msg, get_deps=None):
|
|||
if error_to_reraise:
|
||||
raise error_to_reraise
|
||||
|
||||
return results
|
||||
return results, errors
|
||||
|
||||
|
||||
def _no_deps(x):
|
||||
|
|
|
@ -390,13 +390,18 @@ class Project(object):
|
|||
def get_deps(service):
|
||||
return {self.get_service(dep) for dep in service.get_dependency_names()}
|
||||
|
||||
results = parallel.parallel_execute(
|
||||
results, errors = parallel.parallel_execute(
|
||||
services,
|
||||
do,
|
||||
operator.attrgetter('name'),
|
||||
None,
|
||||
get_deps
|
||||
)
|
||||
if errors:
|
||||
raise ProjectError(
|
||||
'Encountered errors while bringing up the project.'
|
||||
)
|
||||
|
||||
return [
|
||||
container
|
||||
for svc_containers in results
|
||||
|
@ -531,3 +536,7 @@ class NoSuchService(Exception):
|
|||
|
||||
def __str__(self):
|
||||
return self.msg
|
||||
|
||||
|
||||
class ProjectError(Exception):
|
||||
pass
|
||||
|
|
|
@ -19,6 +19,7 @@ from compose.const import LABEL_PROJECT
|
|||
from compose.const import LABEL_SERVICE
|
||||
from compose.container import Container
|
||||
from compose.project import Project
|
||||
from compose.project import ProjectError
|
||||
from compose.service import ConvergenceStrategy
|
||||
from tests.integration.testcases import v2_only
|
||||
|
||||
|
@ -752,7 +753,8 @@ class ProjectTest(DockerClientTestCase):
|
|||
config_data=config_data,
|
||||
)
|
||||
|
||||
assert len(project.up()) == 0
|
||||
with self.assertRaises(ProjectError):
|
||||
project.up()
|
||||
|
||||
@v2_only()
|
||||
def test_project_up_volumes(self):
|
||||
|
|
|
@ -29,7 +29,7 @@ def get_deps(obj):
|
|||
|
||||
|
||||
def test_parallel_execute():
|
||||
results = parallel_execute(
|
||||
results, errors = parallel_execute(
|
||||
objects=[1, 2, 3, 4, 5],
|
||||
func=lambda x: x * 2,
|
||||
get_name=six.text_type,
|
||||
|
@ -37,6 +37,7 @@ def test_parallel_execute():
|
|||
)
|
||||
|
||||
assert sorted(results) == [2, 4, 6, 8, 10]
|
||||
assert errors == {}
|
||||
|
||||
|
||||
def test_parallel_execute_with_deps():
|
||||
|
|
Loading…
Reference in New Issue