From bcbeed244bbb6c3e3f0dba9c816866257d1e25e5 Mon Sep 17 00:00:00 2001 From: shaung <_@shaung.org> Date: Tue, 23 Aug 2016 16:03:16 +0800 Subject: [PATCH] Fix #4504 Respect timeout option when starting/stopping/restarting containers. --- lib/ansible/modules/cloud/docker/docker_service.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/cloud/docker/docker_service.py b/lib/ansible/modules/cloud/docker/docker_service.py index db4352c9306..3e7d4335813 100644 --- a/lib/ansible/modules/cloud/docker/docker_service.py +++ b/lib/ansible/modules/cloud/docker/docker_service.py @@ -466,9 +466,11 @@ try: from compose.cli.command import project_from_options from compose.service import ConvergenceStrategy from compose.cli.main import convergence_strategy_from_opts, build_action_from_opts, image_type_from_opt + from compose.const import DEFAULT_TIMEOUT except ImportError as exc: HAS_COMPOSE = False HAS_COMPOSE_EXC = str(exc) + DEFAULT_TIMEOUT = 10 from ansible.module_utils.docker_common import * @@ -653,7 +655,8 @@ class ContainerManager(DockerBaseClass): strategy=converge, do_build=do_build, detached=detached, - remove_orphans=self.remove_orphans) + remove_orphans=self.remove_orphans, + timeout=self.timeout) except Exception as exc: self.client.fail("Error starting project - %s" % str(exc)) @@ -828,7 +831,7 @@ class ContainerManager(DockerBaseClass): if not self.check_mode and result['changed']: try: - self.project.stop(service_names=service_names) + self.project.stop(service_names=service_names, timeout=self.timeout) except Exception as exc: self.client.fail("Error stopping services for %s - %s" % (self.project.name, str(exc))) @@ -855,7 +858,7 @@ class ContainerManager(DockerBaseClass): if not self.check_mode and result['changed']: try: - self.project.restart(service_names=service_names) + self.project.restart(service_names=service_names, timeout=self.timeout) except Exception as exc: self.client.fail("Error restarting services for %s - %s" % (self.project.name, str(exc))) @@ -903,7 +906,8 @@ def main(): dependencies=dict(type='bool', default=True), pull=dict(type='bool', default=False), nocache=dict(type='bool', default=False), - debug=dict(type='bool', default=False) + debug=dict(type='bool', default=False), + timeout=dict(type='int', default=DEFAULT_TIMEOUT) ) mutually_exclusive = [