]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
task: add loop 481/head
authorSamuel Just <sjust@redhat.com>
Mon, 4 May 2015 17:41:21 +0000 (10:41 -0700)
committerSamuel Just <sjust@redhat.com>
Mon, 4 May 2015 17:41:21 +0000 (10:41 -0700)
teuthology/task/loop.py [new file with mode: 0644]

diff --git a/teuthology/task/loop.py b/teuthology/task/loop.py
new file mode 100644 (file)
index 0000000..598f561
--- /dev/null
@@ -0,0 +1,44 @@
+"""
+Task to loop a list of items
+"""
+import sys
+import logging
+
+from teuthology import run_tasks
+
+log = logging.getLogger(__name__)
+
+def task(ctx, config):
+    """
+    Loop a sequential group of tasks
+
+    example:
+    - loop:
+       count: 10
+       body:
+         - tasktest:
+         - tasktest:
+
+    :param ctx: Context
+    :param config: Configuration
+    """
+    for i in range(config.get('count', 1)):
+        stack = []
+        try:
+            for entry in config.get('body', []):
+                if not isinstance(entry, dict):
+                    entry = ctx.config.get(entry, {})
+                ((taskname, confg),) = entry.iteritems()
+                log.info('In sequential, running task %s...' % taskname)
+                mgr = run_tasks.run_one_task(taskname, ctx=ctx, config=confg)
+                if hasattr(mgr, '__enter__'):
+                    mgr.__enter__()
+                    stack.append(mgr)
+        finally:
+            try:
+                exc_info = sys.exc_info()
+                while stack:
+                    mgr = stack.pop()
+                    mgr.__exit__(*exc_info)
+            finally:
+                del exc_info