]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Move schedule() to new schedule module
authorZack Cerza <zack@cerza.org>
Wed, 9 Oct 2013 20:13:01 +0000 (15:13 -0500)
committerZack Cerza <zack@cerza.org>
Fri, 11 Oct 2013 00:09:34 +0000 (19:09 -0500)
scripts/schedule.py
teuthology/run.py
teuthology/schedule.py [new file with mode: 0644]

index ab7d3e23104e191b0f1eba487723bcbc56cf8c2c..6668794958b5937c687ed1df7571df7d6873c622 100644 (file)
@@ -1,8 +1,11 @@
 import argparse
 
-from teuthology.run import config_file
-from teuthology.run import MergeConfig
-from teuthology.run import schedule
+import teuthology.run
+import teuthology.schedule
+
+
+def main():
+    teuthology.schedule.main(parse_args())
 
 
 def parse_args():
@@ -12,8 +15,8 @@ def parse_args():
         'config',
         metavar='CONFFILE',
         nargs='*',
-        type=config_file,
-        action=MergeConfig,
+        type=teuthology.run.config_file,
+        action=teuthology.run.MergeConfig,
         default={},
         help='config file to read',
     )
@@ -85,15 +88,12 @@ def parse_args():
         help='output the contents of specified jobs in the queue',
     )
 
-    return parser.parse_args()
+    args = parser.parse_args()
 
-
-def main():
-    args = parse_args()
     if not args.last_in_suite:
         msg = '--email is only applicable to the last job in a suite'
         assert not args.email, msg
         msg = '--timeout is only applicable to the last job in a suite'
         assert not args.timeout, msg
-    schedule(args)
 
+    return args
index 4c5a71827d0569d4d4ea33d45675f81e9acb956a..5832788295c21a5296cc0b7a74f2d129b940195f 100644 (file)
@@ -282,66 +282,3 @@ def main():
             log.info('FAIL')
             import sys
             sys.exit(1)
-
-
-def schedule(ctx):
-    from teuthology.misc import read_config, get_user
-    if ctx.owner is None:
-        ctx.owner = 'scheduled_{user}'.format(user=get_user())
-    read_config(ctx)
-
-    import teuthology.queue
-    beanstalk = teuthology.queue.connect(ctx)
-
-    tube = ctx.worker
-    beanstalk.use(tube)
-
-    if ctx.show:
-        for job_id in ctx.show:
-            job = beanstalk.peek(job_id)
-            if job is None and ctx.verbose:
-                print 'job {jid} is not in the queue'.format(jid=job_id)
-            else:
-                print '--- job {jid} priority {prio} ---\n'.format(
-                    jid=job_id,
-                    prio=job.stats()['pri']), job.body
-        return
-
-    if ctx.delete:
-        for job_id in ctx.delete:
-            job = beanstalk.peek(job_id)
-            if job is None:
-                print 'job {jid} is not in the queue'.format(jid=job_id)
-            else:
-                job.delete()
-        return
-
-    # strip out targets; the worker will allocate new ones when we run
-    # the job with --lock.
-    if ctx.config.get('targets'):
-        del ctx.config['targets']
-
-    job_config = dict(
-        name=ctx.name,
-        last_in_suite=ctx.last_in_suite,
-        email=ctx.email,
-        description=ctx.description,
-        owner=ctx.owner,
-        verbose=ctx.verbose,
-    )
-    # Merge job_config and ctx.config
-    job_config.update(ctx.config)
-    if ctx.timeout is not None:
-        job_config['results_timeout'] = ctx.timeout
-
-    job = yaml.safe_dump(job_config)
-    num = ctx.num
-    while num > 0:
-        jid = beanstalk.put(
-            job,
-            ttr=60 * 60 * 24,
-            priority=ctx.priority,
-        )
-        print 'Job scheduled with name {name} and ID {jid}'.format(
-            name=ctx.name, jid=jid)
-        num -= 1
diff --git a/teuthology/schedule.py b/teuthology/schedule.py
new file mode 100644 (file)
index 0000000..509ef09
--- /dev/null
@@ -0,0 +1,65 @@
+import yaml
+
+from teuthology.misc import read_config, get_user
+import teuthology.queue
+
+
+def main(ctx):
+    if ctx.owner is None:
+        ctx.owner = 'scheduled_{user}'.format(user=get_user())
+    read_config(ctx)
+
+    beanstalk = teuthology.queue.connect(ctx)
+
+    tube = ctx.worker
+    beanstalk.use(tube)
+
+    if ctx.show:
+        for job_id in ctx.show:
+            job = beanstalk.peek(job_id)
+            if job is None and ctx.verbose:
+                print 'job {jid} is not in the queue'.format(jid=job_id)
+            else:
+                print '--- job {jid} priority {prio} ---\n'.format(
+                    jid=job_id,
+                    prio=job.stats()['pri']), job.body
+        return
+
+    if ctx.delete:
+        for job_id in ctx.delete:
+            job = beanstalk.peek(job_id)
+            if job is None:
+                print 'job {jid} is not in the queue'.format(jid=job_id)
+            else:
+                job.delete()
+        return
+
+    # strip out targets; the worker will allocate new ones when we run
+    # the job with --lock.
+    if ctx.config.get('targets'):
+        del ctx.config['targets']
+
+    job_config = dict(
+        name=ctx.name,
+        last_in_suite=ctx.last_in_suite,
+        email=ctx.email,
+        description=ctx.description,
+        owner=ctx.owner,
+        verbose=ctx.verbose,
+    )
+    # Merge job_config and ctx.config
+    job_config.update(ctx.config)
+    if ctx.timeout is not None:
+        job_config['results_timeout'] = ctx.timeout
+
+    job = yaml.safe_dump(job_config)
+    num = ctx.num
+    while num > 0:
+        jid = beanstalk.put(
+            job,
+            ttr=60 * 60 * 24,
+            priority=ctx.priority,
+        )
+        print 'Job scheduled with name {name} and ID {jid}'.format(
+            name=ctx.name, jid=jid)
+        num -= 1