]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/tasks/workunit: allow passing optional args to workunit
authorKefu Chai <kchai@redhat.com>
Sat, 22 Aug 2020 05:59:19 +0000 (13:59 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 22 Aug 2020 07:26:54 +0000 (15:26 +0800)
* add comment to _run_tests()
* use `os.path.commonpath()` instead using string matching directly
  for matching given workunit spec with executables.
* allow passing optional args to workunit

Signed-off-by: Kefu Chai <kchai@redhat.com>
qa/tasks/workunit.py

index b01ef74a5f70554987be9a7206e11daa77d3663d..5710e34d66aa95501c3a39243fec15a922655c11 100644 (file)
@@ -5,6 +5,7 @@ import logging
 import pipes
 import os
 import re
+import shlex
 
 from tasks.util import get_remote_for_role
 from tasks.util.workunit import get_refspec_after_overrides
@@ -60,6 +61,14 @@ def task(ctx, config):
               BAZ: quux
             timeout: 3h
 
+    You can also pass optional arguments to the found workunits:
+
+        tasks:
+        - workunit:
+            clients:
+              all:
+                - test-ceph-helpers.sh test_get_config
+
     This task supports roles that include a ceph cluster, e.g.::
 
         tasks:
@@ -368,9 +377,12 @@ def _run_tests(ctx, refspec, role, tests, env, basedir,
     try:
         assert isinstance(tests, list)
         for spec in tests:
-            log.info('Running workunits matching %s on %s...', spec, role)
-            prefix = '{spec}/'.format(spec=spec)
-            to_run = [w for w in workunits if w == spec or w.startswith(prefix)]
+            dir_or_fname, *optional_args = shlex.split(spec)
+            log.info('Running workunits matching %s on %s...', dir_or_fname, role)
+            # match executables named "foo" or "foo/*" with workunit named
+            # "foo"
+            to_run = [w for w in workunits
+                      if os.path.commonpath([w, dir_or_fname]) == dir_or_fname]
             if not to_run:
                 raise RuntimeError('Spec did not match any workunits: {spec!r}'.format(spec=spec))
             for workunit in to_run:
@@ -409,7 +421,7 @@ def _run_tests(ctx, refspec, role, tests, env, basedir,
                 ])
                 remote.run(
                     logger=log.getChild(role),
-                    args=args,
+                    args=args + optional_args,
                     label="workunit test {workunit}".format(workunit=workunit)
                 )
                 if cleanup: