]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Create common templates for test zones
authorNicki Křížek <nicki@isc.org>
Fri, 20 Mar 2026 09:09:55 +0000 (10:09 +0100)
committerNicki Křížek <nicki@isc.org>
Thu, 28 May 2026 14:52:24 +0000 (16:52 +0200)
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.

(cherry picked from commit 317cd1277910a2c680a043434ac7f9fa6d8df131)

bin/tests/system/_common/root.hint.conf [new file with mode: 0644]
bin/tests/system/_common/zones.conf.j2 [new file with mode: 0644]
bin/tests/system/_common/zones/delegations.partial.db.j2 [new file with mode: 0644]
bin/tests/system/_common/zones/ns.partial.db.j2 [new file with mode: 0644]
bin/tests/system/_common/zones/root.db.j2.manual [new file with mode: 0644]
bin/tests/system/_common/zones/soa.partial.db.j2 [new file with mode: 0644]
bin/tests/system/_common/zones/template.db.j2.manual [new file with mode: 0644]
bin/tests/system/isctest/template.py

diff --git a/bin/tests/system/_common/root.hint.conf b/bin/tests/system/_common/root.hint.conf
new file mode 100644 (file)
index 0000000..465c5ad
--- /dev/null
@@ -0,0 +1,4 @@
+zone "." {
+       type hint;
+       file "../../_common/root.hint";
+};
diff --git a/bin/tests/system/_common/zones.conf.j2 b/bin/tests/system/_common/zones.conf.j2
new file mode 100644 (file)
index 0000000..27bcb94
--- /dev/null
@@ -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 %}
diff --git a/bin/tests/system/_common/zones/delegations.partial.db.j2 b/bin/tests/system/_common/zones/delegations.partial.db.j2
new file mode 100644 (file)
index 0000000..a44d2ad
--- /dev/null
@@ -0,0 +1,5 @@
+{% if delegations is defined and delegations %}
+{% for zone in delegations %}
+{% include '_common/zones/ns.partial.db.j2' %}
+{% endfor %}
+{% endif %}
diff --git a/bin/tests/system/_common/zones/ns.partial.db.j2 b/bin/tests/system/_common/zones/ns.partial.db.j2
new file mode 100644 (file)
index 0000000..27a2c2e
--- /dev/null
@@ -0,0 +1,2 @@
+@zone.name@.                   NS      @zone.ns.name@.@zone.name@.
+@zone.ns.name@.@zone.name@.                    A       @zone.ns.ip@
diff --git a/bin/tests/system/_common/zones/root.db.j2.manual b/bin/tests/system/_common/zones/root.db.j2.manual
new file mode 100644 (file)
index 0000000..9f4de11
--- /dev/null
@@ -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' %}
diff --git a/bin/tests/system/_common/zones/soa.partial.db.j2 b/bin/tests/system/_common/zones/soa.partial.db.j2
new file mode 100644 (file)
index 0000000..3fae403
--- /dev/null
@@ -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)
+)
diff --git a/bin/tests/system/_common/zones/template.db.j2.manual b/bin/tests/system/_common/zones/template.db.j2.manual
new file mode 100644 (file)
index 0000000..600ffbb
--- /dev/null
@@ -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
index 6f3dd142260377b2fc4a8772413e373694e28362..4562e6da3bc6f9903d502c75dec4bd3b77a9fe62 100644 (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
 import os
 from pathlib import Path
 import re
@@ -161,11 +161,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