2011-06-02 22:04:01 +00:00
|
|
|
import sys
|
|
|
|
import logging
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2013-07-12 03:24:09 +00:00
|
|
|
def run_one_task(taskname, **kwargs):
|
2011-06-09 18:43:16 +00:00
|
|
|
submod = taskname
|
|
|
|
subtask = 'task'
|
|
|
|
if '.' in taskname:
|
|
|
|
(submod, subtask) = taskname.rsplit('.', 1)
|
|
|
|
parent = __import__('teuthology.task', globals(), locals(), [submod], 0)
|
|
|
|
mod = getattr(parent, submod)
|
|
|
|
fn = getattr(mod, subtask)
|
2011-06-02 22:04:01 +00:00
|
|
|
return fn(**kwargs)
|
|
|
|
|
2011-06-16 20:01:09 +00:00
|
|
|
def run_tasks(tasks, ctx):
|
2011-06-02 22:04:01 +00:00
|
|
|
stack = []
|
|
|
|
try:
|
|
|
|
for taskdict in tasks:
|
|
|
|
try:
|
|
|
|
((taskname, config),) = taskdict.iteritems()
|
|
|
|
except ValueError:
|
|
|
|
raise RuntimeError('Invalid task definition: %s' % taskdict)
|
|
|
|
log.info('Running task %s...', taskname)
|
2013-07-12 03:24:09 +00:00
|
|
|
manager = run_one_task(taskname, ctx=ctx, config=config)
|
2011-06-02 22:04:01 +00:00
|
|
|
if hasattr(manager, '__enter__'):
|
|
|
|
manager.__enter__()
|
|
|
|
stack.append(manager)
|
2011-10-03 23:08:49 +00:00
|
|
|
except Exception, e:
|
2011-06-16 20:01:09 +00:00
|
|
|
ctx.summary['success'] = False
|
2011-10-03 23:08:49 +00:00
|
|
|
if 'failure_reason' not in ctx.summary:
|
|
|
|
ctx.summary['failure_reason'] = str(e)
|
2011-06-02 22:04:01 +00:00
|
|
|
log.exception('Saw exception from tasks')
|
2011-08-09 22:42:17 +00:00
|
|
|
if ctx.config.get('interactive-on-error'):
|
|
|
|
from .task import interactive
|
|
|
|
log.warning('Saw failure, going into interactive mode...')
|
|
|
|
interactive.task(ctx=ctx, config=None)
|
2011-06-02 22:04:01 +00:00
|
|
|
finally:
|
|
|
|
try:
|
|
|
|
exc_info = sys.exc_info()
|
|
|
|
while stack:
|
|
|
|
manager = stack.pop()
|
|
|
|
log.debug('Unwinding manager %s', manager)
|
|
|
|
try:
|
|
|
|
suppress = manager.__exit__(*exc_info)
|
2011-10-03 23:08:49 +00:00
|
|
|
except Exception, e:
|
2011-06-16 20:01:09 +00:00
|
|
|
ctx.summary['success'] = False
|
2011-10-03 23:08:49 +00:00
|
|
|
if 'failure_reason' not in ctx.summary:
|
|
|
|
ctx.summary['failure_reason'] = str(e)
|
2011-06-02 22:04:01 +00:00
|
|
|
log.exception('Manager failed: %s', manager)
|
2011-11-22 00:00:19 +00:00
|
|
|
|
|
|
|
if exc_info == (None, None, None):
|
|
|
|
# if first failure is in an __exit__, we don't
|
|
|
|
# have exc_info set yet
|
|
|
|
exc_info = sys.exc_info()
|
2011-12-01 01:07:26 +00:00
|
|
|
|
|
|
|
if ctx.config.get('interactive-on-error'):
|
|
|
|
from .task import interactive
|
|
|
|
log.warning('Saw failure, going into interactive mode...')
|
|
|
|
interactive.task(ctx=ctx, config=None)
|
2011-06-02 22:04:01 +00:00
|
|
|
else:
|
|
|
|
if suppress:
|
|
|
|
sys.exc_clear()
|
|
|
|
exc_info = (None, None, None)
|
|
|
|
|
|
|
|
if exc_info != (None, None, None):
|
2011-06-03 21:49:05 +00:00
|
|
|
log.debug('Exception was not quenched, exiting: %s: %s', exc_info[0].__name__, exc_info[1])
|
|
|
|
raise SystemExit(1)
|
2011-06-02 22:04:01 +00:00
|
|
|
finally:
|
|
|
|
# be careful about cyclic references
|
|
|
|
del exc_info
|