From: Nicki Křížek Date: Thu, 25 Sep 2025 15:30:12 +0000 (+0200) Subject: Use bootstrap() in pytest where applicable X-Git-Tag: v9.21.15~51^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fb4345afd43263f8c4c842e731f9262a75d4f61b;p=thirdparty%2Fbind9.git Use bootstrap() in pytest where applicable 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. --- diff --git a/bin/tests/system/dnssec/tests_badkey_broken.py b/bin/tests/system/dnssec/tests_badkey_broken.py index 8b27e19110a..1471ad0ca29 100644 --- a/bin/tests/system/dnssec/tests_badkey_broken.py +++ b/bin/tests/system/dnssec/tests_badkey_broken.py @@ -11,18 +11,14 @@ 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): diff --git a/bin/tests/system/dnssec/tests_badkey_revoked.py b/bin/tests/system/dnssec/tests_badkey_revoked.py index bc9a422dca3..cb137b26ab1 100644 --- a/bin/tests/system/dnssec/tests_badkey_revoked.py +++ b/bin/tests/system/dnssec/tests_badkey_revoked.py @@ -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(): diff --git a/bin/tests/system/dnssec/tests_validation_accept_expired.py b/bin/tests/system/dnssec/tests_validation_accept_expired.py index 43b44d8cff5..72999a8623c 100644 --- a/bin/tests/system/dnssec/tests_validation_accept_expired.py +++ b/bin/tests/system/dnssec/tests_validation_accept_expired.py @@ -11,15 +11,13 @@ 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): diff --git a/bin/tests/system/dnssec/tests_validation_managed_keys.py b/bin/tests/system/dnssec/tests_validation_managed_keys.py index a72c35ea44f..7cf6e8edbbb 100644 --- a/bin/tests/system/dnssec/tests_validation_managed_keys.py +++ b/bin/tests/system/dnssec/tests_validation_managed_keys.py @@ -12,17 +12,15 @@ 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 diff --git a/bin/tests/system/dnssec/tests_validation_many_anchors.py b/bin/tests/system/dnssec/tests_validation_many_anchors.py index fd6e10eb16c..29b771dcbd6 100644 --- a/bin/tests/system/dnssec/tests_validation_many_anchors.py +++ b/bin/tests/system/dnssec/tests_validation_many_anchors.py @@ -10,27 +10,33 @@ # 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(): diff --git a/bin/tests/system/dnssec/tests_validation_multiview.py b/bin/tests/system/dnssec/tests_validation_multiview.py index a1edf64be09..7c243e90ef5 100644 --- a/bin/tests/system/dnssec/tests_validation_multiview.py +++ b/bin/tests/system/dnssec/tests_validation_multiview.py @@ -12,15 +12,13 @@ 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): diff --git a/bin/tests/system/filters/common.py b/bin/tests/system/filters/common.py index a009d31c0a5..4944775ed13 100644 --- a/bin/tests/system/filters/common.py +++ b/bin/tests/system/filters/common.py @@ -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) diff --git a/bin/tests/system/filters/tests_filter_a_v4.py b/bin/tests/system/filters/tests_filter_a_v4.py index e5aea1bcfb8..e38821b08ba 100644 --- a/bin/tests/system/filters/tests_filter_a_v4.py +++ b/bin/tests/system/filters/tests_filter_a_v4.py @@ -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") diff --git a/bin/tests/system/filters/tests_filter_a_v6.py b/bin/tests/system/filters/tests_filter_a_v6.py index 17e14e8b34d..f077fad5753 100644 --- a/bin/tests/system/filters/tests_filter_a_v6.py +++ b/bin/tests/system/filters/tests_filter_a_v6.py @@ -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") diff --git a/bin/tests/system/filters/tests_filter_aaaa_v4.py b/bin/tests/system/filters/tests_filter_aaaa_v4.py index 90aac2a0cd3..eb232175024 100644 --- a/bin/tests/system/filters/tests_filter_aaaa_v4.py +++ b/bin/tests/system/filters/tests_filter_aaaa_v4.py @@ -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") diff --git a/bin/tests/system/filters/tests_filter_aaaa_v6.py b/bin/tests/system/filters/tests_filter_aaaa_v6.py index a439316677d..e1a4f74cef9 100644 --- a/bin/tests/system/filters/tests_filter_aaaa_v6.py +++ b/bin/tests/system/filters/tests_filter_aaaa_v6.py @@ -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")