4de05ba9620e6634435c189871c6bcb9577af4d2
[tridge/bind9.git] / bin / tests / system / nsupdate / tests.sh
1 #!/bin/sh
2 #
3 # Copyright (C) 2004, 2007, 2009  Internet Systems Consortium, Inc. ("ISC")
4 # Copyright (C) 2000, 2001  Internet Software Consortium.
5 #
6 # Permission to use, copy, modify, and/or distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
9 #
10 # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 # AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 # PERFORMANCE OF THIS SOFTWARE.
17
18 # $Id: tests.sh,v 1.28 2009/09/04 17:14:58 each Exp $
19
20 SYSTEMTESTTOP=..
21 . $SYSTEMTESTTOP/conf.sh
22
23 status=0
24
25 # wait for zone transfer to complete
26 tries=0
27 while true; do
28     if [ $tries -eq 10 ]
29     then
30         exit 1
31     fi
32
33     if grep "example.nil/IN.*Transfer completed" ns2/named.run > /dev/null
34     then
35         break
36     else
37         echo "I:zones are not fully loaded, waiting..."
38         tries=`expr $tries + 1`
39         sleep 1
40     fi
41 done
42
43 echo "I:fetching first copy of zone before update"
44 $DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd example.nil.\
45         @10.53.0.1 axfr -p 5300 > dig.out.ns1 || status=1
46
47 echo "I:fetching second copy of zone before update"
48 $DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd example.nil.\
49         @10.53.0.2 axfr -p 5300 > dig.out.ns2 || status=1
50
51 echo "I:comparing pre-update copies to known good data"
52 $PERL ../digcomp.pl knowngood.ns1.before dig.out.ns1 || status=1
53 $PERL ../digcomp.pl knowngood.ns1.before dig.out.ns2 || status=1
54
55 echo "I:updating zone"
56 # nsupdate will print a ">" prompt to stdout as it gets each input line.
57 $NSUPDATE -k ns1/ddns.key <<END > /dev/null || status=1
58 server 10.53.0.1 5300
59 update add updated.example.nil. 600 A 10.10.10.1
60 update add updated.example.nil. 600 TXT Foo
61 update delete t.example.nil.
62
63 END
64 echo "I:sleeping 15 seconds for server to incorporate changes"
65 sleep 15
66
67 echo "I:fetching first copy of zone after update"
68 $DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd example.nil.\
69         @10.53.0.1 axfr -p 5300 > dig.out.ns1 || status=1
70
71 echo "I:fetching second copy of zone after update"
72 $DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd example.nil.\
73         @10.53.0.2 axfr -p 5300 > dig.out.ns2 || status=1
74
75 echo "I:comparing post-update copies to known good data"
76 $PERL ../digcomp.pl knowngood.ns1.after dig.out.ns1 || status=1
77 $PERL ../digcomp.pl knowngood.ns1.after dig.out.ns2 || status=1
78
79 echo "I:testing local update policy"
80 pre=`$DIG +short new.other.nil. @10.53.0.1 a -p 5300` || status=1
81 [ -z "$pre" ] || status=1
82
83 echo "I:updating zone"
84 # nsupdate will print a ">" prompt to stdout as it gets each input line.
85 $NSUPDATE -l -p 5300 -k ns1/session.key > /dev/null <<END || status=1
86 zone other.nil.
87 update add new.other.nil. 600 IN A 10.10.10.1
88 send
89 END
90
91 echo "I:sleeping 5 seconds for server to incorporate changes"
92 sleep 5
93
94 echo "I:checking result of update"
95 post=`$DIG +short new.other.nil. @10.53.0.1 a -p 5300` || status=1
96 [ "$post" = "10.10.10.1" ] || status=1
97
98 echo "I:comparing post-update copy to known good data"
99 $PERL ../digcomp.pl knowngood.ns1.after dig.out.ns1 || status=1
100
101 if $PERL -e 'use Net::DNS;' 2>/dev/null
102 then
103     echo "I:running update.pl test"
104     $PERL update_test.pl -s 10.53.0.1 -p 5300 update.nil. || status=1
105 else
106     echo "I:The second part of this test requires the Net::DNS library." >&2
107 fi
108
109 echo "I:fetching first copy of test zone"
110 $DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd example.nil.\
111         @10.53.0.1 axfr -p 5300 > dig.out.ns1 || status=1
112
113 echo "I:fetching second copy of test zone"
114 $DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd example.nil.\
115         @10.53.0.2 axfr -p 5300 > dig.out.ns2 || status=1
116
117 echo "I:comparing zones"
118 $PERL ../digcomp.pl dig.out.ns1 dig.out.ns2 || status=1
119
120 echo "I:SIGKILL and restart server ns1"
121 cd ns1
122 kill -KILL `cat named.pid`
123 rm named.pid
124 cd ..
125 sleep 10
126 if 
127         $PERL $SYSTEMTESTTOP/start.pl --noclean . ns1
128 then
129         echo "I:restarted server ns1"   
130 else
131         echo "I:could not restart server ns1"
132         exit 1
133 fi
134 sleep 10
135
136 echo "I:fetching ns1 after hard restart"
137 $DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd example.nil.\
138         @10.53.0.1 axfr -p 5300 > dig.out.ns1.after || status=1
139
140 echo "I:comparing zones"
141 $PERL ../digcomp.pl dig.out.ns1 dig.out.ns1.after || status=1
142
143 echo "I:begin RT #482 regression test"
144
145 echo "I:update master"
146 $NSUPDATE -k ns1/ddns.key <<END > /dev/null || status=1
147 server 10.53.0.1 5300
148 update add updated2.example.nil. 600 A 10.10.10.2
149 update add updated2.example.nil. 600 TXT Bar
150 update delete c.example.nil.
151 send
152 END
153
154 sleep 5
155
156 echo "I:SIGHUP slave"
157 kill -HUP `cat ns2/named.pid`
158
159 sleep 5
160
161 echo "I:update master again"
162 $NSUPDATE -k ns1/ddns.key <<END > /dev/null || status=1
163 server 10.53.0.1 5300
164 update add updated3.example.nil. 600 A 10.10.10.3
165 update add updated3.example.nil. 600 TXT Zap
166 update delete d.example.nil.
167 send
168 END
169
170 sleep 5
171
172 echo "I:SIGHUP slave again"
173 kill -HUP `cat ns2/named.pid`
174
175 sleep 5
176
177 if grep "out of sync" ns2/named.run
178 then
179         status=1
180 fi
181
182 echo "I:end RT #482 regression test"
183
184 echo "I:testing that rndc stop updates the master file"
185 $NSUPDATE -k ns1/ddns.key <<END > /dev/null || status=1
186 server 10.53.0.1 5300
187 update add updated4.example.nil. 600 A 10.10.10.3
188 send
189 END
190 $PERL $SYSTEMTESTTOP/stop.pl --use-rndc . ns1
191 # Removing the journal file and restarting the server means
192 # that the data served by the new server process are exactly
193 # those dumped to the master file by "rndc stop".
194 rm -f ns1/*jnl
195 $PERL $SYSTEMTESTTOP/start.pl --noclean . ns1
196 $DIG +tcp +noadd +nosea +nostat +noquest +nocomm +nocmd updated4.example.nil.\
197         @10.53.0.1 a -p 5300 > dig.out.ns1 || status=1
198 $PERL ../digcomp.pl knowngood.ns1.afterstop dig.out.ns1 || status=1
199
200 echo "I:exit status: $status"
201 exit $status