]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
schedule: add more than one queue backend
authorKyr Shatskyy <kyrylo.shatskyy@suse.com>
Sun, 10 May 2020 15:01:21 +0000 (17:01 +0200)
committerKyr Shatskyy <kyrylo.shatskyy@suse.com>
Mon, 6 Jul 2020 16:45:23 +0000 (18:45 +0200)
This allows to have more than one beanstalk queue for jobs.
For example, use paddles or local sqlite for managing queue.

At the moment it gives a possibility to omit 'beanstalk'
queue in order to get job configurations letting a user
to run teuthology job autonomously.

Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@suse.com>
scripts/schedule.py
scripts/suite.py
teuthology/schedule.py
teuthology/suite/run.py

index feeafd770e0765d1c3b93d325b2c0e5a096d4df1..ffcb112b45e04d08249e6cd6cf16f57fadc8aba5 100644 (file)
@@ -16,6 +16,11 @@ positional arguments:
 optional arguments:
   -h, --help                           Show this help message and exit
   -v, --verbose                        Be more verbose
+  -b <backend>, --queue-backend <backend>
+                                       Queue backend name, use prefix '@'
+                                       to append job config to the given
+                                       file path as yaml.
+                                       [default: beanstalk]
   -n <name>, --name <name>             Name of suite run the job is part of
   -d <desc>, --description <desc>      Job description
   -o <owner>, --owner <owner>          Job owner
index 59036f5992b7bf2fda2a62a293042ad49e596586..0de7be36e87cb20576640ba16686260f3a47f285 100644 (file)
@@ -103,6 +103,8 @@ Standard arguments:
 
 Scheduler arguments:
   --owner <owner>             Job owner
+  -b <backend>, --queue-backend <backend>
+                              Scheduler queue backend name
   -e <email>, --email <email>
                               When tests finish or time out, send an email
                               here. May also be specified in ~/.teuthology.yaml
index f8206cf0179578325eaa433174957ba84fd36fbd..01c998367e0b50feb3b1a59e4fdd03198f7005a2 100644 (file)
@@ -1,3 +1,4 @@
+import os
 import yaml
 
 import teuthology.beanstalk
@@ -31,10 +32,16 @@ def main(args):
     if not name or name.isdigit():
         raise ValueError("Please use a more descriptive value for --name")
     job_config = build_config(args)
+    backend = args['--queue-backend']
     if args['--dry-run']:
         print('---\n' + yaml.safe_dump(job_config))
-    else:
+    elif backend == 'beanstalk':
         schedule_job(job_config, args['--num'], report_status)
+    elif backend.startswith('@'):
+        dump_job_to_file(backend.lstrip('@'), job_config, args['--num'])
+    else:
+        raise ValueError("Provided schedule backend '%s' is not supported. "
+                         "Try 'beanstalk' or '@path-to-a-file" % backend)
 
 
 def build_config(args):
@@ -103,3 +110,33 @@ def schedule_job(job_config, num=1, report_status=True):
         if report_status:
             report.try_push_job_info(job_config, dict(status='queued'))
         num -= 1
+
+
+def dump_job_to_file(path, job_config, num=1):
+    """
+    Schedule a job.
+
+    :param job_config: The complete job dict
+    :param num:      The number of times to schedule the job
+    :param path:     The file path where the job config to append
+    """
+    num = int(num)
+    count_file_path = path + '.count'
+
+    jid = 0
+    if os.path.exists(count_file_path):
+        with open(count_file_path, 'r') as f:
+            jid=int(f.read() or '0')
+
+    with open(path, 'a') as f:
+        while num > 0:
+            jid += 1
+            job_config['job_id'] = str(jid)
+            job = yaml.safe_dump(job_config)
+            print('Job scheduled with name {name} and ID {jid}'.format(
+                name=job_config['name'], jid=jid))
+            f.write('---\n' + job)
+            num -= 1
+    with open(count_file_path, 'w') as f:
+        f.write(str(jid))
+
index 1a71404b1339cf5edb01f23df4668e477985834a..63169910bf38085d2dcebc39d3e781f05e4abc79 100644 (file)
@@ -331,6 +331,8 @@ class Run(object):
             base_args.append('-v')
         if self.args.owner:
             base_args.extend(['--owner', self.args.owner])
+        if self.args.queue_backend:
+            base_args.extend(['--queue-backend', self.args.queue_backend])
         return base_args