]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use bootstrap() in pytest where applicable
authorNicki Křížek <nicki@isc.org>
Thu, 25 Sep 2025 15:30:12 +0000 (17:30 +0200)
committerNicki Křížek <nicki@isc.org>
Tue, 21 Oct 2025 13:07:49 +0000 (15:07 +0200)
Replace the autouse fixtures which were only used to change the initial
server configuration into proper bootstrap() functions. This gets rid of
an extraneous reconfigure.

In the tests_validation_many_anchors.py, split the fixture into a proper
bootstrap() and a separate test for checking the expected log lines for
the ignored keys. Previously, the test was broken - it should check for
all the messages being present in the log, and some of the keys are
actually initial-key rather than static-key. This has been fixed in the
parametrized test.

bin/tests/system/dnssec/tests_badkey_broken.py
bin/tests/system/dnssec/tests_badkey_revoked.py
bin/tests/system/dnssec/tests_validation_accept_expired.py
bin/tests/system/dnssec/tests_validation_managed_keys.py
bin/tests/system/dnssec/tests_validation_many_anchors.py
bin/tests/system/dnssec/tests_validation_multiview.py
bin/tests/system/filters/common.py
bin/tests/system/filters/tests_filter_a_v4.py
bin/tests/system/filters/tests_filter_a_v6.py
bin/tests/system/filters/tests_filter_aaaa_v4.py
bin/tests/system/filters/tests_filter_aaaa_v6.py

index 8b27e19110aa196a14de93ca3ee977a60ec54d9a..1471ad0ca295378a0645d041e80ba843da8d0b7c 100644 (file)
 
 from dns import flags
 
-import pytest
-
 import isctest
 
 
-@pytest.fixture(scope="module", autouse=True)
-def reconfigure(ns5, ns9, templates):
-    templates.render("ns5/named.conf", {"broken_key": True})
-    ns5.reconfigure(log=False)
-
-    templates.render("ns9/named.conf", {"forward_badkey": True})
-    ns9.reconfigure(log=False)
+def bootstrap():
+    return {
+        "broken_key": True,
+        "forward_badkey": True,
+    }
 
 
 def test_broken_forwarding(ns9):
index bc9a422dca3b820a803652921a4f9ad33d31d439..cb137b26ab1bc9b917f5f516cd708d37eccbd0c0 100644 (file)
@@ -9,15 +9,13 @@
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
-import pytest
-
 import isctest
 
 
-@pytest.fixture(scope="module", autouse=True)
-def reconfigure(ns5, templates):
-    templates.render("ns5/named.conf", {"revoked_key": True})
-    ns5.reconfigure(log=False)
+def bootstrap():
+    return {
+        "revoked_key": True,
+    }
 
 
 def test_revoked_init():
index 43b44d8cff54ee169dd0a115af358d085d384fe2..72999a8623cb3c0910bce3161ee3f5d4f999564d 100644 (file)
 
 from dns import flags
 
-import pytest
-
 import isctest
 
 
-@pytest.fixture(scope="module", autouse=True)
-def reconfigure(ns4, templates):
-    templates.render("ns4/named.conf", {"accept_expired": True})
-    ns4.reconfigure(log=False)
+def bootstrap():
+    return {
+        "accept_expired": True,
+    }
 
 
 def test_accept_expired(ns4):
index a72c35ea44fa89d721e9bea330b11caf181ed77e..7cf6e8edbbb04f9b13f21216cbb210a645ff055f 100644 (file)
 import os
 import shutil
 
-import pytest
-
 import isctest
 
 
-@pytest.fixture(scope="module", autouse=True)
-def reconfigure(ns4, templates):
-    assert os.path.exists("ns4/managed-keys.bind.jnl") is False
+def bootstrap():
+    assert not os.path.exists("ns4/managed-keys.bind.jnl")
     shutil.copyfile("ns4/managed-keys.bind.in", "ns4/managed-keys.bind")
-    templates.render("ns4/named.conf", {"managed_key": True})
-    ns4.reconfigure(log=False)
+    return {
+        "managed_key": True,
+    }
 
 
 # helper functions
index fd6e10eb16cc14206d6fba4b3c3e885fa7b643e5..29b771dcbd6380227dad642a62da4aaa540f21e5 100644 (file)
 # information regarding copyright ownership.
 
 from dns import edns
+
 import pytest
 
 import isctest
-
-
-@pytest.fixture(scope="module", autouse=True)
-def reconfigure(ns5, templates):
-    templates.render("ns5/named.conf", {"many_anchors": True})
-    with ns5.watch_log_from_here() as watcher:
-        ns5.reconfigure(log=False)
-        watcher.wait_for_line(
-            [
-                "ignoring static-key for 'disabled.trusted.': algorithm is disabled",
-                "ignoring static-key for 'disabled.managed.': algorithm is disabled",
-                "ignoring static-key for 'unsupported.trusted.': algorithm is unsupported",
-                "ignoring static-key for 'unsupported.managed.': algorithm is unsupported",
-                "ignoring static-key for 'unsupported.managed.': algorithm is unsupported",
-                "ignoring static-key for 'revoked.trusted.': bad key type",
-                "ignoring static-key for 'revoked.managed.': bad key type",
-            ]
-        )
+from isctest.util import param
+
+
+def bootstrap():
+    return {
+        "many_anchors": True,
+    }
+
+
+@pytest.mark.parametrize(
+    "zone, keytype, msg",
+    [
+        param("disabled.trusted.", "static-key", "algorithm is disabled"),
+        param("disabled.managed.", "initial-key", "algorithm is disabled"),
+        param("unsupported.trusted.", "static-key", "algorithm is unsupported"),
+        param("unsupported.managed.", "initial-key", "algorithm is unsupported"),
+        param("revoked.trusted.", "static-key", "bad key type"),
+        param("revoked.managed.", "initial-key", "bad key type"),
+    ],
+)
+def test_log_ignoring_key(zone, keytype, msg, ns5):
+    with ns5.watch_log_from_start() as watcher:
+        watcher.wait_for_line(f"ignoring {keytype} for '{zone}': {msg}")
 
 
 def test_trust_anchors():
