Return-Path: X-Original-To: apmail-aurora-commits-archive@minotaur.apache.org Delivered-To: apmail-aurora-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6B16110ABA for ; Wed, 11 Jun 2014 19:30:52 +0000 (UTC) Received: (qmail 60684 invoked by uid 500); 11 Jun 2014 19:30:52 -0000 Delivered-To: apmail-aurora-commits-archive@aurora.apache.org Received: (qmail 60648 invoked by uid 500); 11 Jun 2014 19:30:52 -0000 Mailing-List: contact commits-help@aurora.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aurora.incubator.apache.org Delivered-To: mailing list commits@aurora.incubator.apache.org Received: (qmail 60641 invoked by uid 99); 11 Jun 2014 19:30:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Jun 2014 19:30:52 +0000 X-ASF-Spam-Status: No, hits=-2000.7 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 11 Jun 2014 19:30:50 +0000 Received: (qmail 60558 invoked by uid 99); 11 Jun 2014 19:30:30 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 11 Jun 2014 19:30:30 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5A05F47264; Wed, 11 Jun 2014 19:30:30 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mchucarroll@apache.org To: commits@aurora.incubator.apache.org Message-Id: <0e64368f869a46ff8990e8dd23b787e8@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: Prevent keyboard interrupts from spewing stack dumps. Date: Wed, 11 Jun 2014 19:30:30 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org Repository: incubator-aurora Updated Branches: refs/heads/master 6feda1cc5 -> 2ed7d8d87 Prevent keyboard interrupts from spewing stack dumps. (Also, cleanup python isort failures.) Testing Done: Added a new test of interrupt, and ran all client tests. Bugs closed: aurora-497 Reviewed at https://reviews.apache.org/r/22207/ Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/2ed7d8d8 Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/2ed7d8d8 Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/2ed7d8d8 Branch: refs/heads/master Commit: 2ed7d8d876241d10ce10fd26e20195e53b50b93a Parents: 6feda1c Author: Mark Chu-Carroll Authored: Wed Jun 11 15:18:07 2014 -0400 Committer: Mark Chu-Carroll Committed: Wed Jun 11 15:18:07 2014 -0400 ---------------------------------------------------------------------- .../python/apache/aurora/client/cli/__init__.py | 13 +++++- .../apache/aurora/client/cli/test_create.py | 42 +++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/2ed7d8d8/src/main/python/apache/aurora/client/cli/__init__.py ---------------------------------------------------------------------- diff --git a/src/main/python/apache/aurora/client/cli/__init__.py b/src/main/python/apache/aurora/client/cli/__init__.py index 4e018f1..0596daa 100644 --- a/src/main/python/apache/aurora/client/cli/__init__.py +++ b/src/main/python/apache/aurora/client/cli/__init__.py @@ -45,6 +45,7 @@ from .options import CommandOption # Constants for standard return codes. EXIT_OK = 0 +EXIT_INTERRUPTED = 130 EXIT_INVALID_CONFIGURATION = 3 EXIT_COMMAND_FAILURE = 4 EXIT_INVALID_COMMAND = 5 @@ -363,7 +364,7 @@ class CommandLine(object): except ConfigurationPlugin.Error as e: print_aurora_log(logging.INFO, "Error executing post-execution plugin: %s", e.msg) - def execute(self, args): + def _execute(self, args): """Execute a command. :param args: the command-line arguments for the command. This only includes arguments that should be parsed by the application; it does not include sys.argv[0]. @@ -398,6 +399,16 @@ class CommandLine(object): print_aurora_log(logging.ERROR, "Internal error executing command: %s", e) return EXIT_API_ERROR + def execute(self, args): + try: + return self._execute(args) + except KeyboardInterrupt: + print_aurora_log(logging.ERROR, "Command interrupted by user") + return EXIT_INTERRUPTED + except Exception as e: + print_aurora_log(logging.ERROR, "Unknown error: %s" % e) + return EXIT_UNKNOWN_ERROR + class Noun(AuroraCommand): """A type of object manipulated by a command line application""" http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/2ed7d8d8/src/test/python/apache/aurora/client/cli/test_create.py ---------------------------------------------------------------------- diff --git a/src/test/python/apache/aurora/client/cli/test_create.py b/src/test/python/apache/aurora/client/cli/test_create.py index 224adc3..b9313be 100644 --- a/src/test/python/apache/aurora/client/cli/test_create.py +++ b/src/test/python/apache/aurora/client/cli/test_create.py @@ -17,7 +17,12 @@ import contextlib from mock import Mock, patch from twitter.common.contextutil import temporary_file -from apache.aurora.client.cli import EXIT_COMMAND_FAILURE, EXIT_INVALID_CONFIGURATION +from apache.aurora.client.cli import ( + EXIT_COMMAND_FAILURE, + EXIT_INTERRUPTED, + EXIT_INVALID_CONFIGURATION, + EXIT_UNKNOWN_ERROR +) from apache.aurora.client.cli.client import AuroraCommandLine from apache.aurora.client.cli.util import AuroraClientCommandTest, FakeAuroraCommandContext from apache.aurora.config import AuroraConfig @@ -181,3 +186,38 @@ class TestClientCreateCommand(AuroraClientCommandTest): api = mock_context.get_api('west') assert api.create_job.call_count == 0 assert api.scheduler_proxy.getTasksStatus.call_count == 0 + + def test_interrupt(self): + mock_context = FakeAuroraCommandContext() + with contextlib.nested( + patch('time.sleep'), + patch('apache.aurora.client.cli.jobs.Job.create_context', + side_effect=KeyboardInterrupt())): + api = mock_context.get_api('west') + api.create_job.return_value = self.get_createjob_response() + + with temporary_file() as fp: + fp.write(self.get_valid_config()) + fp.flush() + cmd = AuroraCommandLine() + result = cmd.execute(['job', 'create', '--wait-until=RUNNING', 'west/bozo/test/hello', + fp.name]) + assert result == EXIT_INTERRUPTED + assert api.create_job.call_count == 0 + + def test_unknown_error(self): + mock_context = FakeAuroraCommandContext() + with contextlib.nested( + patch('time.sleep'), + patch('apache.aurora.client.cli.jobs.Job.create_context', + side_effect=Exception("Argh"))): + api = mock_context.get_api('west') + api.create_job.return_value = self.get_createjob_response() + with temporary_file() as fp: + fp.write(self.get_valid_config()) + fp.flush() + cmd = AuroraCommandLine() + result = cmd.execute(['job', 'create', '--wait-until=RUNNING', 'west/bozo/test/hello', + fp.name]) + assert result == EXIT_UNKNOWN_ERROR + assert api.create_job.call_count == 0