xref: /netbsd-src/external/mpl/bind/dist/bin/tests/system/nzd2nzf/tests.sh (revision 3587d6f89c746bbb4f886219ddacd41ace480ecf)
1#!/bin/sh
2
3# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
4#
5# SPDX-License-Identifier: MPL-2.0
6#
7# This Source Code Form is subject to the terms of the Mozilla Public
8# License, v. 2.0.  If a copy of the MPL was not distributed with this
9# file, you can obtain one at https://mozilla.org/MPL/2.0/.
10#
11# See the COPYRIGHT file distributed with this work for additional
12# information regarding copyright ownership.
13
14SYSTEMTESTTOP=..
15. $SYSTEMTESTTOP/conf.sh
16
17DIGOPTS="-p ${PORT}"
18RNDCCMD="$RNDC -c $SYSTEMTESTTOP/common/rndc.conf -p ${CONTROLPORT} -s"
19
20status=0
21n=0
22
23n=`expr $n + 1`
24echo_i "querying for non-existing zone data ($n)"
25ret=0
26$DIG $DIGOPTS @10.53.0.1 a.added.example a > dig.out.ns1.$n || ret=1
27grep 'status: REFUSED' dig.out.ns1.$n > /dev/null || ret=1
28if [ $ret != 0 ]; then echo_i "failed"; fi
29status=`expr $status + $ret`
30
31n=`expr $n + 1`
32echo_i "adding a new zone into default NZD using rndc addzone ($n)"
33$RNDCCMD 10.53.0.1 addzone "added.example { type master; file \"added.db\"; };" 2>&1 | sed 's/^/I:ns1 /' | cat_i
34sleep 2
35
36n=`expr $n + 1`
37echo_i "querying for existing zone data ($n)"
38ret=0
39$DIG $DIGOPTS @10.53.0.1 a.added.example a > dig.out.ns1.$n || ret=1
40grep 'status: NOERROR' dig.out.ns1.$n > /dev/null || ret=1
41if [ $ret != 0 ]; then echo_i "failed"; fi
42status=`expr $status + $ret`
43
44echo_i "stopping ns1"
45stop_server ns1
46
47n=`expr $n + 1`
48echo_i "dumping _default.nzd to _default.nzf ($n)"
49$NZD2NZF ns1/_default.nzd > ns1/_default.nzf || ret=1
50if [ $ret != 0 ]; then echo_i "failed"; fi
51status=`expr $status + $ret`
52
53n=`expr $n + 1`
54echo_i "checking that _default.nzf contains the expected content ($n)"
55grep 'zone "added.example" { type master; file "added.db"; };' ns1/_default.nzf > /dev/null || ret=1
56if [ $ret != 0 ]; then echo_i "failed"; fi
57status=`expr $status + $ret`
58
59echo_i "deleting _default.nzd database"
60rm -f ns1/_default.nzd
61
62echo_i "starting ns1 which should migrate the .nzf to .nzd"
63start_server --noclean --restart --port ${PORT} ns1
64
65n=`expr $n + 1`
66echo_i "querying for zone data from migrated zone config ($n)"
67# retry loop in case the server restart above causes transient failures
68for try in 0 1 2 3 4 5 6 7 8 9; do
69    ret=0
70    $DIG $DIGOPTS @10.53.0.1 a.added.example a > dig.out.ns1.$n || ret=1
71    grep 'status: NOERROR' dig.out.ns1.$n > /dev/null || ret=1
72    [ "$ret" -eq 0 ] && break
73    sleep 1
74done
75n=`expr $n + 1`
76if [ $ret != 0 ]; then echo_i "failed"; fi
77status=`expr $status + $ret`
78
79echo_i "exit status: $status"
80exit $status
81