index a1edf64be099b0e76cf2e904d6f0d30a263f21bb..7c243e90ef55cfb68fd36558a8dfe7c87778955e 100644 (file)
 import os
 import re
 
-import pytest
-
 import isctest
 
 
-@pytest.fixture(scope="module", autouse=True)
-def reconfigure(ns4, templates):
-    templates.render("ns4/named.conf", {"multi_view": True})
-    ns4.reconfigure(log=False)
+def bootstrap():
+    return {
+        "multi_view": True,
+    }
 
 
 def getfrom(file):
index a009d31c0a556809e03b764972333a75e6f6250e..4944775ed13cce5e14559eb4fc1ae9d8f26651a2 100644 (file)
@@ -25,14 +25,6 @@ ARTIFACTS = [
 ]
 
 
-def reconfigure_servers(ftype, family, servers, templates):
-    for server_id in ["ns1", "ns2", "ns3", "ns4"]:
-        templates.render(
-            f"{server_id}/named.conf", {"family": family, "filtertype": ftype}
-        )
-        servers[server_id].reconfigure(log=False)
-
-
 def check_filtertype_only(dest, source, qname, ftype, expected, adflag):
     qname = dns.name.from_text(qname)
 
index e5aea1bcfb86312ae7e42bc0a58b71e7791c51a3..e38821b08ba149afb9f5e6d18f2febeff1c6fa11 100644 (file)
@@ -18,17 +18,21 @@ from filters.common import (
     check_filter,
     check_filter_other_family,
     prime_cache,
-    reconfigure_servers,
 )
 
 
 pytestmark = pytest.mark.extra_artifacts(ARTIFACTS)
 
 
+def bootstrap():
+    return {
+        "family": "v4",
+        "filtertype": "a",
+    }
+
+
 @pytest.fixture(scope="module", autouse=True)
-def setup_filters(servers, templates):
-    isctest.log.info("configuring server to filter A on V4")
-    reconfigure_servers("a", "v4", servers, templates)
+def setup_filters():
     prime_cache("10.53.0.2")
     prime_cache("10.53.0.3")
 
index 17e14e8b34d25e3b8aedb3c7900567dd68718b42..f077fad575349c657d5eb1e18e88228e063508f7 100644 (file)
@@ -18,17 +18,21 @@ from filters.common import (
     check_filter,
     check_filter_other_family,
     prime_cache,
-    reconfigure_servers,
 )
 
 
 pytestmark = pytest.mark.extra_artifacts(ARTIFACTS)
 
 
+def bootstrap():
+    return {
+        "family": "v6",
+        "filtertype": "a",
+    }
+
+
 @pytest.fixture(scope="module", autouse=True)
-def setup_filters(servers, templates):
-    isctest.log.info("configuring server to filter A on V6")
-    reconfigure_servers("a", "v6", servers, templates)
+def setup_filters():
     prime_cache("fd92:7065:b8e:ffff::2")
     prime_cache("fd92:7065:b8e:ffff::3")
 
index 90aac2a0cd3bacd41a9b57ee78f21e53bfeaf201..eb232175024f5f6001f6115ade214f0ae885b88c 100644 (file)
@@ -19,17 +19,21 @@ from filters.common import (
     check_filter,
     check_filter_other_family,
     prime_cache,
-    reconfigure_servers,
 )
 
 
 pytestmark = pytest.mark.extra_artifacts(ARTIFACTS)
 
 
+def bootstrap():
+    return {
+        "family": "v4",
+        "filtertype": "aaaa",
+    }
+
+
 @pytest.fixture(scope="module", autouse=True)
-def setup_filters(servers, templates):
-    isctest.log.info("configuring server to filter AAAA on V4")
-    reconfigure_servers("aaaa", "v4", servers, templates)
+def setup_filters():
     prime_cache("10.53.0.2")
     prime_cache("10.53.0.3")
 
index a439316677d3be655c062a7c913dd81e553e1320..e1a4f74cef9ed14dde2d3537c1ce8577836fc310 100644 (file)
@@ -18,17 +18,21 @@ from filters.common import (
     check_filter,
     check_filter_other_family,
     prime_cache,
-    reconfigure_servers,
 )
 
 
 pytestmark = pytest.mark.extra_artifacts(ARTIFACTS)
 
 
+def bootstrap():
+    return {
+        "family": "v6",
+        "filtertype": "aaaa",
+    }
+
+
 @pytest.fixture(scope="module", autouse=True)
-def setup_filters(servers, templates):
-    isctest.log.info("configuring server to filter AAAA on V6")
-    reconfigure_servers("aaaa", "v6", servers, templates)
+def setup_filters():
     prime_cache("fd92:7065:b8e:ffff::2")
     prime_cache("fd92:7065:b8e:ffff::3")