]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
qa: add sequential_yield task
authorPatrick Donnelly <pdonnell@ibm.com>
Wed, 26 Mar 2025 01:53:08 +0000 (21:53 -0400)
committerPatrick Donnelly <pdonnell@ibm.com>
Wed, 1 Oct 2025 18:47:12 +0000 (14:47 -0400)
This is identical to the sequential task except it yields after entering each
sub-task.

Signed-off-by: Patrick Donnelly <pdonnell@ibm.com>
qa/tasks/sequential_yield.py [new file with mode: 0644]

diff --git a/qa/tasks/sequential_yield.py b/qa/tasks/sequential_yield.py
new file mode 100644 (file)
index 0000000..bc963c7
--- /dev/null
@@ -0,0 +1,61 @@
+"""
+Task sequencer
+"""
+import contextlib
+import sys
+import logging
+
+from teuthology import run_tasks
+
+log = logging.getLogger(__name__)
+
+
+@contextlib.contextmanager
+def task(ctx, config):
+    """
+    Sequentialize a group of tasks into one executable block
+
+    example::
+
+        - sequential:
+           - tasktest:
+           - tasktest:
+
+    You can also reference the job from elsewhere::
+
+        foo:
+          tasktest:
+        tasks:
+        - sequential:
+          - tasktest:
+          - foo
+          - tasktest:
+
+    That is, if the entry is not a dict, we will look it up in the top-level
+    config.
+
+    Sequential tasks and Parallel tasks can be nested.
+
+    :param ctx: Context
+    :param config: Configuration
+    """
+    stack = []
+    try:
+        for entry in config:
+            if not isinstance(entry, dict):
+                entry = ctx.config.get(entry, {})
+            ((taskname, confg),) = entry.items()
+            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)
+        yield # !!
+    finally:
+        try:
+            exc_info = sys.exc_info()
+            while stack:
+                mgr = stack.pop()
+                mgr.__exit__(*exc_info)
+        finally:
+            del exc_info