提交 1401a60f 编写于 作者: C Cleber Rosa

Merge remote-tracking branch 'ldoktor/exceptions3'

......@@ -37,3 +37,5 @@ AVOCADO_FAIL = 3
#: The job was explicitly interrupted. Usually this means that a user
#: hit CTRL+C while the job was still running.
AVOCADO_JOB_INTERRUPTED = 4
#: Avocado generic crash
AVOCADO_GENERIC_CRASH = -1
......@@ -533,11 +533,11 @@ class Job(object):
except exceptions.JobBaseException, details:
self.status = details.status
fail_class = details.__class__.__name__
self.view.notify(event='error', msg=('Avocado job failed: %s: %s' %
(fail_class, details)))
self.view.notify(event='error', msg=('\nAvocado job failed: %s: %s'
% (fail_class, details)))
return exit_codes.AVOCADO_JOB_FAIL
except exceptions.OptionValidationError, details:
self.view.notify(event='error', msg=str(details))
self.view.notify(event='error', msg='\n' + str(details))
return exit_codes.AVOCADO_JOB_FAIL
except Exception, details:
......@@ -546,7 +546,7 @@ class Job(object):
tb_info = traceback.format_exception(exc_type, exc_value,
exc_traceback.tb_next)
fail_class = details.__class__.__name__
self.view.notify(event='error', msg=('Avocado crashed: %s: %s' %
self.view.notify(event='error', msg=('\nAvocado crashed: %s: %s' %
(fail_class, details)))
for line in tb_info:
self.view.notify(event='minor', msg=line)
......
......@@ -140,14 +140,24 @@ class TestRunner(object):
proc.start()
end = time.time() + 10
while queue.empty():
if not proc.is_alive() and queue.empty():
raise exceptions.TestError("Process died before it pushed "
"early state.")
if time.time() > end:
msg = ("Unable to receive test's early-state in 10s, "
"something wrong happened probably in the "
"avocado framework.")
os.kill(proc.pid, 9)
raise exceptions.TestError(msg)
time.sleep(0)
early_state = queue.get()
if 'load_exception' in early_state:
self.job.view.notify(event='error',
msg='Avocado crashed during test load. '
'Some reports might have not been '
'generated. Aborting...')
sys.exit(exit_codes.AVOCADO_FAIL)
raise exceptions.TestError('Avocado crashed during test load. '
'Some reports might have not been '
'generated. Aborting...')
# At this point, the test is already initialized and we know
# for sure if there's a timeout set.
......
......@@ -14,8 +14,62 @@
# Author: Lucas Meneghel Rodrigues <lmr@redhat.com>
import os
import sys
try:
import logging
import os
import tempfile
import traceback
except:
sys.stderr.write("Unable to import basic python libraries, please "
"reinstall avocado and dependencies.\n")
# This exit code is replicated from avocado/core/exit_codes.py and not
# imported because we are dealing with import failures
sys.exit(-1)
def handle_exception(*exc_info):
# Print traceback into avocado.app.traceback if initialized
msg = "Avocado crashed:\n" + "".join(traceback.format_exception(*exc_info))
log = logging.getLogger("avocado.app.tracebacks")
if getattr(log, "handlers", False):
log.error(msg)
# Store traceback in data_dir or TMPDIR
crash_dir = None
prefix = "avocado-traceback-"
try:
import time
prefix += time.strftime("%F_%T") + "-"
from avocado.core import data_dir
_crash_dir = os.path.join(data_dir.get_data_dir(), "crashes")
os.makedirs(_crash_dir)
crash_dir = _crash_dir
except:
pass
tmp, name = tempfile.mkstemp(".log", prefix, crash_dir)
os.write(tmp, msg)
os.close(tmp)
# Print friendly message in console-like output
msg = ("Avocado crashed unexpectidly: %s\nYou can find details in %s"
% (exc_info[1], name))
for name in ("avocado.app", "avocado.test", None):
log = logging.getLogger(name)
for handler in getattr(log, "handlers", []):
if isinstance(handler, logging.StreamHandler):
break
else:
continue
log.critical(msg)
break
else: # Log not found, use stderr and hope it's enabled
sys.stderr.write(msg + '\n')
# This exit code is replicated from avocado/core/exit_codes.py and not
# imported because we are dealing with import failures
sys.exit(-1)
if __name__ == '__main__':
sys.excepthook = handle_exception
# simple magic for using scripts within a source tree
basedir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册