Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / tests / scripts / test048-syncrepl-multiproxy
bloba27db783cad0e824415c370a7e515fc8a039c8c4
1 #! /bin/sh
2 # $OpenLDAP: pkg/ldap/tests/scripts/test048-syncrepl-multiproxy,v 1.1.2.7 2008/07/08 19:04:25 quanah Exp $
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2008 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
19 if test $BACKLDAP = ldapno; then
20 echo "LDAP backend not available, test skipped"
21 exit 0
22 fi
24 if test $SYNCPROV = syncprovno; then
25 echo "Syncrepl provider overlay not available, test skipped"
26 exit 0
27 fi
29 if test $MONITORDB = no; then
30 echo "Monitor backend not available, test skipped"
31 exit 0
32 fi
34 if test $THREADS = threadsno ; then
35 echo "Need threads support, test skipped"
36 exit 0
39 mkdir -p $TESTDIR $DBDIR1 $DBDIR2 $DBDIR3
42 # Test replication:
43 # - start master
44 # - start slave
45 # - populate over ldap
46 # - perform some modifies and deleted
47 # - attempt to modify the slave (referral or chain)
48 # - retrieve database over ldap and compare against expected results
51 echo "Starting master slapd on TCP/IP port $PORT1..."
52 . $CONFFILTER $BACKEND $MONITORDB < $PLSRMASTERCONF > $CONF1
53 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
54 MASTERPID=$!
55 if test $WAIT != 0 ; then
56 echo MASTERPID $MASTERPID
57 read foo
59 KILLPIDS="$MASTERPID"
61 sleep 1
63 echo "Using ldapsearch to check that master slapd is running..."
64 for i in 0 1 2 3 4 5; do
65 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
66 '(objectClass=*)' > /dev/null 2>&1
67 RC=$?
68 if test $RC = 0 ; then
69 break
71 echo "Waiting 5 seconds for slapd to start..."
72 sleep 5
73 done
75 if test $RC != 0 ; then
76 echo "ldapsearch failed ($RC)!"
77 test $KILLSERVERS != no && kill -HUP $KILLPIDS
78 exit $RC
81 echo "Using ldapadd to create the context prefix entry in the master..."
82 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
83 $LDIFORDEREDCP > /dev/null 2>&1
84 RC=$?
85 if test $RC != 0 ; then
86 echo "ldapadd failed ($RC)!"
87 test $KILLSERVERS != no && kill -HUP $KILLPIDS
88 exit $RC
91 echo "Starting P1 slave slapd on TCP/IP port $PORT2..."
92 . $CONFFILTER $BACKEND $MONITORDB < $RSLAVECONF > $CONF2
93 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
94 P1SLAVEPID=$!
95 if test $WAIT != 0 ; then
96 echo P1SLAVEPID $P1SLAVEPID
97 read foo
99 KILLPIDS="$MASTERPID $P1SLAVEPID"
101 sleep 1
103 echo "Using ldapsearch to check that P1 slave slapd is running..."
104 for i in 0 1 2 3 4 5; do
105 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
106 '(objectClass=*)' > /dev/null 2>&1
107 RC=$?
108 if test $RC = 0 ; then
109 break
111 echo "Waiting 5 seconds for slapd to start..."
112 sleep 5
113 done
115 if test $RC != 0 ; then
116 echo "ldapsearch failed ($RC)!"
117 test $KILLSERVERS != no && kill -HUP $KILLPIDS
118 exit $RC
121 echo "Starting R1 slave slapd on TCP/IP port $PORT3..."
122 . $CONFFILTER $BACKEND $MONITORDB < $RSLAVECONF | sed -e 's;\.2\.;.3.;' > $CONF3
123 $SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
124 R1SLAVEPID=$!
125 if test $WAIT != 0 ; then
126 echo R1SLAVEPID $R1SLAVEPID
127 read foo
129 KILLPIDS="$MASTERPID $P1SLAVEPID $R1SLAVEPID"
131 sleep 1
133 echo "Using ldapsearch to check that R1 slave slapd is running..."
134 for i in 0 1 2 3 4 5; do
135 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT3 \
136 '(objectClass=*)' > /dev/null 2>&1
137 RC=$?
138 if test $RC = 0; then
139 break
141 echo "Waiting 5 seconds for slapd to start..."
142 sleep 5
143 done
145 if test $RC != 0 ; then
146 echo "ldapsearch failed ($RC)!"
147 test $KILLSERVERS != no && kill -HUP $KILLPIDS
148 exit $RC
151 CHECK=1
152 echo "$CHECK > Using ldapadd to populate the master directory..."
153 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
154 $LDIFORDEREDNOCP > /dev/null 2>&1
155 RC=$?
156 if test $RC != 0 ; then
157 echo "ldapadd failed ($RC)!"
158 test $KILLSERVERS != no && kill -HUP $KILLPIDS
159 exit $RC
162 SLEEP=15
163 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
164 sleep $SLEEP
166 #echo "Using ldapsearch to read all the entries from the master..."
167 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
168 '(objectClass=*)' > "${MASTEROUT}.1" 2>&1
169 RC=$?
171 if test $RC != 0 ; then
172 echo "ldapsearch failed at master ($RC)!"
173 test $KILLSERVERS != no && kill -HUP $KILLPIDS
174 exit $RC
177 #echo "Using ldapsearch to read all the entries from the P1 slave..."
178 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
179 '(objectClass=*)' > "${SLAVEOUT}.1" 2>&1
180 RC=$?
182 if test $RC != 0 ; then
183 echo "ldapsearch failed at P1 slave ($RC)!"
184 test $KILLSERVERS != no && kill -HUP $KILLPIDS
185 exit $RC
188 #echo "Filtering master results..."
189 . $LDIFFILTER < "${MASTEROUT}.1" > $MASTERFLT
190 #echo "Filtering slave results..."
191 . $LDIFFILTER < "${SLAVEOUT}.1" > $SLAVEFLT
193 echo "$CHECK < Comparing retrieved entries from master and P1 slave..."
194 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
196 if test $? != 0 ; then
197 echo "test failed - master and P1 slave databases differ"
198 test $KILLSERVERS != no && kill -HUP $KILLPIDS
199 exit 1
202 #echo "Using ldapsearch to read all the entries from the R1 slave..."
203 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \
204 '(objectClass=*)' > "${SLAVEOUT}.1" 2>&1
205 RC=$?
207 if test $RC != 0 ; then
208 echo "ldapsearch failed at R1 slave ($RC)!"
209 test $KILLSERVERS != no && kill -HUP $KILLPIDS
210 exit $RC
213 #echo "Filtering slave results..."
214 . $LDIFFILTER < "${SLAVEOUT}.1" > $SLAVEFLT
216 echo "$CHECK < Comparing retrieved entries from master and R1 slave..."
217 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
219 if test $? != 0 ; then
220 echo "test failed - master and R1 slave databases differ"
221 test $KILLSERVERS != no && kill -HUP $KILLPIDS
222 exit 1
225 CHECK=`expr $CHECK + 1`
226 SLEEP=10
227 echo "$CHECK > Stopping the provider, sleeping $SLEEP seconds and restarting it..."
228 kill -HUP "$MASTERPID"
229 wait $MASTERPID
230 sleep $SLEEP
232 echo "======================= RESTART =======================" >> $LOG1
233 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
234 MASTERPID=$!
235 if test $WAIT != 0 ; then
236 echo MASTERPID $MASTERPID
237 read foo
239 KILLPIDS="$MASTERPID $P1SLAVEPID $R1SLAVEPID"
241 sleep 1
243 echo "Using ldapsearch to check that master slapd is running..."
244 for i in 0 1 2 3 4 5; do
245 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
246 '(objectClass=*)' > /dev/null 2>&1
247 RC=$?
248 if test $RC = 0 ; then
249 break
251 echo "Waiting 5 seconds for slapd to start..."
252 sleep 5
253 done
255 if test $RC != 0 ; then
256 echo "ldapsearch failed ($RC)!"
257 test $KILLSERVERS != no && kill -HUP $KILLPIDS
258 exit $RC
261 echo "Using ldapmodify to modify master directory..."
264 # Do some modifications
267 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
268 $TESTOUT 2>&1 << EOMODS
269 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
270 changetype: modify
271 add: drink
272 drink: Orange Juice
274 delete: sn
275 sn: Jones
277 add: sn
278 sn: Jones
280 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
281 changetype: modify
282 replace: drink
283 drink: Iced Tea
285 dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
286 changetype: modify
287 delete: uniquemember
288 uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
289 uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
291 add: uniquemember
292 uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
293 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
295 dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc
296 =com
297 changetype: modify
298 delete: cn
299 cn: Biiff Jensen
301 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
302 changetype: add
303 objectclass: OpenLDAPperson
304 cn: Gern Jensen
305 sn: Jensen
306 uid: gjensen
307 title: Chief Investigator, ITD
308 postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
309 seealso: cn=All Staff, ou=Groups, dc=example,dc=com
310 drink: Coffee
311 homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
312 description: Very odd
313 facsimiletelephonenumber: +1 313 555 7557
314 telephonenumber: +1 313 555 8343
315 mail: gjensen@mailgw.example.com
316 homephone: +1 313 555 8844
318 dn: ou=Retired, ou=People, dc=example,dc=com
319 changetype: add
320 objectclass: organizationalUnit
321 ou: Retired
323 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
324 changetype: add
325 objectclass: OpenLDAPperson
326 cn: Rosco P. Coltrane
327 sn: Coltrane
328 uid: rosco
329 description: Fat tycoon
331 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
332 changetype: modrdn
333 newrdn: cn=Rosco P. Coltrane
334 deleteoldrdn: 1
335 newsuperior: ou=Retired, ou=People, dc=example,dc=com
337 dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
338 changetype: delete
339 EOMODS
341 RC=$?
342 if test $RC != 0 ; then
343 echo "ldapmodify failed ($RC)!"
344 test $KILLSERVERS != no && kill -HUP $KILLPIDS
345 exit $RC
348 SLEEP=15
349 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
350 sleep $SLEEP
352 #echo "Using ldapsearch to read all the entries from the master..."
353 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
354 '(objectClass=*)' > "${MASTEROUT}.2" 2>&1
355 RC=$?
357 if test $RC != 0 ; then
358 echo "ldapsearch failed at master ($RC)!"
359 test $KILLSERVERS != no && kill -HUP $KILLPIDS
360 exit $RC
363 #echo "Using ldapsearch to read all the entries from the P1 slave..."
364 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
365 '(objectClass=*)' > "${SLAVEOUT}.2" 2>&1
366 RC=$?
368 if test $RC != 0 ; then
369 echo "ldapsearch failed at P1 slave ($RC)!"
370 test $KILLSERVERS != no && kill -HUP $KILLPIDS
371 exit $RC
374 #echo "Filtering master results..."
375 . $LDIFFILTER < "${MASTEROUT}.2" > $MASTERFLT
376 #echo "Filtering P1 slave results..."
377 . $LDIFFILTER < "${SLAVEOUT}.2" > $SLAVEFLT
379 echo "$CHECK < Comparing retrieved entries from master and P1 slave..."
380 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
382 if test $? != 0 ; then
383 echo "test failed - master and P1 slave databases differ"
384 test $KILLSERVERS != no && kill -HUP $KILLPIDS
385 exit 1
388 #echo "Using ldapsearch to read all the entries from the R1 slave..."
389 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \
390 '(objectClass=*)' > "${SLAVEOUT}.2" 2>&1
391 RC=$?
393 if test $RC != 0 ; then
394 echo "ldapsearch failed at R1 slave ($RC)!"
395 test $KILLSERVERS != no && kill -HUP $KILLPIDS
396 exit $RC
399 #echo "Filtering slave results..."
400 . $LDIFFILTER < "${SLAVEOUT}.2" > $SLAVEFLT
402 echo "$CHECK < Comparing retrieved entries from master and R1 slave..."
403 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
405 if test $? != 0 ; then
406 echo "test failed - master and R1 slave databases differ"
407 test $KILLSERVERS != no && kill -HUP $KILLPIDS
408 exit 1
411 CHECK=`expr $CHECK + 1`
412 echo "$CHECK > Stopping slaves to test recovery..."
413 kill -HUP $P1SLAVEPID $R1SLAVEPID
414 wait $P1SLAVEPID
415 wait $R1SLAVEPID
417 echo "Modifying more entries on the master..."
418 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
419 $TESTOUT 2>&1 << EOMODS
420 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
421 changetype: modify
422 add: description
423 description: r1 slave is down...
425 dn: cn=James T. Kirk, ou=Retired, ou=People, dc=example,dc=com
426 changetype: add
427 objectclass: OpenLDAPperson
428 sn: Kirk
429 uid: jtk
430 cn: James T. Kirk
432 dn: cn=Tiberius J. Hooker, ou=Retired, ou=People, dc=example,dc=com
433 changetype: add
434 objectclass: OpenLDAPperson
435 sn: Hooker
436 uid: tjh
437 cn: Tiberius J. Hooker
439 EOMODS
441 echo "Restarting P1 slave..."
442 echo "======================= RESTART =======================" >> $LOG3
443 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
444 P1SLAVEPID=$!
445 if test $WAIT != 0 ; then
446 echo P1SLAVEPID $P1SLAVEPID
447 read foo
450 echo "Restarting R1 slave..."
451 echo "======================= RESTART =======================" >> $LOG3
452 $SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
453 R1SLAVEPID=$!
454 if test $WAIT != 0 ; then
455 echo R1SLAVEPID $R1SLAVEPID
456 read foo
458 KILLPIDS="$MASTERPID $P1SLAVEPID $R1SLAVEPID"
460 SLEEP=25
461 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
462 sleep $SLEEP
464 #echo "Using ldapsearch to read all the entries from the master..."
465 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
466 '(objectClass=*)' > "${MASTEROUT}.3" 2>&1
467 RC=$?
469 if test $RC != 0 ; then
470 echo "ldapsearch failed at master ($RC)!"
471 test $KILLSERVERS != no && kill -HUP $KILLPIDS
472 exit $RC
475 #echo "Using ldapsearch to read all the entries from the P1 slave..."
476 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
477 '(objectClass=*)' > "${SLAVEOUT}.3" 2>&1
478 RC=$?
480 if test $RC != 0 ; then
481 echo "ldapsearch failed at slave ($RC)!"
482 test $KILLSERVERS != no && kill -HUP $KILLPIDS
483 exit $RC
486 #echo "Filtering master results..."
487 . $LDIFFILTER < "${MASTEROUT}.3" > $MASTERFLT
488 #echo "Filtering slave results..."
489 . $LDIFFILTER < "${SLAVEOUT}.3" > $SLAVEFLT
491 echo "$CHECK < Comparing retrieved entries from master and P1 slave..."
492 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
494 if test $? != 0 ; then
495 echo "test failed - master and slave databases differ"
496 test $KILLSERVERS != no && kill -HUP $KILLPIDS
497 exit 1
500 #echo "Using ldapsearch to read all the entries from the R1 slave..."
501 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \
502 '(objectClass=*)' > "${SLAVEOUT}.3" 2>&1
503 RC=$?
505 if test $RC != 0 ; then
506 echo "ldapsearch failed at slave ($RC)!"
507 test $KILLSERVERS != no && kill -HUP $KILLPIDS
508 exit $RC
511 #echo "Filtering slave results..."
512 . $LDIFFILTER < "${SLAVEOUT}.3" > $SLAVEFLT
514 echo "$CHECK < Comparing retrieved entries from master and R1 slave..."
515 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
517 if test $? != 0 ; then
518 echo "test failed - master and slave databases differ"
519 test $KILLSERVERS != no && kill -HUP $KILLPIDS
520 exit 1
523 CHECK=`expr $CHECK + 1`
524 echo "$CHECK > Try updating the P1 slave slapd..."
525 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
526 $TESTOUT 2>&1 << EOMODS
527 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
528 changetype: modify
529 add: description
530 description: This write must fail because directed to a shadow context,
531 description: unless the chain overlay is configured appropriately ;)
533 EOMODS
535 RC=$?
536 if test $RC != 0 ; then
537 echo "ldapmodify failed ($RC)!"
538 test $KILLSERVERS != no && kill -HUP $KILLPIDS
539 exit $RC
542 SLEEP=15
543 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
544 sleep $SLEEP
546 #echo "Using ldapsearch to read all the entries from the master..."
547 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
548 '(objectClass=*)' > "${MASTEROUT}.4" 2>&1
549 RC=$?
551 if test $RC != 0 ; then
552 echo "ldapsearch failed at master ($RC)!"
553 test $KILLSERVERS != no && kill -HUP $KILLPIDS
554 exit $RC
557 #echo "Using ldapsearch to read all the entries from the P1 slave..."
558 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
559 '(objectClass=*)' > "${SLAVEOUT}.4" 2>&1
560 RC=$?
562 if test $RC != 0 ; then
563 echo "ldapsearch failed at slave ($RC)!"
564 test $KILLSERVERS != no && kill -HUP $KILLPIDS
565 exit $RC
568 #echo "Filtering master results..."
569 . $LDIFFILTER < "${MASTEROUT}.4" > $MASTERFLT
570 #echo "Filtering slave results..."
571 . $LDIFFILTER < "${SLAVEOUT}.4" > $SLAVEFLT
573 echo "$CHECK < Comparing retrieved entries from master and P1 slave..."
574 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
576 if test $? != 0 ; then
577 echo "test failed - master and P1 slave databases differ"
578 test $KILLSERVERS != no && kill -HUP $KILLPIDS
579 exit 1
582 #echo "Using ldapsearch to read all the entries from the R1 slave..."
583 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \
584 '(objectClass=*)' > "${SLAVEOUT}.4" 2>&1
585 RC=$?
587 if test $RC != 0 ; then
588 echo "ldapsearch failed at slave ($RC)!"
589 test $KILLSERVERS != no && kill -HUP $KILLPIDS
590 exit $RC
593 #echo "Filtering slave results..."
594 . $LDIFFILTER < "${SLAVEOUT}.4" > $SLAVEFLT
596 echo "$CHECK < Comparing retrieved entries from master and R1 slave..."
597 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
599 if test $? != 0 ; then
600 echo "test failed - master and R1 slave databases differ"
601 test $KILLSERVERS != no && kill -HUP $KILLPIDS
602 exit 1
605 test $KILLSERVERS != no && kill -HUP $KILLPIDS
607 echo ">>>>> Test succeeded"
609 test $KILLSERVERS != no && wait
611 exit 0