From 58f2f10d49a8b46888173236277658af39971f36 Mon Sep 17 00:00:00 2001 From: Madeline Stager Date: Mon, 4 Dec 2017 20:01:00 -0600 Subject: [PATCH] Raise error if up used with both -d and --timeout Fix #5434 Signed-off-by: Madeline Stager --- compose/cli/main.py | 10 +++++++--- tests/acceptance/cli_test.py | 15 +++------------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/compose/cli/main.py b/compose/cli/main.py index f842f05c8..222f7d013 100644 --- a/compose/cli/main.py +++ b/compose/cli/main.py @@ -898,8 +898,8 @@ class TopLevelCommand(object): Options: -d Detached mode: Run containers in the background, - print new container names. - Incompatible with --abort-on-container-exit. + print new container names. Incompatible with + --abort-on-container-exit and --timeout. --no-color Produce monochrome output. --no-deps Don't start linked services. --force-recreate Recreate containers even if their configuration @@ -913,7 +913,8 @@ class TopLevelCommand(object): --abort-on-container-exit Stops all containers if any container was stopped. Incompatible with -d. -t, --timeout TIMEOUT Use this timeout in seconds for container shutdown - when attached or when containers are already + when attached or when containers are already. + Incompatible with -d. running. (default: 10) --remove-orphans Remove containers for services not defined in the Compose file @@ -934,6 +935,9 @@ class TopLevelCommand(object): if detached and (cascade_stop or exit_value_from): raise UserError("--abort-on-container-exit and -d cannot be combined.") + if detached and timeout: + raise UserError("-d and --timeout cannot be combined.") + if no_start: for excluded in ['-d', '--abort-on-container-exit', '--exit-code-from']: if options.get(excluded): diff --git a/tests/acceptance/cli_test.py b/tests/acceptance/cli_test.py index 21e716751..251e39db6 100644 --- a/tests/acceptance/cli_test.py +++ b/tests/acceptance/cli_test.py @@ -1325,18 +1325,9 @@ class CLITestCase(DockerClientTestCase): ['up', '-d', '--force-recreate', '--no-recreate'], returncode=1) - def test_up_with_timeout(self): - self.dispatch(['up', '-d', '-t', '1']) - service = self.project.get_service('simple') - another = self.project.get_service('another') - self.assertEqual(len(service.containers()), 1) - self.assertEqual(len(another.containers()), 1) - - # Ensure containers don't have stdin and stdout connected in -d mode - config = service.containers()[0].inspect()['Config'] - self.assertFalse(config['AttachStderr']) - self.assertFalse(config['AttachStdout']) - self.assertFalse(config['AttachStdin']) + def test_up_with_timeout_detached(self): + result = self.dispatch(['up', '-d', '-t', '1'], returncode=1) + assert "-d and --timeout cannot be combined." in result.stderr def test_up_handles_sigint(self): proc = start_process(self.base_dir, ['up', '-t', '2'])