aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mchucarr...@apache.org
Subject git commit: Move the error-log seed file to a user specified directory.
Date Wed, 08 Oct 2014 18:01:57 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 0e63ed232 -> 29ce18378


Move the error-log seed file to a user specified directory.

Instead of dumping error traces into the users current directory,
dump them into a user specified directory, with a benign default.

Bugs closed: aurora-779

Reviewed at https://reviews.apache.org/r/26448/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/29ce1837
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/29ce1837
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/29ce1837

Branch: refs/heads/master
Commit: 29ce18378fb6ccbd614efbd6fe6305f8ee9e2a0f
Parents: 0e63ed2
Author: Mark Chu-Carroll <mchucarroll@twopensource.com>
Authored: Wed Oct 8 13:59:16 2014 -0400
Committer: Mark Chu-Carroll <mchucarroll@twitter.com>
Committed: Wed Oct 8 13:59:16 2014 -0400

----------------------------------------------------------------------
 .../python/apache/aurora/client/cli/__init__.py | 30 +++++++++++---------
 .../aurora/client/cli/standalone_client.py      | 18 +++++++-----
 .../apache/aurora/client/cli/test_create.py     | 19 ++++++++-----
 .../apache/aurora/client/cli/test_inspect.py    |  3 +-
 .../apache/aurora/client/cli/test_plugins.py    |  2 +-
 .../python/apache/aurora/client/cli/util.py     |  4 +--
 6 files changed, 42 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/29ce1837/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 5c0688f..da9d5b6 100644
--- a/src/main/python/apache/aurora/client/cli/__init__.py
+++ b/src/main/python/apache/aurora/client/cli/__init__.py
@@ -33,6 +33,8 @@ from __future__ import print_function
 import argparse
 import getpass
 import logging
+import os
+import os.path
 import sys
 import time
 import traceback
@@ -105,25 +107,21 @@ class Context(object):
       self.msg = msg
       self.code = code
 
-  REVEAL_ERRORS = False
+  ERROR_LOG_DIR = None
+
+  @staticmethod
+  def set_error_log_dir(dir):
+    Context.ERROR_LOG_DIR = dir  # noqa
+
+  @staticmethod
+  def get_error_log_dir():
+    return Context.ERROR_LOG_DIR # noqa
 
   def __init__(self):
     self.options = None
     self.logging_level = None
 
   @classmethod
-  def reveal_errors(cls):
-    return cls.REVEAL_ERRORS
-
-  @classmethod
-  def enable_reveal_errors(cls):
-    cls.REVEAL_ERRORS = True
-
-  @classmethod
-  def disable_reveal_errors(cls):
-    cls.REVEAL_ERRORS = False
-
-  @classmethod
   def exit(cls, code, msg):
     raise cls.CommandError(code, msg)
 
@@ -432,9 +430,13 @@ class CommandLine(object):
     :param exc_traceback: the exc_traceback value for the error returnen by sys.exc_info()
     """
     now = str(int(time.time()))
-    path = "%s-%s.error-log" % (self.name, now)
+    dir = os.path.expanduser(Context.get_error_log_dir())
+    if not os.path.isdir(dir):
+      os.makedirs(dir)
+    path = os.path.join(dir, "%s-%s.error-log" % (self.name, now))
     print("Fatal error running command; traceback can be found in %s" % path,
         file=sys.stderr)
+
     with open(path, "w") as out:
       print("ERROR LOG: command arguments = %s" % cmd_args, file=out)
       traceback.print_exception(exc_type, exc_value, exc_traceback, file=out)

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/29ce1837/src/main/python/apache/aurora/client/cli/standalone_client.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/standalone_client.py b/src/main/python/apache/aurora/client/cli/standalone_client.py
index 4fdcf6d..20f4d7e 100644
--- a/src/main/python/apache/aurora/client/cli/standalone_client.py
+++ b/src/main/python/apache/aurora/client/cli/standalone_client.py
@@ -22,21 +22,25 @@ from apache.aurora.client.cli.options import CommandOption
 
 
 class AuroraErrorHandlingPlugin(ConfigurationPlugin):
-  """Plugin for managing the REVEAL_ERRORS flag, which determines whether or not the aurora
-  command line supresses unknown excepts, or dumps the stack. The default behavior
-  should be to supress errors, but for debugging, we want to see the stack dump.
+  """Plugin for managing error logs for internal system errors.
+  When an unknown error occurs, the command-line supresses the stack dump on standard out/standard
+  error and instead dumps the detailed information including the stack trace into a log
+  file. This plugin allows the location where the error log will be written to be defined
by
+  the user.
   """
 
   def get_options(self):
-    return [CommandOption("--reveal-errors", default=False, action="store_true",
-        help="If enabled, allow unknown errors to generate stack dumps")]
+    return [
+        CommandOption("--error-log-dir", default="~/.aurora/errors",
+            help="Directory location where error files containing stack traces "
+            "should be written. If the directory doesn't exist, it will be "
+            "created")]
 
   def before_dispatch(self, raw_args):
     return raw_args
 
   def before_execution(self, context):
-    if context.options.reveal_errors:
-      context.enable_reveal_errors()
+    context.set_error_log_dir(context.options.error_log_dir)
 
   def after_execution(self, context, result_code):
     pass

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/29ce1837/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 8dc0ccb..88d1b35 100644
--- a/src/test/python/apache/aurora/client/cli/test_create.py
+++ b/src/test/python/apache/aurora/client/cli/test_create.py
@@ -14,6 +14,7 @@
 
 import contextlib
 import os
+import shutil
 
 from mock import Mock, patch
 from twitter.common.contextutil import temporary_file
@@ -145,16 +146,19 @@ class TestClientCreateCommand(AuroraClientCommandTest):
         fp.write(self.get_valid_config())
         fp.flush()
         cmd = AuroraCommandLine()
