From: Nicki Křížek Date: Wed, 1 Apr 2026 15:10:08 +0000 (+0200) Subject: Add a directory-specific nameserver data to templates X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=5cd3e1b6a60102a968f53f5755fe87dd186ade4e;p=thirdparty%2Fbind9.git Add a directory-specific nameserver data to templates If a template is being rendered into a directory that represents a nameserver (e.g. "ns1"), include a nameserver-specific information in the data - variable called "ns" which has information about the nameserver this file belongs to. Ensure the "ns" variable is only exposed to the template when rendered, without affecting the environment variables (always work with a copy of the env_vars). (cherry picked from commit aa435b2e036a668d87579495cae1e31524a97f31) --- diff --git a/bin/tests/system/isctest/template.py b/bin/tests/system/isctest/template.py index f26c7deab9f..b90054e4a5f 100644 --- a/bin/tests/system/isctest/template.py +++ b/bin/tests/system/isctest/template.py @@ -15,12 +15,15 @@ from dataclasses import dataclass import os from pathlib import Path import re +from re import compile as Re from typing import Any, Dict, Optional, Union import pytest from .log import debug +NS_DIR_RE = Re(r"^(a?ns([0-9]+))/") + class TemplateEngine: """ @@ -81,10 +84,16 @@ class TemplateEngine: raise RuntimeError('No jinja2 template found for "{output}"') if data is None: - data = self.env_vars + data = {**self.env_vars} else: data = {**self.env_vars, **data} + # directory-specific "ns" var + assert "ns" not in data, '"ns" variable is reserved for nameserver data' + match = NS_DIR_RE.search(output) + if match: + data["ns"] = Nameserver(match.group(1)) + debug("rendering template `%s` to file `%s`", template, output) stream = self.j2env.get_template(template).stream(data) stream.dump(output, encoding="utf-8")