2013-10-09 20:13:01 +00:00
|
|
|
import yaml
|
|
|
|
|
2014-04-15 00:28:54 +00:00
|
|
|
import teuthology.beanstalk
|
2014-06-24 15:13:30 +00:00
|
|
|
from teuthology.misc import deep_merge, get_user
|
2014-04-15 00:46:07 +00:00
|
|
|
from teuthology import report
|
2013-10-09 20:13:01 +00:00
|
|
|
|
|
|
|
|
2014-06-09 18:31:11 +00:00
|
|
|
def main(args):
|
|
|
|
if not args['--last-in-suite']:
|
|
|
|
if args['--email']:
|
|
|
|
raise ValueError(
|
|
|
|
'--email is only applicable to the last job in a suite')
|
|
|
|
if args['--timeout']:
|
|
|
|
raise ValueError(
|
|
|
|
'--timeout is only applicable to the last job in a suite')
|
|
|
|
job_config = build_config(args)
|
|
|
|
schedule_job(job_config, args['--num'])
|
2013-10-09 20:13:01 +00:00
|
|
|
|
|
|
|
|
2014-06-09 18:31:11 +00:00
|
|
|
def build_config(args):
|
|
|
|
"""
|
|
|
|
Given a dict of arguments, build a job config
|
|
|
|
"""
|
|
|
|
config_paths = args.get('<conf_file>', list())
|
|
|
|
conf_dict = dict()
|
|
|
|
for conf_path in config_paths:
|
2014-06-23 22:53:03 +00:00
|
|
|
with file(conf_path) as partial_file:
|
|
|
|
partial_dict = yaml.safe_load(partial_file)
|
|
|
|
conf_dict = deep_merge(conf_dict, partial_dict)
|
2013-10-09 20:13:01 +00:00
|
|
|
# strip out targets; the worker will allocate new ones when we run
|
|
|
|
# the job with --lock.
|
2014-06-09 18:31:11 +00:00
|
|
|
if 'targets' in conf_dict:
|
|
|
|
del conf_dict['targets']
|
|
|
|
args['config'] = conf_dict
|
|
|
|
|
|
|
|
owner = args['--owner']
|
|
|
|
if owner is None:
|
|
|
|
owner = 'scheduled_{user}'.format(user=get_user())
|
2013-10-09 20:13:01 +00:00
|
|
|
|
|
|
|
job_config = dict(
|
2014-06-09 18:31:11 +00:00
|
|
|
name=args['--name'],
|
|
|
|
last_in_suite=args['--last-in-suite'],
|
|
|
|
email=args['--email'],
|
|
|
|
description=args['--description'],
|
|
|
|
owner=owner,
|
|
|
|
verbose=args['--verbose'],
|
|
|
|
machine_type=args['--worker'],
|
|
|
|
tube=args['--worker'],
|
|
|
|
priority=int(args['--priority']),
|
2013-10-09 20:13:01 +00:00
|
|
|
)
|
2014-06-09 18:31:11 +00:00
|
|
|
# Update the dict we just created, and not the other way around, to let
|
|
|
|
# settings in the yaml override what's passed on the command line. This is
|
|
|
|
# primarily to accommodate jobs with multiple machine types.
|
|
|
|
job_config.update(conf_dict)
|
|
|
|
if args['--timeout'] is not None:
|
|
|
|
job_config['results_timeout'] = args['--timeout']
|
|
|
|
return job_config
|
2013-10-09 20:13:01 +00:00
|
|
|
|
2014-06-09 18:31:11 +00:00
|
|
|
|
|
|
|
def schedule_job(job_config, num=1):
|
|
|
|
"""
|
|
|
|
Schedule a job.
|
|
|
|
|
|
|
|
:param job_config: The complete job dict
|
|
|
|
:param num: The number of times to schedule the job
|
|
|
|
"""
|
|
|
|
num = int(num)
|
2013-10-09 20:13:01 +00:00
|
|
|
job = yaml.safe_dump(job_config)
|
2014-06-09 18:31:11 +00:00
|
|
|
tube = job_config.pop('tube')
|
|
|
|
beanstalk = teuthology.beanstalk.connect()
|
|
|
|
beanstalk.use(tube)
|
2013-10-09 20:13:01 +00:00
|
|
|
while num > 0:
|
|
|
|
jid = beanstalk.put(
|
|
|
|
job,
|
|
|
|
ttr=60 * 60 * 24,
|
2014-06-09 18:31:11 +00:00
|
|
|
priority=job_config['priority'],
|
2013-10-09 20:13:01 +00:00
|
|
|
)
|
|
|
|
print 'Job scheduled with name {name} and ID {jid}'.format(
|
2014-06-09 18:31:11 +00:00
|
|
|
name=job_config['name'], jid=jid)
|
2014-04-15 00:46:07 +00:00
|
|
|
job_config['job_id'] = str(jid)
|
2014-04-25 20:22:30 +00:00
|
|
|
report.try_push_job_info(job_config, dict(status='queued'))
|
2013-10-09 20:13:01 +00:00
|
|
|
num -= 1
|