]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Consolidate sys.excepthook replacements
authorZack Cerza <zack@redhat.com>
Fri, 24 Mar 2017 18:32:33 +0000 (12:32 -0600)
committerZack Cerza <zack@redhat.com>
Thu, 30 Mar 2017 18:31:49 +0000 (12:31 -0600)
Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/__init__.py
teuthology/run.py
teuthology/worker.py

index b7347612be73f817e62c50e39d3a6e1d6b7ad788..d037f53a18f4e1b738f8de17c7f9aa9f13fcfa49 100644 (file)
@@ -80,3 +80,16 @@ def setup_log_file(log_path):
     handler.setFormatter(formatter)
     root_logger.addHandler(handler)
     root_logger.info('teuthology version: %s', __version__)
+
+
+def install_except_hook():
+    """
+    Install an exception hook that first logs any uncaught exception, then
+    raises it.
+    """
+    def log_exception(exc_type, exc_value, exc_traceback):
+        if not issubclass(exc_type, KeyboardInterrupt):
+            log.critical("Uncaught exception", exc_info=(exc_type, exc_value,
+                                                         exc_traceback))
+        sys.__excepthook__(exc_type, exc_value, exc_traceback)
+    sys.excepthook = log_exception
index eda7e43c3ebf9c7166251f117d351b45f3c47aed..3ec1c12f89d455435df55aeb5ca765c9321f6874 100644 (file)
@@ -4,9 +4,9 @@ import StringIO
 import contextlib
 import sys
 import logging
-from traceback import format_tb
 
 import teuthology
+from teuthology import install_except_hook
 from . import report
 from .job_status import get_status
 from .misc import get_user, merge_configs
@@ -33,18 +33,6 @@ def set_up_logging(verbose, archive):
     install_except_hook()
 
 
-def install_except_hook():
-    def log_exception(exception_class, exception, traceback):
-        logging.critical(''.join(format_tb(traceback)))
-        if not exception.message:
-            logging.critical(exception_class.__name__)
-            return
-        logging.critical('{0}: {1}'.format(
-            exception_class.__name__, exception))
-
-    sys.excepthook = log_exception
-
-
 def write_initial_metadata(archive, config, name, description, owner):
     if archive is not None:
         with file(os.path.join(archive, 'pid'), 'w') as f:
index 7593963e986fec770fdde31ac9567010dc68ad20..f73bacaf6a208aeac998313db3bbd4a178bd8fc7 100644 (file)
@@ -8,7 +8,7 @@ import yaml
 
 from datetime import datetime
 
-from teuthology import setup_log_file
+from teuthology import setup_log_file, install_except_hook
 from . import beanstalk
 from . import report
 from . import safepath
@@ -58,19 +58,6 @@ def load_config(ctx=None):
             teuth_config.archive_base = ctx.archive_dir
 
 
-def install_except_hook():
-    """
-    Install an exception hook that first logs any uncaught exception, then
-    raises it.
-    """
-    def log_exception(exc_type, exc_value, exc_traceback):
-        if not issubclass(exc_type, KeyboardInterrupt):
-            log.critical("Uncaught exception", exc_info=(exc_type, exc_value,
-                                                         exc_traceback))
-        sys.__excepthook__(exc_type, exc_value, exc_traceback)
-    sys.excepthook = log_exception
-
-
 def main(ctx):
     loglevel = logging.INFO
     if ctx.verbose: