[PATCH] NetTestController: Write traceback to debug on error

Radek Pazdera rpazdera at redhat.com
Thu Aug 23 09:30:45 UTC 2012


When the recipe execution fails with an exception in NetTestController,
the exception is always caught and rethrown after propper cleanup has
been done.

This unfortunatelly leads to loosing the original exception traceback
which is very helpful for debugging.

The original traceback is now logged into debug when exception is
caught and then rethrown.

Signed-off-by: Radek Pazdera <rpazdera at redhat.com>
---
 Common/Logs.py               |    6 ++++++
 NetTest/NetTestController.py |    4 +++-
 NetTest/NetTestSlave.py      |    7 ++-----
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/Common/Logs.py b/Common/Logs.py
index ac0d5d3..0772f1f 100644
--- a/Common/Logs.py
+++ b/Common/Logs.py
@@ -12,9 +12,15 @@ jzupka at redhat.com (Jiri Zupka)
 import os, sys, shutil, datetime
 from logging import Formatter
 import logging.handlers
+import traceback
 
 LOCAL_IP = "(127.0.0.1)"
 
+def log_exc_traceback():
+    cmd_type, value, tb = sys.exc_info()
+    exception = traceback.format_exception(cmd_type, value, tb)
+    logging.debug(''.join(exception))
+
 class FindRootPathError(Exception):
     def __init__(self, path, rootFolder):
             Exception.__init__(self, path, rootFolder)
diff --git a/NetTest/NetTestController.py b/NetTest/NetTestController.py
index c5a218c..41707c5 100644
--- a/NetTest/NetTestController.py
+++ b/NetTest/NetTestController.py
@@ -14,7 +14,7 @@ jpirko at redhat.com (Jiri Pirko)
 import logging
 import socket
 import os
-from Common.Logs import Logs
+from Common.Logs import Logs, log_exc_traceback
 from Common.SshUtils import scp_from_remote
 from pprint import pprint, pformat
 from Common.XmlRpc import ServerProxy
@@ -295,6 +295,7 @@ class NetTestController:
         try:
             self._ntparse.parse_recipe()
         except Exception, exc:
+            log_exc_traceback()
             logging.debug("Exception raised during recipe parsing. "\
                     "Deconfiguring machines.")
             self._deconfigure_slaves()
@@ -377,6 +378,7 @@ class NetTestController:
         try:
             res = self._run_recipe()
         except Exception, exc:
+            log_exc_traceback()
             err = exc
 
         if packet_capture:
diff --git a/NetTest/NetTestSlave.py b/NetTest/NetTestSlave.py
index a7722e4..8065591 100644
--- a/NetTest/NetTestSlave.py
+++ b/NetTest/NetTestSlave.py
@@ -11,7 +11,7 @@ __author__ = """
 jpirko at redhat.com (Jiri Pirko)
 """
 
-from Common.Logs import Logs
+from Common.Logs import Logs, log_exc_traceback
 import signal
 import select, logging
 import os
@@ -114,10 +114,7 @@ class NetTestSlaveXMLRPC:
         try:
             return NetTestCommand(command).run()
         except:
-            import sys, traceback
-            cmd_type, value, tb = sys.exc_info()
-            exception = traceback.format_exception(cmd_type, value, tb)
-            logging.error(''.join(exception))
+            log_exc_traceback()
             raise CommandException(command)
 
     def machine_cleanup(self):
-- 
1.7.7.6



More information about the LNST-developers mailing list