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