]> git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests/start-test-stop
Merge pull request #7087 from phonedph1/dynpool
[thirdparty/pdns.git] / regression-tests / start-test-stop
1 #!/usr/bin/env bash
2 set -e
3 if [ "${PDNS_DEBUG}" = "YES" ]; then
4 set -x
5 fi
6
7 export PDNS=${PDNS:-${PWD}/../pdns/pdns_server}
8 export PDNS2=${PDNS2:-${PWD}/../pdns/pdns_server}
9 export PDNSRECURSOR=${PDNSRECURSOR:-${PWD}/../pdns/recursordist/pdns_recursor}
10 export RECCONTROL=${RECCONTROL:-${PWD}/../pdns/recursordist/rec_control}
11 export SDIG=${SDIG:-${PWD}/../pdns/sdig}
12 export NOTIFY=${NOTIFY:-${PWD}/../pdns/pdns_notify}
13 export NSEC3DIG=${NSEC3DIG:-${PWD}/../pdns/nsec3dig}
14 export SAXFR=${SAXFR:-${PWD}/../pdns/saxfr}
15 export ZONE2SQL=${ZONE2SQL:-${PWD}/../pdns/zone2sql}
16 export ZONE2LDAP=${ZONE2LDAP:-${PWD}/../pdns/zone2ldap}
17 export PDNSUTIL=${PDNSUTIL:-${PWD}/../pdns/pdnsutil}
18 export PDNSCONTROL=${PDNSCONTROL:-${PWD}/../pdns/pdns_control}
19
20
21 ALGORITHM=${ALGORITHM:="hmac-md5"}
22 KEY=${KEY:="kp4/24gyYsEzbuTVJRUMoqGFmN3LYgVDzJ/3oRSP7ys="}
23
24 MAKE=${MAKE:-make}
25
26 export ALGORITHM
27 export KEY
28
29 trap "kill_process 2" EXIT INT TERM
30
31 source ../regression-tests/common
32
33 bindwait ()
34 {
35 check_process
36 configname=$1
37 domcount=$(grep -c ^zone named.conf)
38 if [ ! -x $PDNSCONTROL ]
39 then
40 echo "No pdns_control found"
41 exit
42 fi
43 loopcount=0
44
45 while [ $loopcount -lt 20 ]
46 do
47 sleep 5
48 done=$( ($PDNSCONTROL --config-name=$configname --socket-dir=. --no-config bind-domain-status || true) | grep -c 'parsed into memory' || true )
49 if [ $done = $domcount ]
50 then
51 return
52 fi
53 let loopcount=loopcount+1
54 done
55
56 if [ $done != $domcount ]
57 then
58 echo "Domain parsing failed" >> failed_tests
59 fi
60 }
61
62 securezone ()
63 {
64 local zone=$1
65 local configname=$2
66
67 if [ -n "$configname" ]
68 then
69 configname="--config-name=$configname"
70 fi
71 if [ "${zone: 0:16}" = "secure-delegated" ]
72 then
73 $PDNSUTIL --config-dir=. $configname import-zone-key $zone $zone.private ksk 2>&1
74 $PDNSUTIL --config-dir=. $configname add-zone-key $zone rsasha256 1024 zsk active 2>&1
75 $PDNSUTIL --config-dir=. $configname rectify-zone $zone 2>&1
76 $PDNSUTIL --config-dir=. $configname set-publish-cds $zone 2>&1
77 $PDNSUTIL --config-dir=. $configname set-publish-cdnskey $zone 2>&1
78 else
79 # check if PKCS#11 should be used
80 if [ "$pkcs11" -eq 1 ]; then
81 if [ "$slot" == "" ]; then
82 slot=0
83 else
84 slot=$((slot+1))
85 fi
86 sudo softhsm --init-token --slot $slot --label label$slot --pin 123$slot --so-pin 123$slot
87 kid=`$PDNSUTIL --config-dir=. $configname hsm assign $zone ecdsa256 zsk softhsm label$slot 123$slot label$slot 2>&1 | grep softhsm | awk '{ print $NF }'`
88 kid=`$PDNSUTIL --config-dir=. $configname show-zone $zone | grep 'ID =.*ZSK' | awk '{ print $3 }'`
89 $PDNSUTIL --config-dir=. $configname hsm create-key $zone $kid
90 else
91 $PDNSUTIL --config-dir=. $configname secure-zone $zone 2>&1
92 if [ "${zone: 0:20}" = "cdnskey-cds-test.com" ]; then
93 $PDNSUTIL --config-dir=. $configname set-publish-cds $zone 2>&1
94 $PDNSUTIL --config-dir=. $configname set-publish-cdnskey $zone 2>&1
95 fi
96 fi
97 fi
98 }
99
100 kill_process ()
101 {
102 set +e
103 trap - EXIT INT TERM
104
105 if [ $1 -gt 1 ]
106 then
107 echo "exitvalue$1" >> failed_tests
108 ./toxml
109 ./totar
110 fi
111
112 pids=$(cat pdns*.pid)
113
114 if [ -n "$pids" ]
115 then
116 kill $pids
117 # make sure they die.
118 loopcount=0
119 done=0
120 while [ $loopcount -lt 10 ] && [ $done -eq 0 ]
121 do
122 done=1
123 for pid in $pids
124 do
125 kill -0 $pid > /dev/null 2>&1
126 if [ $? -eq 0 ];
127 then
128 done=0
129 fi
130 done
131 let loopcount=loopcount+1
132 sleep 1
133 done
134
135 kill -9 $pids
136 fi
137
138 rm pdns*.pid
139 exit $1
140 }
141
142 if [ ! -x $PDNS ]
143 then
144 echo "$PDNS is not executable binary"
145 exit
146 fi
147
148 if [ ! -x $PDNS2 ]
149 then
150 echo "$PDNS2 is not executable binary"
151 exit
152 fi
153
154 address="${PDNS_LISTEN_ADDR:-127.0.0.1}"
155 port=$1
156 [ -z "$port" ] && port=5300
157 context=$2
158 [ -z "$context" ] && context=bind-dnssec
159 wait=$3
160 [ -z "$wait" ] && wait=nowait
161 cachettl=$4
162 [ -z "$cachettl" ] && cachettl=0
163 spectest=$5
164
165 testsdir=./tests
166
167 if [ "$port" = help ] || [ "$context" = help ] || [ "$port" = "--help" ] || [ "$context" = "--help" ]
168 then
169 set +x
170 grep -v '^#' << '__EOF__'
171
172 Usage: ./start-test-stop <port> [<context>] [wait|nowait] [<cachettl>] [<specifictest>]
173
174 context is one of:
175 bind bind-dnssec bind-dnssec-nsec3 bind-dnssec-nsec3-optout bind-dnssec-nsec3-narrow
176 geoip geoip-nsec3-narrow
177 gmysql-nodnssec gmysql gmysql-nsec3 gmysql-nsec3-optout gmysql-nsec3-narrow
178 godbc_mssql-nodnssec godbc_mssql godbc_mssql-nsec3 godbc_mssql-nsec3-optout godbc_mssql-nsec3-narrow
179 goracle-nodnssec goracle goracle-nsec3 goracle-nsec3-optout goracle-nsec3-narrow
180 godbc_sqlite3-nodnssec godbc_sqlite3 godbc_sqlite3-nsec3 godbc_sqlite3-nsec3-optout godbc_sqlite3-narrow
181 gpgsql-nodnssec gpgsql gpgsql-nsec3 gpgsql-nsec3-optout gpgsql-nsec3-narrow
182 gsqlite3-nodnssec gsqlite3 gsqlite3-nsec3 gsqlite3-nsec3-optout gsqlite3-nsec3-narrow
183 mydns
184 opendbx-sqlite3
185 oracle-nodnssec oracle oracle-nsec3
186 remotebackend-pipe remotebackend-unix remotebackend-http remotebackend-zeromq
187 remotebackend-pipe-dnssec remotebackend-unix-dnssec remotebackend-http-dnssec remotebackend-zeromq-dnssec
188 #remotebackend-pipe-nsec3 remotebackend-unix-nsec3 remotebackend-http-nsec3
189 #remotebackend-pipe-nsec3-narrow remotebackend-unix-nsec3-narrow remotebackend-http-nsec3-narrow
190 tinydns
191 ldap-tree ldap-simple ldap-strict
192 lua2 lua2-dnssec lua2-nsec3 lua2-nsec3-narrow
193 #ext-nsd ext-nsd-nsec ext-nsd-nsec3 ext-bind ext-bind-nsec ext-bind-nsec3
194
195 * Add -presigned to any ext-nsd, ext-bind, bind, gmysql or gsqlite3 test (except narrow)
196 to test presigned operation.
197
198 * Add -both to any bind or gmysql test (except narrow) to
199 test normal and presigned operation.
200
201 * Add 'wait' (literally) after the context to not kill
202 pdns_server immediately after testing. 'nowait' will kill it.
203
204 * A cachettl can be supplied if you want to run tests with a
205 ttl setting set. The default cachettl is 0.
206
207 * Specifictest can be used to run only one single test.
208 __EOF__
209 exit
210 fi
211
212 for prog in $SDIG $SAXFR $NOTIFY $NSEC3DIG; do
213 if `echo $prog | grep -q '\.\./pdns'`; then
214 ${MAKE} -C ../pdns ${prog##*../pdns/} || exit
215 fi
216 done
217
218 # Copy original zones because the test might modify them (well only the dyndns stuff, but let's make this work for others as well)
219 for zone in $(grep 'zone ' named.conf | cut -f2 -d\")
220 do
221 if [ -f zones/$zone.orig ]
222 then
223 cp -f zones/$zone.orig zones/$zone
224 fi
225 done
226
227 rm -f pdns*.pid
228 rm -f *_tests
229 rm -f pdns-*.conf
230
231 presigned=no
232 both=no
233
234 if [[ "$context" =~ .+-presigned.* ]]
235 then
236 presigned=yes
237 port=$((port-100))
238 eval "$(echo "$context" | sed -r 's/(.+)(-presigned)(-(.*))?/context=\1 presignedcontext=\4/')"
239 if [ -z "$presignedcontext" ]
240 then
241 presignedcontext=$context
242 fi
243 fi
244
245 if [ "${context: -5}" = "-both" ]
246 then
247 both=yes
248 port=$((port-100))
249 context=${context%-both}
250 presignedcontext=$context
251 fi
252
253 optout=0
254 pkcs11=0
255
256 if [ "${context: -13}" = "-nsec3-optout" ]
257 then
258 optout=1
259 fi
260
261 if [ "${context: -7}" = "-pkcs11" ]
262 then
263 pkcs11=1
264 context=${context:0:-7}
265 fi
266
267 # check for lua
268 if $PDNS --version 2>&1 | grep Features: | grep -q "lua"
269 then
270 lua_prequery="--lua-prequery-script=./check_stest_source"
271 skiplua=0
272 else
273 lua_prequery=""
274 skiplua=1
275 fi
276
277 source backends/common
278
279 start_master
280
281 if [ "$skiplua" == "1" ]; then
282 skipreasons="$skipreasons nolua"
283 fi
284
285 check_process
286
287 dotests () {
288 nameserver=127.0.0.1 ./runtests $spectest
289 ./toxml
290 ./totar
291
292 cat ./trustedkeys
293
294 if [ -s "./failed_tests" ]
295 then
296 for t in `cat failed_tests`
297 do
298 echo -e "\n\n$t"
299 cat ${testsdir}/$t/diff
300 done
301 if [ "${!1}" -eq 0 ]
302 then
303 eval "$1=1"
304 fi
305 fi
306 }
307
308 ## TODO: give sdig a timeout
309
310 RETVAL=0
311
312 export address
313 export port
314 export context
315 export extracontexts
316 export skipreasons
317 export testsdir
318 export optout
319
320 sleep 2
321
322 if [ $presigned = no ] || [ $both = yes ]
323 then
324 dotests RETVAL
325 fi
326
327 if [ $presigned = yes ] || [ $both = yes ]
328 then
329 start_slave
330
331 export port
332 export context
333 export skipreasons
334
335 dotests RETVAL
336 fi
337
338 if [ "$wait" = "wait" ]
339 then
340 echo tests done! push enter to terminate instance
341 read l
342 fi
343
344 trap "kill_process $RETVAL" EXIT