mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-11 08:59:59 -04:00
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 7474d38295)
This commit is contained in:
parent
6364ec5f52
commit
c322f2dde7
3 changed files with 25 additions and 13 deletions
|
|
@ -695,7 +695,7 @@ vulture:
|
|||
<<: *python_triggering_rules
|
||||
needs: []
|
||||
script:
|
||||
- vulture --exclude "*ans.py,conftest.py,isctest" --ignore-names "pytestmark,reconfigure_policy,setup_filters" bin/tests/system/
|
||||
- vulture --exclude "*ans.py,conftest.py,isctest" --ignore-names "bootstrap,pytestmark,reconfigure_policy,setup_filters" bin/tests/system/
|
||||
|
||||
ci-variables:
|
||||
<<: *precheck_job
|
||||
|
|
|
|||
|
|
@ -555,14 +555,26 @@ def system_test(
|
|||
pytest.skip("Prerequisites missing.")
|
||||
|
||||
def setup_test():
|
||||
templates.render_auto()
|
||||
try:
|
||||
isctest.run.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:
|
||||
isctest.run.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:
|
||||
|
|
|
|||
|
|
@ -68,14 +68,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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue