2011-06-02 22:04:01 +00:00
|
|
|
import sys
|
|
|
|
import logging
|
2013-09-11 15:17:02 +00:00
|
|
|
from .sentry import get_client as get_sentry_client
|
|
|
|
from .misc import get_http_log_path
|
2013-08-26 22:11:51 +00:00
|
|
|
from .config import config as teuth_config
|
2013-09-11 20:17:22 +00:00
|
|
|
from copy import deepcopy
|
2011-06-02 22:04:01 +00:00
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2013-08-26 22:11:51 +00:00
|
|
|
|
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)
|
2014-05-12 09:55:58 +00:00
|
|
|
|
|
|
|
# Teuthology configs may refer to modules like ceph_deploy as ceph-deploy
|
|
|
|
submod = submod.replace('-', '_')
|
|
|
|
|
2011-06-09 18:43:16 +00:00
|
|
|
parent = __import__('teuthology.task', globals(), locals(), [submod], 0)
|
2014-03-31 14:57:19 +00:00
|
|
|
try:
|
|
|
|
mod = getattr(parent, submod)
|
|
|
|
except AttributeError:
|
|
|
|
log.error("No task named %s was found", submod)
|
|
|
|
raise
|
|
|
|
try:
|
|
|
|
fn = getattr(mod, subtask)
|
|
|
|
except AttributeError:
|
|
|
|
log.error("No subtask of %s named %s was found", mod, subtask)
|
|
|
|
raise
|
2011-06-02 22:04:01 +00:00
|
|
|
return fn(**kwargs)
|
|
|
|
|
2013-08-26 22:11:51 +00:00
|
|
|
|
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()
|
2014-07-02 18:09:03 +00:00
|
|
|
except (ValueError, AttributeError):
|
2011-06-02 22:04:01 +00:00
|
|
|
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__()
|
2014-02-05 20:28:35 +00:00
|
|
|
stack.append((taskname, manager))
|
2014-01-27 19:02:30 +00:00
|
|
|
except Exception as 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)
|
2013-08-23 19:53:38 +00:00
|
|
|
log.exception('Saw exception from tasks.')
|
2014-02-05 20:28:35 +00:00
|
|
|
|
2013-08-23 16:40:44 +00:00
|
|
|
sentry = get_sentry_client()
|
2013-08-21 15:07:12 +00:00
|
|
|
if sentry:
|
2013-09-11 20:45:45 +00:00
|
|
|
config = deepcopy(ctx.config)
|
|
|
|
|
2013-08-26 22:38:23 +00:00
|
|
|
tags = {
|
|
|
|
'task': taskname,
|
|
|
|
'owner': ctx.owner,
|
|
|
|
}
|
2013-09-11 20:45:45 +00:00
|
|
|
if 'teuthology_branch' in config:
|
|
|
|
tags['teuthology_branch'] = config['teuthology_branch']
|
2013-09-11 20:17:22 +00:00
|
|
|
|
|
|
|
# Remove ssh keys from reported config
|
|
|
|
if 'targets' in config:
|
|
|
|
targets = config['targets']
|
|
|
|
for host in targets.keys():
|
|
|
|
targets[host] = '<redacted>'
|
|
|
|
|
2013-09-18 15:05:14 +00:00
|
|
|
job_id = ctx.config.get('job_id')
|
|
|
|
archive_path = ctx.config.get('archive_path')
|
2013-09-11 15:17:02 +00:00
|
|
|
extra = {
|
2013-09-11 20:17:22 +00:00
|
|
|
'config': config,
|
2013-09-18 15:05:14 +00:00
|
|
|
'logs': get_http_log_path(archive_path, job_id),
|
2013-09-11 15:17:02 +00:00
|
|
|
}
|
2013-09-11 19:00:58 +00:00
|
|
|
exc_id = sentry.get_ident(sentry.captureException(
|
2013-09-11 15:17:02 +00:00
|
|
|
tags=tags,
|
|
|
|
extra=extra,
|
2013-09-11 19:00:58 +00:00
|
|
|
))
|
2013-08-26 22:11:51 +00:00
|
|
|
event_url = "{server}/search?q={id}".format(
|
2013-08-26 23:12:20 +00:00
|
|
|
server=teuth_config.sentry_server.strip('/'), id=exc_id)
|
2013-08-26 22:11:51 +00:00
|
|
|
log.exception(" Sentry event: %s" % event_url)
|
2013-11-04 20:02:45 +00:00
|
|
|
ctx.summary['sentry_event'] = event_url
|
2014-02-05 20:28:35 +00:00
|
|
|
|
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)
|
2014-05-07 21:05:56 +00:00
|
|
|
# Throughout teuthology, (x,) = y has been used to assign values
|
|
|
|
# from yaml files where only one entry of type y is correct. This
|
|
|
|
# causes failures with 'too many values to unpack.' We want to
|
|
|
|
# fail as before, but with easier to understand error indicators.
|
|
|
|
if type(e) == ValueError:
|
|
|
|
if e.message == 'too many values to unpack':
|
|
|
|
emsg = 'Possible configuration error in yaml file'
|
|
|
|
log.error(emsg)
|
|
|
|
ctx.summary['failure_info'] = emsg
|
2011-06-02 22:04:01 +00:00
|
|
|
finally:
|
|
|
|
try:
|
|
|
|
exc_info = sys.exc_info()
|
|
|
|
while stack:
|
2014-02-05 20:28:35 +00:00
|
|
|
taskname, manager = stack.pop()
|
|
|
|
log.debug('Unwinding manager %s', taskname)
|
2011-06-02 22:04:01 +00:00
|
|
|
try:
|
|
|
|
suppress = manager.__exit__(*exc_info)
|
2014-01-27 19:02:30 +00:00
|
|
|
except Exception as 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)
|
2014-02-05 20:28:35 +00:00
|
|
|
log.exception('Manager failed: %s', taskname)
|
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
|
2014-01-27 19:02:30 +00:00
|
|
|
log.warning(
|
|
|
|
'Saw failure, going into interactive mode...')
|
2011-12-01 01:07:26 +00:00
|
|
|
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):
|
2014-01-27 19:02:30 +00:00
|
|
|
log.debug('Exception was not quenched, exiting: %s: %s',
|
|
|
|
exc_info[0].__name__, exc_info[1])
|
2011-06-03 21:49:05 +00:00
|
|
|
raise SystemExit(1)
|
2011-06-02 22:04:01 +00:00
|
|
|
finally:
|
|
|
|
# be careful about cyclic references
|
|
|
|
del exc_info
|