From: Nicki Křížek Date: Fri, 5 Dec 2025 16:04:47 +0000 (+0100) Subject: Use jinja2 templates in staticstub test X-Git-Tag: v9.21.17~46^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=efc302b0ad70d5d949826eadb4c7070b0aeb77ff;p=thirdparty%2Fbind9.git Use jinja2 templates in staticstub test - Instead of strings to be replaced by sed, use proper jinja templates. - ns3/named1.conf.j2 is basically a copy of the default config, because it needs to be restored later in the test. --- diff --git a/bin/tests/system/staticstub/ns1/named.conf.in b/bin/tests/system/staticstub/ns1/named.conf.j2 similarity index 100% rename from bin/tests/system/staticstub/ns1/named.conf.in rename to bin/tests/system/staticstub/ns1/named.conf.j2 diff --git a/bin/tests/system/staticstub/ns2/named.conf.in b/bin/tests/system/staticstub/ns2/named.conf.j2 similarity index 86% rename from bin/tests/system/staticstub/ns2/named.conf.in rename to bin/tests/system/staticstub/ns2/named.conf.j2 index 7ffe39f6b09..1f568da9081 100644 --- a/bin/tests/system/staticstub/ns2/named.conf.in +++ b/bin/tests/system/staticstub/ns2/named.conf.j2 @@ -11,6 +11,8 @@ * information regarding copyright ownership. */ +{% set server_config_use_addr = server_config_use_addr | default(False) %} + key rndc_key { secret "1234abcd8765"; algorithm @DEFAULT_HMAC@; @@ -49,7 +51,11 @@ zone "example" { zone "example.org" { type static-stub; - SERVER_CONFIG_PLACEHOLDER +{% if server_config_use_addr %} + server-addresses { 10.53.0.4; }; +{% else %} + server-names { "ns.example.net"; }; +{% endif %} }; zone "example.info" { diff --git a/bin/tests/system/staticstub/ns2/named2.conf.j2 b/bin/tests/system/staticstub/ns2/named2.conf.j2 new file mode 100644 index 00000000000..04b336459ef --- /dev/null +++ b/bin/tests/system/staticstub/ns2/named2.conf.j2 @@ -0,0 +1,16 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +{% set server_config_use_addr = True %} + +{% include "ns2/named.conf.j2" %} diff --git a/bin/tests/system/staticstub/ns3/named.conf.in b/bin/tests/system/staticstub/ns3/named.conf.j2 similarity index 87% rename from bin/tests/system/staticstub/ns3/named.conf.in rename to bin/tests/system/staticstub/ns3/named.conf.j2 index d6ff10c97a0..690e7199ae6 100644 --- a/bin/tests/system/staticstub/ns3/named.conf.in +++ b/bin/tests/system/staticstub/ns3/named.conf.j2 @@ -11,6 +11,8 @@ * information regarding copyright ownership. */ +{% set example_zone = example_zone | default(True) %} + key rndc_key { secret "1234abcd8765"; algorithm @DEFAULT_HMAC@; @@ -33,7 +35,12 @@ options { notify no; }; -EXAMPLE_ZONE_PLACEHOLDER +{% if example_zone %} +zone "example" { + type primary; + file "example.db.signed"; +}; +{% endif %} zone "example.org" { type primary; diff --git a/bin/tests/system/staticstub/ns3/named1.conf.j2 b/bin/tests/system/staticstub/ns3/named1.conf.j2 new file mode 100644 index 00000000000..d0f4cf00877 --- /dev/null +++ b/bin/tests/system/staticstub/ns3/named1.conf.j2 @@ -0,0 +1,16 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +{% set example_zone = True %} + +{% include "ns3/named.conf.j2" %} diff --git a/bin/tests/system/staticstub/ns3/named2.conf.j2 b/bin/tests/system/staticstub/ns3/named2.conf.j2 new file mode 100644 index 00000000000..b401bbbfb8b --- /dev/null +++ b/bin/tests/system/staticstub/ns3/named2.conf.j2 @@ -0,0 +1,16 @@ +/* + * Copyright (C) Internet Systems Consortium, Inc. ("ISC") + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * See the COPYRIGHT file distributed with this work for additional + * information regarding copyright ownership. + */ + +{% set example_zone = False %} + +{% include "ns3/named.conf.j2" %} diff --git a/bin/tests/system/staticstub/ns4/named.conf.in b/bin/tests/system/staticstub/ns4/named.conf.j2 similarity index 100% rename from bin/tests/system/staticstub/ns4/named.conf.in rename to bin/tests/system/staticstub/ns4/named.conf.j2 diff --git a/bin/tests/system/staticstub/setup.sh b/bin/tests/system/staticstub/setup.sh index 38e2218363d..119cd3d3f92 100755 --- a/bin/tests/system/staticstub/setup.sh +++ b/bin/tests/system/staticstub/setup.sh @@ -13,13 +13,4 @@ . ../conf.sh -copy_setports ns1/named.conf.in ns1/named.conf -copy_setports ns2/named.conf.in tmp -sed 's/SERVER_CONFIG_PLACEHOLDER/server-names { "ns.example.net"; };/' tmp >ns2/named.conf - -copy_setports ns3/named.conf.in tmp -sed 's/EXAMPLE_ZONE_PLACEHOLDER/zone "example" { type primary; file "example.db.signed"; };/' tmp >ns3/named.conf - -copy_setports ns4/named.conf.in ns4/named.conf - cd ns3 && $SHELL -e sign.sh diff --git a/bin/tests/system/staticstub/tests.sh b/bin/tests/system/staticstub/tests.sh index 3d63aab2943..a34df23cdc9 100755 --- a/bin/tests/system/staticstub/tests.sh +++ b/bin/tests/system/staticstub/tests.sh @@ -101,8 +101,7 @@ ret=0 $DIG $DIGOPTS +tcp data1.sub.example. @10.53.0.2 txt >dig.out.ns2.test1.$n || ret=1 grep "1st sub test data" dig.out.ns2.test1.$n >/dev/null || ret=1 # temporarily disable the the parent zone -copy_setports ns3/named.conf.in tmp -sed 's/EXAMPLE_ZONE_PLACEHOLDER//' tmp >ns3/named.conf +cp ns3/named2.conf ns3/named.conf rndc_reload ns3 10.53.0.3 # query the child zone again. this should directly go to the child and # succeed. @@ -113,8 +112,7 @@ for i in 0 1 2 3 4 5 6 7 8 9; do done grep "2nd sub test data" dig.out.ns2.test2.$n >/dev/null || ret=1 # re-enable the parent -copy_setports ns3/named.conf.in tmp -sed 's/EXAMPLE_ZONE_PLACEHOLDER/zone "example" { type primary; file "example.db.signed"; };/' tmp >ns3/named.conf +cp ns3/named1.conf ns3/named.conf rndc_reload ns3 10.53.0.3 if [ $ret != 0 ]; then echo_i "failed"; fi status=$((status + ret)) @@ -193,8 +191,7 @@ status=$((status + ret)) n=$((n + 1)) echo_i "checking server reload with a different static-stub config ($n)" ret=0 -copy_setports ns2/named.conf.in tmp -sed 's/SERVER_CONFIG_PLACEHOLDER/server-addresses { 10.53.0.4; };/' tmp >ns2/named.conf +cp ns2/named2.conf ns2/named.conf rndc_reload ns2 10.53.0.2 $DIG $DIGOPTS +tcp data2.example.org. @10.53.0.2 txt >dig.out.ns2.test$n || ret=1 grep "2nd example org data" dig.out.ns2.test$n >/dev/null || ret=1