implement --timeout flag for docker-compose down

Fix #3370

Signed-off-by: Madeline Stager <stager.madeline@gmail.com>
This commit is contained in:
Madeline Stager 2017-11-22 16:21:47 -06:00 committed by Joffrey F
parent 76e9076cb7
commit 6b0138d70f
3 changed files with 27 additions and 3 deletions

View File

@ -371,9 +371,12 @@ class TopLevelCommand(object):
attached to containers. attached to containers.
--remove-orphans Remove containers for services not defined in the --remove-orphans Remove containers for services not defined in the
Compose file Compose file
-t, --timeout TIMEOUT Specify a shutdown timeout in seconds.
(default: 10)
""" """
image_type = image_type_from_opt('--rmi', options['--rmi']) 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): def events(self, options):
""" """

View File

@ -330,8 +330,8 @@ class Project(object):
service_names, stopped=True, one_off=one_off service_names, stopped=True, one_off=one_off
), options) ), options)
def down(self, remove_image_type, include_volumes, remove_orphans=False): def down(self, remove_image_type, include_volumes, remove_orphans=False, timeout=None):
self.stop(one_off=OneOffFilter.include) self.stop(one_off=OneOffFilter.include, timeout=timeout)
self.find_orphan_containers(remove_orphans) self.find_orphan_containers(remove_orphans)
self.remove_stopped(v=include_volumes, one_off=OneOffFilter.include) self.remove_stopped(v=include_volumes, one_off=OneOffFilter.include)

View File

@ -794,6 +794,27 @@ class CLITestCase(DockerClientTestCase):
assert 'Removing network v2full_default' in result.stderr assert 'Removing network v2full_default' in result.stderr
assert 'Removing network v2full_front' 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): def test_up_detached(self):
self.dispatch(['up', '-d']) self.dispatch(['up', '-d'])
service = self.project.get_service('simple') service = self.project.get_service('simple')