Create common templates for test zones

Add commonly used zone-related data (config snippet and zone file
snippets) as templates which can be reused by filling in different data.

Adjust the isctest.template.Zone to use filepath argument rather than
filename for clarity.
This commit is contained in:
Nicki Křížek 2026-03-20 10:09:55 +01:00
parent f4ca352bc8
commit 317cd12779
9 changed files with 60 additions and 7 deletions

View file

@ -0,0 +1,4 @@
zone "." {
type hint;
file "../../_common/root.hint";
};

View file

@ -0,0 +1,10 @@
{% if zones is defined and zones %}
{% for zone in zones.values() %}
{% if zone.ns.name == ns.name %}
zone "@zone.name@" {
type @zone.type@;
file "@zone.filepath@";
};
{% endif %}
{% endfor %}
{% endif %}

View file

@ -0,0 +1,5 @@
{% if delegations is defined and delegations %}
{% for zone in delegations %}
{% include '_common/zones/ns.partial.db.j2' %}
{% endfor %}
{% endif %}

View file

@ -0,0 +1,2 @@
@zone.name@. NS @zone.ns.name@.@zone.name@.
@zone.ns.name@.@zone.name@. A @zone.ns.ip@

View file

@ -0,0 +1,13 @@
$TTL 300
. IN SOA . a.root.servers.nil. (
2000042100 ; serial
600 ; refresh
600 ; retry
1200 ; expire
600 ; minimum
)
. NS a.root-servers.nil.
a.root-servers.nil. A 10.53.0.1
{% include '_common/zones/delegations.partial.db.j2' %}

View file

@ -0,0 +1,9 @@
$ORIGIN @zone.name@.
$TTL 300
{% raw %}@{% endraw %} IN SOA @zone.ns.name@.@zone.name@. . (
1 ; serial
20 ; refresh (20 seconds)
20 ; retry (20 seconds)
1814400 ; expire (3 weeks)
3600 ; minimum (1 hour)
)

View file

@ -0,0 +1,7 @@
{% include '_common/zones/soa.partial.db.j2' %}
{% include '_common/zones/ns.partial.db.j2' %}
{% include '_common/zones/delegations.partial.db.j2' %}
a A 10.0.0.1
b A 10.0.0.2
c A 10.0.0.3

View file

@ -11,7 +11,7 @@
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
from dataclasses import dataclass
from dataclasses import dataclass, field
from pathlib import Path
from re import compile as Re
from typing import Any
@ -144,11 +144,12 @@ class Zone:
name: str
ns: Nameserver
type: str = "primary"
filename: str | None = None
filepath: Path | None = field(default=None)
def __post_init__(self):
if self.filename is None:
self.filename = f"{self.name}.db"
def __post_init__(self) -> None:
if self.filepath is None:
base = "root" if self.name == "." else self.name
self.filepath = Path(f"zones/{base}.db")
@dataclass

View file

@ -9,6 +9,8 @@
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.
from pathlib import Path
import shutil
from isctest.kasp import SettimeOptions, private_type_record
@ -50,7 +52,7 @@ def configure_tld(zonename: str, delegations: list[Zone]) -> Zone:
templates.render(f"ns2/{outfile}", tdata, template=f"ns2/{template}")
signer(f"-P -x -O full -o {zonename} -f {outfile}.signed {outfile}", cwd="ns2")
return Zone(zonename, NS2, filename=f"{outfile}.signed")
return Zone(zonename, NS2, filepath=Path(f"{outfile}.signed"))
def configure_root(delegations: list[Zone]) -> TrustAnchor:
@ -1662,7 +1664,7 @@ def configure_straight2none(tld: str) -> list[Zone]:
render_and_sign_zone(zonename, [csk_name], extra_options="-z")
zonename = f"going-straight-to-none-dynamic.{tld}"
zones.append(Zone(zonename, NS3, filename=f"{zonename}.db.signed"))
zones.append(Zone(zonename, NS3, filepath=Path(f"{zonename}.db.signed")))
isctest.log.info(f"setup {zonename}")
# Key generation.
csk_name = keygen(f"-f KSK {keytimes} {zonename}", cwd="ns3").out.strip()