From e04f8fd3cd958a6e82f6cbd7b9568714a02ae2c3 Mon Sep 17 00:00:00 2001 From: Sandon Van Ness Date: Tue, 25 Feb 2014 11:13:31 -0800 Subject: [PATCH] Add teuthology-queue command for beanstalk Managmeent. Supports listing entire queue of machine type and deleting test suite runs from the queue without wiping the entire queue. Signed-off-by: Sandon Van Ness --- scripts/queue.py | 27 ++++++++++++++++++ setup.py | 1 + teuthology/beanstalk.py | 61 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 scripts/queue.py create mode 100644 teuthology/beanstalk.py diff --git a/scripts/queue.py b/scripts/queue.py new file mode 100644 index 0000000000..e89b19ee29 --- /dev/null +++ b/scripts/queue.py @@ -0,0 +1,27 @@ +import docopt + +import teuthology.config +import teuthology.beanstalk + +doc = """ +usage: teuthology-queue [-h] -m MACHINE_TYPE + teuthology-queue [-h] -m MACHINE_TYPE -d JOB + +List Jobs in queue: + If -d then jobs with JOB in the job name are delete from the queue. + +Arguments: + -m, --machine_type MACHINE_TYPE + Which machine type queue to work on. + +optional arguments: + -h, --help show this help message and exit + + -d, --delete JOB Delete Jobs with JOB in jobname. + +""".format(archive_base=teuthology.config.config.archive_base) + + +def main(): + args = docopt.docopt(doc) + teuthology.beanstalk.main(args) diff --git a/setup.py b/setup.py index df95fdb1fe..2354e68a0d 100644 --- a/setup.py +++ b/setup.py @@ -28,6 +28,7 @@ setup( 'teuthology-results = scripts.results:main', 'teuthology-report = scripts.report:main', 'teuthology-kill = scripts.kill:main', + 'teuthology-queue = scripts.queue:main', ], }, diff --git a/teuthology/beanstalk.py b/teuthology/beanstalk.py new file mode 100644 index 0000000000..e8489c16cb --- /dev/null +++ b/teuthology/beanstalk.py @@ -0,0 +1,61 @@ +import beanstalkc +import yaml +import logging + +from .config import config + +log = logging.getLogger(__name__) + +def beanstalk_connect(machine_type): + qhost = config.queue_host + qport = config.queue_port + if qhost is None or qport is None: + raise RuntimeError( + 'Beanstalk queue information not found in {conf_path}'.format( + conf_path=config.teuthology_yaml)) + log.info("Checking Beanstalk Queue...") + beanstalk = beanstalkc.Connection(host=qhost, port=qport) + beanstalk.watch(machine_type) + beanstalk.ignore('default') + return beanstalk + +def walk_jobs(beanstalk, machine_type, delete=False): + curjobs = beanstalk.stats_tube(machine_type)['current-jobs-ready'] + if curjobs != 0: + x=1 + while x != curjobs: + x += 1 + job = beanstalk.reserve(timeout=20) + if job.body is not None: + job_config = yaml.safe_load(job.body) + job_name=job_config['name'] + job_id = job.stats()['id'] + job_description = job_config['description'] + if delete: + if delete in job_name: + print 'Deleted Job: {job_id} from queue. Name: {job_name}'.format( + job_id = job_id, + job_name = job_name, + ) + job.delete() + else: + print "Searching queue... Checked " + str(x) + "/" + str(curjobs)," Jobs\r", + else: + print 'Job: {x}/{curjobs} ID: {job_id} Name: {job_name}'.format( + x=x, + curjobs=curjobs, + job_id=job_id, + job_name=job_name, + ) + print '\t {desc}'.format(desc=job_description) + + print "\nDone" + else: + log.info('No jobs in Beanstalk Queue') + +def main(args): + machine_type = args['--machine_type'] + delete = args['--delete'] + beanstalk = beanstalk_connect(machine_type) + walk_jobs(beanstalk, machine_type, delete) + beanstalk.close() -- 2.39.5