From 9fa7d6d86539ff93fca8d336282984dab169512b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicki=20K=C5=99=C3=AD=C5=BEek?= Date: Wed, 10 Sep 2025 11:09:41 +0200 Subject: [PATCH 1/2] Add module-specific python setup to system tests During the system test execution, allow use of module-specific bootstrap() function in addition to the setup.sh script which this function should ultimately replace. The purpose of bootstrap() is two-fold. First, it can execute any commands needed to create the initial conditions for the test, such as creating key materials, manipulating files etc. Second, it should return any test-specific template values as a dictionary. Those will be used to render the jinja2 templates. (cherry picked from commit 7474d3829513d90370e6792dc9ceb68a6738328c) --- .gitlab-ci.yml | 2 +- bin/tests/system/conftest.py | 28 ++++++++++++++++++++-------- bin/tests/system/isctest/template.py | 8 ++++---- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 562393663f..0e3f9fc22d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -649,7 +649,7 @@ vulture: <<: *python_triggering_rules needs: [] script: - - vulture --exclude "*/ans*/ans.py,conftest.py,get_algorithms.py,isctest" --ignore-names "pytestmark" bin/tests/system/ + - vulture --exclude "*/ans*/ans.py,conftest.py,get_algorithms.py,isctest" --ignore-names "bootstrap,pytestmark" bin/tests/system/ ci-variables: <<: *precheck_job diff --git a/bin/tests/system/conftest.py b/bin/tests/system/conftest.py index 2ea55e8aa6..b3b790c11f 100644 --- a/bin/tests/system/conftest.py +++ b/bin/tests/system/conftest.py @@ -656,14 +656,26 @@ def system_test( pytest.skip("Prerequisites missing.") def setup_test(): - templates.render_auto() - try: - shell(f"{system_test_dir}/setup.sh") - except FileNotFoundError: - pass # setup.sh is optional - except subprocess.CalledProcessError as exc: - isctest.log.error("Failed to run test setup") - pytest.fail(f"setup.sh exited with {exc.returncode}") + template_data = None + bootstrap_fn = getattr(request.module, "bootstrap", None) + if bootstrap_fn: + isctest.log.debug("Running test bootstrap()") + try: + template_data = bootstrap_fn() + except Exception as exc: # pylint: disable=broad-exception-caught + isctest.log.error("Failed to run test bootstrap()") + kind = type(exc).__name__ + pytest.fail(f"bootstrap() failed with {kind}") + + templates.render_auto(template_data) + + setup_sh_path = f"{system_test_dir}/setup.sh" + if os.path.exists(setup_sh_path): + try: + shell(f"{system_test_dir}/setup.sh") + except subprocess.CalledProcessError as exc: + isctest.log.error("Failed to run test setup.sh") + pytest.fail(f"setup.sh exited with {exc.returncode}") def start_servers(): try: diff --git a/bin/tests/system/isctest/template.py b/bin/tests/system/isctest/template.py index 123d758ab0..3b175b9709 100644 --- a/bin/tests/system/isctest/template.py +++ b/bin/tests/system/isctest/template.py @@ -87,14 +87,14 @@ class TemplateEngine: stream = self.j2env.get_template(template).stream(data) stream.dump(output, encoding="utf-8") - def render_auto(self): + def render_auto(self, data: Optional[Dict[str, Any]] = None): """ - Render all *.j2 templates with default values and write the output to - files without the .j2 extensions. + Render all *.j2 templates with default (and optionally the provided) + values and write the output to files without the .j2 extensions. """ templates = [ str(filepath.relative_to(self.directory)) for filepath in self.directory.rglob("*.j2") ] for template in templates: - self.render(template[:-3]) + self.render(template[:-3], data) From cd29f31ca3410a2a1fb27d9df7954ca92e0fedfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicki=20K=C5=99=C3=AD=C5=BEek?= Date: Tue, 16 Sep 2025 16:28:24 +0200 Subject: [PATCH 2/2] Use common name for post-startup server functions Unify the names of autouse module-wide fixtures that perform after_servers_start() setup. The consistent naming doesn't just help readability, but also makes it simpler for the vulture exception (since it doesn't properly deal with autouse fixtures). (cherry picked from commit 377724c26d399aa82434bee64f9c7dcf29eab0d7) --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0e3f9fc22d..02e8009a89 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -649,7 +649,7 @@ vulture: <<: *python_triggering_rules needs: [] script: - - vulture --exclude "*/ans*/ans.py,conftest.py,get_algorithms.py,isctest" --ignore-names "bootstrap,pytestmark" bin/tests/system/ + - vulture --exclude "*/ans*/ans.py,conftest.py,get_algorithms.py,isctest" --ignore-names "after_servers_start,bootstrap,pytestmark" bin/tests/system/ ci-variables: <<: *precheck_job