-        result = cmd.execute(['job', 'create', '--wait-until=RUNNING', 'west/bozo/test/hello',
+        result = cmd.execute(['job', 'create', '--wait-until=RUNNING',
+           '--error-log-dir=./logged-errors', 'west/bozo/test/hello',
             fp.name])
         assert result == EXIT_UNKNOWN_ERROR
-        with open("aurora-23.error-log", "r") as logfile:
+        with open("./logged-errors/aurora-23.error-log", "r") as logfile:
           error_log = logfile.read()
           assert error_log.startswith("ERROR LOG: command arguments = %s" %
-              ['job', 'create', '--wait-until=RUNNING', 'west/bozo/test/hello',
+              ['job', 'create', '--wait-until=RUNNING', '--error-log-dir=./logged-errors',
+               'west/bozo/test/hello',
               fp.name])
           assert "Traceback" in error_log
-        os.remove('aurora-23.error-log')
+        if os.path.exists("./logged-errors"):
+          shutil.rmtree("./logged-errors")
 
   def test_create_job_delayed(self):
     """Run a test of the "create" command against a mocked-out API:
@@ -237,7 +241,7 @@ class TestClientCreateCommand(AuroraClientCommandTest):
         assert api.create_job.call_count == 0
 
   def test_interrupt_error(self):
-    mock_context = FakeAuroraCommandContext(reveal=False)
+    mock_context = FakeAuroraCommandContext()
     with contextlib.nested(
         patch('time.sleep'),
         patch('time.time', return_value=23),
@@ -250,10 +254,12 @@ class TestClientCreateCommand(AuroraClientCommandTest):
         fp.flush()
         cmd = AuroraCommandLine()
         result = cmd.execute(['job', 'create', '--wait-until=RUNNING', 'west/bozo/test/hello',
+            '--error-log-dir=./error-logs',
             fp.name])
         assert result == EXIT_UNKNOWN_ERROR
         assert api.create_job.call_count == 0
-        os.remove('aurora-23.error-log')
+        if os.path.exists("./error-logs"):
+          shutil.rmtree("./error-logs")
 
   def test_simple_successful_create_job_output(self):
     """Run a test of the "create" command against a mocked-out API:
@@ -317,7 +323,6 @@ class TestClientCreateCommand(AuroraClientCommandTest):
         self.create_mock_status_query_result(ScheduleStatus.RUNNING))
       api = mock_context.get_api('west')
       api.create_job.return_value = self.get_createjob_response()
-      mock_context.enable_reveal_errors()
 
       # This is the real test: invoke create as if it had been called by the command line.
       with temporary_file() as fp:

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/29ce1837/src/test/python/apache/aurora/client/cli/test_inspect.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_inspect.py b/src/test/python/apache/aurora/client/cli/test_inspect.py
index fd35fe0..b64fbf9 100644
--- a/src/test/python/apache/aurora/client/cli/test_inspect.py
+++ b/src/test/python/apache/aurora/client/cli/test_inspect.py
@@ -59,7 +59,6 @@ class TestInspectCommand(AuroraClientCommandTest):
 
   def test_inspect_job(self):
     (mock_api, mock_scheduler_proxy) = self.create_mock_api()
-    AuroraCommandContext.enable_reveal_errors()
     mock_transcript = []
     def mock_print_out(msg, indent=0):
       indent_str = " " * indent
@@ -75,7 +74,7 @@ class TestInspectCommand(AuroraClientCommandTest):
         fp.write(self.get_valid_config())
         fp.flush()
         cmd = AuroraCommandLine()
-        result = cmd.execute(['job', 'inspect', '--reveal-errors', 'west/bozo/test/hello',
fp.name])
+        result = cmd.execute(['job', 'inspect', 'west/bozo/test/hello', fp.name])
         # inspect command should run without errors, and return 0.
         assert result == 0
         # The command output for the mock should look right.

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/29ce1837/src/test/python/apache/aurora/client/cli/test_plugins.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_plugins.py b/src/test/python/apache/aurora/client/cli/test_plugins.py
index 7a0a318..7c79c7a 100644
--- a/src/test/python/apache/aurora/client/cli/test_plugins.py
+++ b/src/test/python/apache/aurora/client/cli/test_plugins.py
@@ -202,7 +202,7 @@ class TestPlugins(AuroraClientCommandTest):
 
     # We'll patch out create_context, which will give us a fake context
     # object, and everything can be stubbed through that.
-    mock_context = FakeAuroraCommandContext(reveal=False)
+    mock_context = FakeAuroraCommandContext()
     with patch('apache.aurora.client.cli.jobs.Job.create_context', return_value=mock_context):
       # After making the client, create sets up a job monitor.
       # The monitor uses TaskQuery to get the tasks. It's called at least twice:once before

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/29ce1837/src/test/python/apache/aurora/client/cli/util.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/util.py b/src/test/python/apache/aurora/client/cli/util.py
index ff7eda2..4e9b636 100644
--- a/src/test/python/apache/aurora/client/cli/util.py
+++ b/src/test/python/apache/aurora/client/cli/util.py
@@ -37,7 +37,7 @@ from gen.apache.aurora.api.ttypes import (
 
 
 class FakeAuroraCommandContext(AuroraCommandContext):
-  def __init__(self, reveal=True):
+  def __init__(self):
     super(FakeAuroraCommandContext, self).__init__()
     self.options = None
     self.status = []
@@ -46,8 +46,6 @@ class FakeAuroraCommandContext(AuroraCommandContext):
     self.showed_urls = []
     self.out = []
     self.err = []
-    if reveal:
-      self.enable_reveal_errors()
 
   def get_api(self, cluster):
     return self.fake_api


Mime
View raw message