xref: /netbsd-src/external/mpl/bind/dist/bin/tests/system/nzd2nzf/tests.sh (revision f8cf1a9151c7af1cb0bd8b09c13c66bca599c027)
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
14set -e
15
16. ../conf.sh
17
18dig_with_opts() {
19  "$DIG" -p "${PORT}" "$@"
20}
21
22rndccmd() {
23  "$RNDC" -c ../_common/rndc.conf -p "${CONTROLPORT}" -s "$@"
24}
25
26status=0
27n=0
28
29n=$((n + 1))
30echo_i "querying for non-existing zone data ($n)"
31ret=0
32dig_with_opts @10.53.0.1 a.added.example a >dig.out.ns1.$n || ret=1
33grep 'status: REFUSED' dig.out.ns1.$n >/dev/null || ret=1
34if [ $ret != 0 ]; then echo_i "failed"; fi
35status=$((status + ret))
36
37n=$((n + 1))
38echo_i "adding a new zone into default NZD using rndc addzone ($n)"
39rndccmd 10.53.0.1 addzone 'added.example { type primary; file "added.db"; };' 2>&1 | sed 's/^/I:ns1 /' | cat_i
40sleep 2
41
42n=$((n + 1))
43echo_i "querying for existing zone data ($n)"
44ret=0
45dig_with_opts @10.53.0.1 a.added.example a >dig.out.ns1.$n || ret=1
46grep 'status: NOERROR' dig.out.ns1.$n >/dev/null || ret=1
47if [ $ret != 0 ]; then echo_i "failed"; fi
48status=$((status + ret))
49
50echo_i "stopping ns1"
51stop_server ns1
52
53n=$((n + 1))
54echo_i "dumping _default.nzd to _default.nzf ($n)"
55$NZD2NZF ns1/_default.nzd >ns1/_default.nzf || ret=1
56if [ $ret != 0 ]; then echo_i "failed"; fi
57status=$((status + ret))
58
59n=$((n + 1))
60echo_i "checking that _default.nzf contains the expected content ($n)"
61grep 'zone "added.example" { type primary; file "added.db"; };' ns1/_default.nzf >/dev/null || ret=1
62if [ $ret != 0 ]; then echo_i "failed"; fi
63status=$((status + ret))
64
65echo_i "deleting _default.nzd database"
66rm -f ns1/_default.nzd
67
68echo_i "starting ns1 which should migrate the .nzf to .nzd"
69start_server --noclean --restart --port ${PORT} ns1
70
71n=$((n + 1))
72echo_i "querying for zone data from migrated zone config ($n)"
73# retry loop in case the server restart above causes transient failures
74_do_query() (
75  dig_with_opts @10.53.0.1 a.added.example a >dig.out.ns1.$n \
76    && grep 'status: NOERROR' dig.out.ns1.$n >/dev/null
77)
78ret=0
79retry_quiet "10" _do_query || ret=1
80n=$((n + 1))
81if [ $ret != 0 ]; then echo_i "failed"; fi
82status=$((status + ret))
83
84echo_i "exit status: $status"
85exit $status
86