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.

(cherry picked from commit efc302b0ad)
This commit is contained in:
Nicki Křížek 2025-12-05 17:04:47 +01:00
parent a034844b48
commit 8e93a62113
9 changed files with 66 additions and 17 deletions

View file

@ -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" {

View file

@ -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" %}

View file

@ -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;

View file

@ -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" %}

View file

@ -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" %}

View file

@ -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

View file

@ -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