Home | History | Annotate | Line # | Download | only in scripts
      1 #! /bin/sh
      2 # $OpenLDAP$
      3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4 ##
      5 ## Copyright 1998-2024 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.
     11 ##
     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>.
     15 
     16 echo "running defines.sh"
     17 . $SRCDIR/scripts/defines.sh
     18 
     19 if test $SYNCPROV = syncprovno; then 
     20 	echo "Syncrepl provider overlay not available, test skipped"
     21 	exit 0
     22 fi 
     23 
     24 MPR=${MPR-4}
     25 
     26 if [ $MPR -gt 9 ]; then
     27 MPR=9
     28 fi
     29 
     30 XDIR=$TESTDIR/srv
     31 TMP=$TESTDIR/tmp
     32 
     33 mkdir -p $TESTDIR
     34 
     35 $SLAPPASSWD -g -n >$CONFIGPWF
     36 
     37 if test x"$SYNCMODE" = x ; then
     38 	SYNCMODE=rp
     39 fi
     40 case "$SYNCMODE" in
     41 	ro)
     42 		SYNCTYPE="type=refreshOnly interval=00:00:00:03"
     43 		;;
     44 	rp)
     45 		SYNCTYPE="type=refreshAndPersist"
     46 		;;
     47 	*)
     48 		echo "unknown sync mode $SYNCMODE"
     49 		exit 1;
     50 		;;
     51 esac
     52 
     53 #
     54 # Test replication of dynamic config:
     55 # - start servers
     56 # - configure over ldap
     57 # - populate over ldap
     58 # - configure syncrepl over ldap
     59 # - retrieve database over ldap and compare against expected results
     60 #
     61 
     62 echo "Initializing server configurations..."
     63 n=1
     64 while [ $n -le $MPR ]; do
     65 
     66 DBDIR=${XDIR}$n/db
     67 CFDIR=${XDIR}$n/slapd.d
     68 
     69 mkdir -p ${XDIR}$n $DBDIR $CFDIR
     70 
     71 $SLAPADD -F $CFDIR -n 0 <<EOF
     72 dn: cn=config
     73 objectClass: olcGlobal
     74 cn: config
     75 olcServerID: $n
     76 
     77 dn: olcDatabase={0}config,cn=config
     78 objectClass: olcDatabaseConfig
     79 olcDatabase: {0}config
     80 olcRootPW:< file://$CONFIGPWF
     81 EOF
     82 RC=$?
     83 if test $RC != 0 ; then
     84 	echo "slapadd failed ($RC)!"
     85 	exit $RC
     86 fi
     87 
     88 n=`expr $n + 1`
     89 done
     90 
     91 echo "Starting server 1 on TCP/IP port $PORT1..."
     92 cd ${XDIR}1
     93 $SLAPD -F slapd.d -h $URI1 -d $LVL > $LOG1 2>&1 &
     94 PID=$!
     95 if test $WAIT != 0 ; then
     96     echo PID $PID
     97     read foo
     98 fi
     99 KILLPIDS="$PID"
    100 cd $TESTWD
    101 
    102 sleep 1
    103 
    104 echo "Using ldapsearch to check that server 1 is running..."
    105 for i in 0 1 2 3 4 5; do
    106 	$LDAPSEARCH -s base -b "" -H $URI1 \
    107 		'objectclass=*' > /dev/null 2>&1
    108 	RC=$?
    109 	if test $RC = 0 ; then
    110 		break
    111 	fi
    112 	echo "Waiting 5 seconds for slapd to start..."
    113 	sleep 5
    114 done
    115 
    116 if test $RC != 0 ; then
    117 	echo "ldapsearch failed ($RC)!"
    118 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    119 	exit $RC
    120 fi
    121 
    122 echo "Inserting syncprov overlay on server 1..."
    123 echo "" > $TMP
    124 if [ "$SYNCPROV" = syncprovmod ]; then
    125 cat <<EOF >> $TMP
    126 dn: cn=module,cn=config
    127 changetype: add
    128 objectClass: olcModuleList
    129 cn: module
    130 olcModulePath: $TESTWD/../servers/slapd/overlays
    131 olcModuleLoad: syncprov.la
    132 
    133 EOF
    134 fi
    135 #
    136 # Note that we configure a timeout here; it's possible for both
    137 # servers to attempt to bind to each other while a modify to
    138 # cn=config is in progress. When the modify pauses the thread pool
    139 # neither server will progress. The timeout will drop the syncrepl
    140 # attempt and allow the modifies to complete.
    141 #
    142 read CONFIGPW < $CONFIGPWF
    143 echo "dn: cn=config" >> $TMP
    144 echo "changetype: modify" >> $TMP
    145 echo "replace: olcServerID" >> $TMP
    146 n=1
    147 while [ $n -le $MPR ]; do
    148 PORT=`expr $BASEPORT + $n`
    149 URI="ldap://${LOCALHOST}:$PORT/"
    150 echo "olcServerID: $n $URI" >> $TMP
    151 n=`expr $n + 1`
    152 done
    153 
    154 cat <<EOF >> $TMP
    155 
    156 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
    157 changetype: add
    158 objectClass: olcOverlayConfig
    159 objectClass: olcSyncProvConfig
    160 olcOverlay: syncprov
    161 
    162 dn: olcDatabase={0}config,cn=config
    163 changetype: modify
    164 add: olcSyncRepl
    165 EOF
    166 
    167 n=1
    168 while [ $n -le $MPR ]; do
    169 PORT=`expr $BASEPORT + $n`
    170 URI="ldap://${LOCALHOST}:$PORT/"
    171 echo "olcSyncRepl: rid=00$n provider=$URI binddn=\"cn=config\" bindmethod=simple" >> $TMP
    172 echo "  credentials=$CONFIGPW searchbase=\"cn=config\" type=refreshAndPersist" >> $TMP
    173 echo "  retry=\"1 12 300 5\" timeout=3" >> $TMP
    174 n=`expr $n + 1`
    175 done
    176 echo "-" >> $TMP
    177 echo "add: olcMultiProvider" >> $TMP
    178 echo "olcMultiProvider: TRUE" >> $TMP
    179 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF < $TMP >> $TESTOUT 2>&1
    180 RC=$?
    181 if test $RC != 0 ; then
    182 	echo "ldapmodify failed for syncrepl config ($RC)!"
    183 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    184 	exit $RC
    185 fi
    186 
    187 n=2
    188 while [ $n -le $MPR ]; do
    189 PORT=`expr $BASEPORT + $n`
    190 URI="ldap://${LOCALHOST}:$PORT/"
    191 LOG=$TESTDIR/slapd.$n.log
    192 echo "Starting server $n on TCP/IP port $PORT..."
    193 cd ${XDIR}$n
    194 $SLAPD -F ./slapd.d -h $URI -d $LVL > $LOG 2>&1 &
    195 CONSUMERPID=$!
    196 if test $WAIT != 0 ; then
    197     echo CONSUMERPID $CONSUMERPID
    198     read foo
    199 fi
    200 KILLPIDS="$KILLPIDS $CONSUMERPID"
    201 cd $TESTWD
    202 
    203 sleep 1
    204 
    205 echo "Using ldapsearch to check that server $n is running..."
    206 for i in 0 1 2 3 4 5; do
    207 	$LDAPSEARCH -s base -b "" -H $URI \
    208 		'objectclass=*' > /dev/null 2>&1
    209 	RC=$?
    210 	if test $RC = 0 ; then
    211 		break
    212 	fi
    213 	echo "Waiting 5 seconds for slapd to start..."
    214 	sleep 5
    215 done
    216 
    217 if test $RC != 0 ; then
    218 	echo "ldapsearch failed ($RC)!"
    219 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    220 	exit $RC
    221 fi
    222 
    223 echo "Configuring syncrepl on server $n..."
    224 cat <<EOF > $TMP
    225 dn: olcDatabase={0}config,cn=config
    226 changetype: modify
    227 add: olcSyncRepl
    228 EOF
    229 j=1
    230 while [ $j -le $MPR ]; do
    231 P2=`expr $BASEPORT + $j`
    232 U2="ldap://${LOCALHOST}:$P2/"
    233 echo "olcSyncRepl: rid=00$j provider=$U2 binddn=\"cn=config\" bindmethod=simple" >> $TMP
    234 echo "  credentials=$CONFIGPW searchbase=\"cn=config\" type=refreshAndPersist" >> $TMP
    235 echo "  retry=\"1 12 300 5\" timeout=3" >> $TMP
    236 j=`expr $j + 1`
    237 done
    238 cat <<EOF >> $TMP
    239 -
    240 add: olcMultiProvider
    241 olcMultiProvider: TRUE
    242 EOF
    243 $LDAPMODIFY -D cn=config -H $URI -y $CONFIGPWF < $TMP >>$TESTOUT 2>&1
    244 n=`expr $n + 1`
    245 done
    246 
    247 echo "Adding schema and databases on server 1..."
    248 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
    249 include: file://$ABS_SCHEMADIR/core.ldif
    250 
    251 include: file://$ABS_SCHEMADIR/cosine.ldif
    252 
    253 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
    254 
    255 include: file://$ABS_SCHEMADIR/openldap.ldif
    256 
    257 include: file://$ABS_SCHEMADIR/nis.ldif
    258 EOF
    259 RC=$?
    260 if test $RC != 0 ; then
    261 	echo "ldapadd failed for schema config ($RC)!"
    262 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    263 	exit $RC
    264 fi
    265 
    266 nullExclude=""
    267 test $BACKEND = null && nullExclude="# "
    268 
    269 echo "" > $TMP
    270 if [ "$BACKENDTYPE" = mod ]; then
    271 cat <<EOF >> $TMP
    272 dn: cn=module,cn=config
    273 objectClass: olcModuleList
    274 cn: module
    275 olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
    276 olcModuleLoad: back_$BACKEND.la
    277 
    278 EOF
    279 fi
    280 
    281 cat <<EOF >> $TMP
    282 dn: olcDatabase={1}$BACKEND,cn=config
    283 objectClass: olcDatabaseConfig
    284 ${nullExclude}objectClass: olc${BACKEND}Config
    285 olcDatabase: {1}$BACKEND
    286 olcSuffix: $BASEDN
    287 ${nullExclude}olcDbDirectory: ./db
    288 olcRootDN: $MANAGERDN
    289 olcRootPW: $PASSWD
    290 EOF
    291 
    292 n=1
    293 while [ $n -le $MPR ]; do
    294 PORT=`expr $BASEPORT + $n`
    295 URI="ldap://${LOCALHOST}:$PORT/"
    296 
    297 echo "olcSyncRepl: rid=01$n provider=$URI binddn=\"$MANAGERDN\" bindmethod=simple" >> $TMP
    298 echo "  credentials=$PASSWD searchbase=\"$BASEDN\" $SYNCTYPE" >> $TMP
    299 echo "  retry=\"1 12 300 5\" timeout=3" >> $TMP
    300 n=`expr $n + 1`
    301 done
    302 
    303 cat <<EOF >> $TMP
    304 olcMultiProvider: TRUE
    305 
    306 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
    307 objectClass: olcOverlayConfig
    308 objectClass: olcSyncProvConfig
    309 olcOverlay: syncprov
    310 EOF
    311 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF < $TMP >>$TESTOUT 2>&1
    312 RC=$?
    313 if test $RC != 0 ; then
    314 	echo "ldapadd failed for database config ($RC)!"
    315 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    316 	exit $RC
    317 fi
    318 
    319 if test $INDEXDB = indexdb ; then
    320 	$LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
    321 dn: olcDatabase={1}$BACKEND,cn=config
    322 changetype: modify
    323 add: olcDbIndex
    324 olcDbIndex: objectClass,entryUUID,entryCSN eq
    325 olcDbIndex: cn,uid pres,eq,sub
    326 EOF
    327 	RC=$?
    328 	if test $RC != 0 ; then
    329 		echo "ldapadd modify for database config ($RC)!"
    330 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
    331 		exit $RC
    332 	fi
    333 fi
    334 
    335 echo "Using ldapadd to populate server 1..."
    336 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
    337 	>> $TESTOUT 2>&1
    338 RC=$?
    339 if test $RC != 0 ; then
    340 	echo "ldapadd failed for server 1 database ($RC)!"
    341 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    342 	exit $RC
    343 fi
    344 
    345 echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..."
    346 sleep $SLEEP2
    347 
    348 n=1
    349 while [ $n -le $MPR ]; do
    350 PORT=`expr $BASEPORT + $n`
    351 URI="ldap://${LOCALHOST}:$PORT/"
    352 
    353 echo "Using ldapsearch to read config from server $n..."
    354 $LDAPSEARCH -b cn=config -D cn=config -H $URI -y $CONFIGPWF  \
    355 	'objectclass=*' > $TESTDIR/server$n.out 2>&1
    356 RC=$?
    357 
    358 if test $RC != 0 ; then
    359 	echo "ldapsearch failed at server $n ($RC)!"
    360 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    361 	exit $RC
    362 fi
    363 
    364 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
    365 
    366 n=`expr $n + 1`
    367 done
    368 
    369 n=2
    370 while [ $n -le $MPR ]; do
    371 echo "Comparing retrieved configs from server 1 and server $n..."
    372 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
    373 
    374 if test $? != 0 ; then
    375 	echo "test failed - server 1 and server $n configs differ"
    376 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    377 	exit 1
    378 fi
    379 n=`expr $n + 1`
    380 done
    381 
    382 n=1
    383 while [ $n -le $MPR ]; do
    384 PORT=`expr $BASEPORT + $n`
    385 URI="ldap://${LOCALHOST}:$PORT/"
    386 
    387 echo "Using ldapsearch to read all the entries from server $n..."
    388 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
    389 	'objectclass=*' > $TESTDIR/server$n.out 2>&1
    390 RC=$?
    391 
    392 if test $RC != 0 ; then
    393 	echo "ldapsearch failed at server $n ($RC)!"
    394 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    395 	exit $RC
    396 fi
    397 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
    398 n=`expr $n + 1`
    399 done
    400 
    401 n=2
    402 while [ $n -le $MPR ]; do
    403 echo "Comparing retrieved entries from server 1 and server $n..."
    404 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
    405 
    406 if test $? != 0 ; then
    407 	echo "test failed - server 1 and server $n databases differ"
    408 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    409 	exit 1
    410 fi
    411 n=`expr $n + 1`
    412 done
    413 
    414 echo "Using ldapadd to populate server 2..."
    415 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
    416 	>> $TESTOUT 2>&1
    417 RC=$?
    418 if test $RC != 0 ; then
    419 	echo "ldapadd failed for server 2 database ($RC)!"
    420 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    421 	exit $RC
    422 fi
    423 
    424 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    425 sleep $SLEEP1
    426 
    427 n=1
    428 while [ $n -le $MPR ]; do
    429 PORT=`expr $BASEPORT + $n`
    430 URI="ldap://${LOCALHOST}:$PORT/"
    431 
    432 echo "Using ldapsearch to read all the entries from server $n..."
    433 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
    434 	'objectclass=*' > $TESTDIR/server$n.out 2>&1
    435 RC=$?
    436 
    437 if test $RC != 0 ; then
    438 	echo "ldapsearch failed at server $n ($RC)!"
    439 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    440 	exit $RC
    441 fi
    442 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
    443 n=`expr $n + 1`
    444 done
    445 
    446 n=2
    447 while [ $n -le $MPR ]; do
    448 echo "Comparing retrieved entries from server 1 and server $n..."
    449 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
    450 
    451 if test $? != 0 ; then
    452 	echo "test failed - server 1 and server $n databases differ"
    453 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    454 	exit 1
    455 fi
    456 n=`expr $n + 1`
    457 done
    458 
    459 echo "Using ldapadd to populate server 3..."
    460 $LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD \
    461 	<< EOMODS >> $TESTOUT 2>&1
    462 dn: cn=Server 3 Test,dc=example,dc=com
    463 changetype: add
    464 objectClass: device
    465 cn: Server 3 Test
    466 EOMODS
    467 RC=$?
    468 if test $RC != 0 ; then
    469 	echo "ldapadd failed for server 3 database ($RC)!"
    470 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    471 	exit $RC
    472 fi
    473 
    474 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    475 sleep $SLEEP1
    476 
    477 n=1
    478 while [ $n -le $MPR ]; do
    479 PORT=`expr $BASEPORT + $n`
    480 URI="ldap://${LOCALHOST}:$PORT/"
    481 
    482 echo "Using ldapsearch to read all the entries from server $n..."
    483 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
    484 	'objectclass=*' > $TESTDIR/server$n.out 2>&1
    485 RC=$?
    486 
    487 if test $RC != 0 ; then
    488 	echo "ldapsearch failed at server $n ($RC)!"
    489 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    490 	exit $RC
    491 fi
    492 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
    493 n=`expr $n + 1`
    494 done
    495 
    496 n=2
    497 while [ $n -le $MPR ]; do
    498 echo "Comparing retrieved entries from server 1 and server $n..."
    499 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
    500 
    501 if test $? != 0 ; then
    502 	echo "test failed - server 1 and server $n databases differ"
    503 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    504 	exit 1
    505 fi
    506 n=`expr $n + 1`
    507 done
    508 
    509 echo "Using ldapmodify to add to server 1 entries that will be deleted..."
    510 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
    511 	>> $TESTOUT 2>&1 << EOADDS
    512 dn: cn=To be deleted by server 1,dc=example,dc=com
    513 changetype: add
    514 objectClass: device
    515 # no distinguished values, will be added by DSA
    516 
    517 dn: cn=To be deleted by server 2,dc=example,dc=com
    518 changetype: add
    519 objectClass: device
    520 # no distinguished values, will be added by DSA
    521 
    522 dn: cn=To be deleted by server 3,dc=example,dc=com
    523 changetype: add
    524 objectClass: device
    525 # no distinguished values, will be added by DSA
    526 
    527 dn: cn=To be deleted by server 1,dc=example,dc=com
    528 changetype: delete
    529 EOADDS
    530 RC=$?
    531 if test $RC != 0 ; then
    532 	echo "ldapmodify failed for server 1 database ($RC)!"
    533 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    534 	exit $RC
    535 fi
    536 
    537 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    538 sleep $SLEEP1
    539 
    540 n=1
    541 while [ $n -le $MPR ]; do
    542 PORT=`expr $BASEPORT + $n`
    543 URI="ldap://${LOCALHOST}:$PORT/"
    544 
    545 echo "Using ldapsearch to read all the entries from server $n..."
    546 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
    547 	'objectclass=*' > $TESTDIR/server$n.out 2>&1
    548 RC=$?
    549 
    550 if test $RC != 0 ; then
    551 	echo "ldapsearch failed at server $n ($RC)!"
    552 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    553 	exit $RC
    554 fi
    555 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
    556 n=`expr $n + 1`
    557 done
    558 
    559 n=2
    560 while [ $n -le $MPR ]; do
    561 echo "Comparing retrieved entries from server 1 and server $n..."
    562 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
    563 
    564 if test $? != 0 ; then
    565 	echo "test failed - server 1 and server $n databases differ"
    566 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    567 	exit 1
    568 fi
    569 n=`expr $n + 1`
    570 done
    571 
    572 echo "Using ldapmodify to delete entries from server 2..."
    573 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
    574 	>> $TESTOUT 2>&1 << EOADDS
    575 dn: cn=To be deleted by server 2,dc=example,dc=com
    576 changetype: delete
    577 EOADDS
    578 RC=$?
    579 if test $RC != 0 ; then
    580 	echo "ldapmodify failed for server 2 database ($RC)!"
    581 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    582 	exit $RC
    583 fi
    584 
    585 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    586 sleep $SLEEP1
    587 
    588 echo "Using ldapmodify to delete entries from server 3..."
    589 $LDAPMODIFY -D "$MANAGERDN" -H $URI3 -w $PASSWD \
    590 	>> $TESTOUT 2>&1 << EOADDS
    591 dn: cn=To be deleted by server 3,dc=example,dc=com
    592 changetype: delete
    593 EOADDS
    594 RC=$?
    595 if test $RC != 0 ; then
    596 	echo "ldapmodify failed for server 3 database ($RC)!"
    597 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    598 	exit $RC
    599 fi
    600 
    601 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    602 sleep $SLEEP1
    603 
    604 n=1
    605 while [ $n -le $MPR ]; do
    606 PORT=`expr $BASEPORT + $n`
    607 URI="ldap://${LOCALHOST}:$PORT/"
    608 
    609 echo "Using ldapsearch to read all the entries from server $n..."
    610 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
    611 	'objectclass=*' > $TESTDIR/server$n.out 2>&1
    612 RC=$?
    613 
    614 if test $RC != 0 ; then
    615 	echo "ldapsearch failed at server $n ($RC)!"
    616 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    617 	exit $RC
    618 fi
    619 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
    620 n=`expr $n + 1`
    621 done
    622 
    623 n=2
    624 while [ $n -le $MPR ]; do
    625 echo "Comparing retrieved entries from server 1 and server $n..."
    626 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
    627 
    628 if test $? != 0 ; then
    629 	echo "test failed - server 1 and server $n databases differ"
    630 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    631 	exit 1
    632 fi
    633 n=`expr $n + 1`
    634 done
    635 
    636 # kill!
    637 # test $KILLSERVERS != no && kill -HUP $KILLPIDS
    638 kill -HUP $KILLPIDS
    639 
    640 # kill!
    641 # test $KILLSERVERS != no && wait
    642 wait
    643 
    644 echo "Restarting servers..."
    645 KILLPIDS=""
    646 
    647 echo "Starting server 1 on TCP/IP port $PORT1..."
    648 echo "======================= RESTART =======================" >> $LOG1
    649 cd ${XDIR}1
    650 $SLAPD -F slapd.d -h $URI1 -d $LVL >> $LOG1 2>&1 &
    651 PID=$!
    652 if test $WAIT != 0 ; then
    653     echo PID $PID
    654     read foo
    655 fi
    656 KILLPIDS="$PID"
    657 cd $TESTWD
    658 
    659 sleep 1
    660 
    661 echo "Using ldapsearch to check that server 1 is running..."
    662 for i in 0 1 2 3 4 5; do
    663 	$LDAPSEARCH -s base -b "" -H $URI1 \
    664 		'objectclass=*' > /dev/null 2>&1
    665 	RC=$?
    666 	if test $RC = 0 ; then
    667 		break
    668 	fi
    669 	echo "Waiting 5 seconds for slapd to start..."
    670 	sleep 5
    671 done
    672 
    673 if test $RC != 0 ; then
    674 	echo "ldapsearch failed ($RC)!"
    675 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    676 	exit $RC
    677 fi
    678 
    679 n=2
    680 while [ $n -le $MPR ]; do
    681 PORT=`expr $BASEPORT + $n`
    682 URI="ldap://${LOCALHOST}:$PORT/"
    683 LOG=$TESTDIR/slapd.$n.log
    684 echo "Starting server $n on TCP/IP port $PORT..."
    685 cd ${XDIR}$n
    686 echo "======================= RESTART =======================" >> $LOG
    687 $SLAPD -F ./slapd.d -h $URI -d $LVL >> $LOG 2>&1 &
    688 PID=$!
    689 if test $WAIT != 0 ; then
    690     echo PID $PID
    691     read foo
    692 fi
    693 KILLPIDS="$KILLPIDS $PID"
    694 cd $TESTWD
    695 n=`expr $n + 1`
    696 done
    697 
    698 n=2
    699 while [ $n -le $MPR ]; do
    700 PORT=`expr $BASEPORT + $n`
    701 URI="ldap://${LOCALHOST}:$PORT/"
    702 echo "Using ldapsearch to check that server $n is running..."
    703 for i in 0 1 2 3 4 5; do
    704 	$LDAPSEARCH -s base -b "" -H $URI \
    705 		'objectclass=*' > /dev/null 2>&1
    706 	RC=$?
    707 	if test $RC = 0 ; then
    708 		break
    709 	fi
    710 	echo "Waiting 5 seconds for slapd to start..."
    711 	sleep 5
    712 done
    713 
    714 if test $RC != 0 ; then
    715 	echo "ldapsearch failed ($RC)!"
    716 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    717 	exit $RC
    718 fi
    719 n=`expr $n + 1`
    720 done
    721 
    722 # Insert modifications and more tests here.
    723 echo "Waiting $SLEEP1 seconds for servers to resync..."
    724 sleep $SLEEP1
    725 
    726 echo "Using ldapmodify to add/modify/delete entries from server 1..."
    727 for i in 1 2 3 4 5 6 7 8 9 10; do
    728 echo "  iteration $i"
    729 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
    730 	>> $TESTOUT 2>&1 << EOMODS
    731 dn: cn=Add-Mod-Del,dc=example,dc=com
    732 changetype: add
    733 cn: Add-Mod-Del
    734 objectclass: organizationalRole
    735 
    736 dn: cn=Add-Mod-Del,dc=example,dc=com
    737 changetype: modify
    738 replace: description
    739 description: guinea pig
    740 -
    741 
    742 dn: cn=Add-Mod-Del,dc=example,dc=com
    743 changetype: delete
    744 EOMODS
    745 RC=$?
    746 if test $RC != 0 ; then
    747 	echo "ldapmodify failed for server 1 database ($RC)!"
    748 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    749 	exit $RC
    750 fi
    751 done
    752 
    753 echo "Waiting $SLEEP1 seconds for servers to resync..."
    754 sleep $SLEEP1
    755 
    756 n=1
    757 while [ $n -le $MPR ]; do
    758 PORT=`expr $BASEPORT + $n`
    759 URI="ldap://${LOCALHOST}:$PORT/"
    760 
    761 echo "Using ldapsearch to read all the entries from server $n..."
    762 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
    763 	'objectclass=*' > $TESTDIR/server$n.out 2>&1
    764 RC=$?
    765 
    766 if test $RC != 0 ; then
    767 	echo "ldapsearch failed at server $n ($RC)!"
    768 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    769 	exit $RC
    770 fi
    771 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
    772 n=`expr $n + 1`
    773 done
    774 
    775 n=2
    776 while [ $n -le $MPR ]; do
    777 echo "Comparing retrieved entries from server 1 and server $n..."
    778 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
    779 
    780 if test $? != 0 ; then
    781 	echo "test failed - server 1 and server $n databases differ"
    782 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    783 	exit 1
    784 fi
    785 n=`expr $n + 1`
    786 done
    787 
    788 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    789 
    790 echo ">>>>> Test succeeded"
    791 
    792 test $KILLSERVERS != no && wait
    793 
    794 exit 0
    795