From 56c86bbb23ce4d2ca3391fab5d66ee4a643f167d Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 22 Aug 2020 13:59:19 +0800 Subject: [PATCH] qa/tasks/workunit: allow passing optional args to workunit * 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 --- qa/tasks/workunit.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/qa/tasks/workunit.py b/qa/tasks/workunit.py index b01ef74a5f705..5710e34d66aa9 100644 --- a/qa/tasks/workunit.py +++ b/qa/tasks/workunit.py @@ -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: -- 2.39.5