osmith has submitted this change. ( https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/38285?usp=email )
Change subject: testenv: improve --config argument parsing ......................................................................
testenv: improve --config argument parsing
* Support using wildcards for the config names via fnmatch as that makes it much easier to run the ggsn tests against all osmo-ggsn config variations, and update the examples in "testenv.py -h" to illustrate this. * Fix that it didn't complain about an invalid --config argument, as long as there was a valid --config argument before it. * Let raise_error_config_arg only output the invalid --config argument instead of all of them. * Complain if "--config all" is used in combination with another --config argument. * Sort testenv*.cfg files found alphabetically, so they are always executed in the same order.
Change-Id: I66b976b0332be523c084a6b5d38d0f62134b495d --- M _testenv/testenv/__init__.py M _testenv/testenv/testdir.py M _testenv/testenv/testenv_cfg.py 3 files changed, 31 insertions(+), 13 deletions(-)
Approvals: laforge: Looks good to me, but someone else must approve pespin: Looks good to me, but someone else must approve Jenkins Builder: Verified fixeria: Looks good to me, approved
diff --git a/_testenv/testenv/__init__.py b/_testenv/testenv/__init__.py index 87485c7..2af83ed 100644 --- a/_testenv/testenv/__init__.py +++ b/_testenv/testenv/__init__.py @@ -43,7 +43,9 @@ " ./testenv.py run mgw --test TC_crcx\n" " ./testenv.py run mgw --podman --binary-repo osmocom:latest\n" " ./testenv.py run mgw --io-uring\n" - " ./testenv.py run bts --config oml\n", + " ./testenv.py run ggsn --config open5gs\n" + " ./testenv.py run ggsn --config 'osmo_ggsn_v4_only'\n" + " ./testenv.py run ggsn --config 'osmo_ggsn*'\n", )
sub = parser.add_subparsers(title="action", dest="action", required=True) @@ -77,7 +79,7 @@ "-c", "--config", action="append", - help="which testenv.cfg to use, in case the testsuite has multiple (e.g. generic|oml|hopping for bts)", + help="which testenv.cfg to use (supports * wildcards via fnmatch)", ) group.add_argument("-i", "--io-uring", action="store_true", help="set LIBOSMO_IO_BACKEND=IO_URING")
diff --git a/_testenv/testenv/testdir.py b/_testenv/testenv/testdir.py index ee698fff..aa0ba47 100644 --- a/_testenv/testenv/testdir.py +++ b/_testenv/testenv/testdir.py @@ -28,7 +28,7 @@
prefix = f"testenv-{testenv.args.testsuite}-" if testenv.args.config: - prefix += f"{'-'.join(testenv.args.config)}-" + prefix += f"{'-'.join(testenv.args.config).replace('*','')}-" if testenv.args.binary_repo: prefix += f"{testenv.args.binary_repo.replace(':','-')}-" prefix += datetime.datetime.now().strftime("%Y%m%d-%H%M") diff --git a/_testenv/testenv/testenv_cfg.py b/_testenv/testenv/testenv_cfg.py index 9642ae8..ba830a1 100644 --- a/_testenv/testenv/testenv_cfg.py +++ b/_testenv/testenv/testenv_cfg.py @@ -1,6 +1,7 @@ # Copyright 2024 sysmocom - s.f.m.c. GmbH # SPDX-License-Identifier: GPL-3.0-or-later import configparser +import fnmatch import glob import logging import os.path @@ -134,14 +135,14 @@ get_vty_host_port(cfg, path)
-def raise_error_config_arg(glob_result): +def raise_error_config_arg(glob_result, config_arg): valid = [] for path in glob_result: basename = os.path.basename(path) if basename != "testenv.cfg": valid += [basename.split("_", 1)[1].split(".", -1)[0]]
- msg = f"Invalid parameter for --config: {testenv.args.config}" + msg = f"Invalid parameter for --config: {config_arg}"
if valid: msg += f" (valid: all, {', '.join(valid)})" @@ -154,7 +155,7 @@ def find_configs(): dir_testsuite = os.path.join(testenv.testsuite.ttcn3_hacks_dir_src, testenv.args.testsuite) pattern = os.path.join(dir_testsuite, "testenv*.cfg") - ret = glob.glob(pattern) + ret = sorted(glob.glob(pattern))
if not ret: logging.error(f"Missing testenv.cfg in: {dir_testsuite}") @@ -185,6 +186,8 @@ def init(): global cfgs
+ cfgs_all = {} + config_paths = find_configs()
for path in config_paths: @@ -201,14 +204,27 @@ handle_latest(cfg, path) verify(cfg, path)
+ # No --config argument given, and there is only one testenv.cfg if not testenv.args.config: cfgs[basename] = cfg - continue + return
- for config_arg in testenv.args.config: - if config_arg == "all" or f"testenv_{config_arg}.cfg" == basename: - cfgs[basename] = cfg - break + cfgs_all[basename] = cfg
- if not cfgs: - raise_error_config_arg(config_paths) + # Select configs based on --config argument(s) + for config_arg in testenv.args.config: + if config_arg == "all": + if len(testenv.args.config) != 1: + raise testenv.NoTraceException("Can't use multiple --config arguments if one of them is 'all'") + cfgs = cfgs_all + return + + matched = False + for basename in cfgs_all: + pattern = f"testenv_{config_arg}.cfg" + if fnmatch.fnmatch(basename, pattern): + matched = True + cfgs[basename] = cfgs_all[basename] + + if not matched: + raise_error_config_arg(config_paths, config_arg)