aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mchucarr...@apache.org
Subject git commit: Prevent keyboard interrupts from spewing stack dumps.
Date Wed, 11 Jun 2014 19:30:30 GMT
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 <mchucarroll@twopensource.com>
Authored: Wed Jun 11 15:18:07 2014 -0400
Committer: Mark Chu-Carroll <mchucarroll@twitter.com>
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


Mime
View raw message