From 3b81e49c66cd20668478d54f291616b7db62f2b7 Mon Sep 17 00:00:00 2001 From: Madeline Stager Date: Wed, 22 Nov 2017 16:21:47 -0600 Subject: [PATCH] implement --timeout flag for docker-compose down Fix #3370 Signed-off-by: Madeline Stager --- compose/cli/main.py | 5 ++++- compose/project.py | 4 ++-- tests/acceptance/cli_test.py | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/compose/cli/main.py b/compose/cli/main.py index c3e30919d..f866d5809 100644 --- a/compose/cli/main.py +++ b/compose/cli/main.py @@ -371,9 +371,12 @@ class TopLevelCommand(object): attached to containers. --remove-orphans Remove containers for services not defined in the Compose file + -t, --timeout TIMEOUT Specify a shutdown timeout in seconds. + (default: 10) """ image_type = image_type_from_opt('--rmi', options['--rmi']) - self.project.down(image_type, options['--volumes'], options['--remove-orphans']) + timeout = timeout_from_opts(options) + self.project.down(image_type, options['--volumes'], options['--remove-orphans'], timeout=timeout) def events(self, options): """ diff --git a/compose/project.py b/compose/project.py index f6bd30a88..9cc726e42 100644 --- a/compose/project.py +++ b/compose/project.py @@ -330,8 +330,8 @@ class Project(object): service_names, stopped=True, one_off=one_off ), options) - def down(self, remove_image_type, include_volumes, remove_orphans=False): - self.stop(one_off=OneOffFilter.include) + def down(self, remove_image_type, include_volumes, remove_orphans=False, timeout=None): + self.stop(one_off=OneOffFilter.include, timeout=timeout) self.find_orphan_containers(remove_orphans) self.remove_stopped(v=include_volumes, one_off=OneOffFilter.include) diff --git a/tests/acceptance/cli_test.py b/tests/acceptance/cli_test.py index 8468dfbde..91fdb9c2f 100644 --- a/tests/acceptance/cli_test.py +++ b/tests/acceptance/cli_test.py @@ -776,6 +776,27 @@ class CLITestCase(DockerClientTestCase): assert 'Removing network v2full_default' in result.stderr assert 'Removing network v2full_front' in result.stderr + def test_down_timeout(self): + self.dispatch(['up', '-d'], None) + service = self.project.get_service('simple') + self.assertEqual(len(service.containers()), 1) + self.assertTrue(service.containers()[0].is_running) + "" + + self.dispatch(['down', '-t', '1'], None) + + self.assertEqual(len(service.containers(stopped=True)), 0) + + def test_down_signal(self): + self.base_dir = 'tests/fixtures/stop-signal-composefile' + self.dispatch(['up', '-d'], None) + service = self.project.get_service('simple') + self.assertEqual(len(service.containers()), 1) + self.assertTrue(service.containers()[0].is_running) + + self.dispatch(['down', '-t', '1'], None) + self.assertEqual(len(service.containers(stopped=True)), 0) + def test_up_detached(self): self.dispatch(['up', '-d']) service = self.project.get_service('simple')