2013-07-12 03:24:09 +00:00
|
|
|
import sys
|
|
|
|
import logging
|
|
|
|
import contextlib
|
|
|
|
|
|
|
|
from teuthology import run_tasks
|
|
|
|
from teuthology import parallel
|
|
|
|
from ..orchestra import run
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
def task(ctx, config):
|
|
|
|
"""
|
|
|
|
Run a group of tasks in parallel.
|
|
|
|
|
|
|
|
example:
|
|
|
|
- parallel:
|
|
|
|
- tasktest:
|
|
|
|
- tasktest:
|
|
|
|
|
2013-07-22 20:03:24 +00:00
|
|
|
You can also reference the job from elsewhere:
|
|
|
|
|
|
|
|
foo:
|
|
|
|
tasktest:
|
|
|
|
tasks:
|
|
|
|
- parallel:
|
|
|
|
- foo
|
|
|
|
- tasktest:
|
|
|
|
|
|
|
|
That is, if the entry is not a dict, we will look it up in the top-level
|
|
|
|
config.
|
|
|
|
|
2013-07-12 03:24:09 +00:00
|
|
|
Sequential task and Parallel tasks can be nested.
|
|
|
|
"""
|
|
|
|
|
|
|
|
log.info('starting parallel...')
|
|
|
|
with parallel.parallel() as p:
|
|
|
|
for entry in config:
|
2013-07-22 20:03:24 +00:00
|
|
|
if not isinstance(entry, dict):
|
|
|
|
entry = ctx.config.get(entry, {})
|
2013-07-12 03:24:09 +00:00
|
|
|
((taskname, confg),) = entry.iteritems()
|
|
|
|
p.spawn(_run_spawned, ctx, confg, taskname)
|
|
|
|
|
|
|
|
def _run_spawned(ctx,config,taskname):
|
|
|
|
mgr = {}
|
|
|
|
try:
|
|
|
|
log.info('In parallel, running task %s...' % taskname)
|
|
|
|
mgr = run_tasks.run_one_task(taskname, ctx=ctx, config=config)
|
|
|
|
if hasattr(mgr, '__enter__'):
|
|
|
|
mgr.__enter__()
|
|
|
|
finally:
|
|
|
|
exc_info = sys.exc_info()
|
|
|
|
if hasattr(mgr, '__exit__'):
|
|
|
|
mgr.__exit__(*exc_info)
|
|
|
|
del exc_info
|