Home | History | Annotate | Line # | Download | only in scripts
test063-delta-multiprovider revision 1.1
      1 #! /bin/sh
      2 # $OpenLDAP$
      3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4 ##
      5 ## Copyright 1998-2021 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 if test $ACCESSLOG = accesslogno; then
     24 	echo "Accesslog overlay not available, test skipped"
     25 	exit 0
     26 fi
     27 
     28 MPR=${MPR-4}
     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 interval=00:00:00:03"
     46 		;;
     47 	*)
     48 		echo "unknown sync mode $SYNCMODE"
     49 		exit 1;
     50 		;;
     51 esac
     52 
     53 #
     54 # Test delta-sync mpr
     55 # - start servers
     56 # - configure over ldap
     57 # - populate over ldap
     58 # - configure syncrepl over ldap
     59 # - break replication
     60 # - modify each server separately
     61 # - restore replication
     62 # - compare results
     63 #
     64 
     65 nullExclude=""
     66 test $BACKEND = null && nullExclude="# "
     67 
     68 KILLPIDS=
     69 
     70 echo "Initializing server configurations..."
     71 n=1
     72 while [ $n -le $MPR ]; do
     73 
     74 DBDIR=${XDIR}$n/db
     75 CFDIR=${XDIR}$n/slapd.d
     76 
     77 mkdir -p ${XDIR}$n $DBDIR.1 $DBDIR.2 $CFDIR
     78 
     79 cat > $TMP <<EOF
     80 dn: cn=config
     81 objectClass: olcGlobal
     82 cn: config
     83 EOF
     84 
     85 o=1
     86 while [ $o -le $MPR ]; do
     87 PORT=`expr $BASEPORT + $o`
     88 URI="ldap://${LOCALHOST}:$PORT/"
     89 echo "olcServerID: $o $URI" >> $TMP
     90 o=`expr $o + 1`
     91 done
     92 echo "" >> $TMP
     93 
     94 if [ "$SYNCPROV" = syncprovmod -o "$ACCESSLOG" = accesslogmod ]; then
     95   cat <<EOF >> $TMP
     96 dn: cn=module,cn=config
     97 objectClass: olcModuleList
     98 cn: module
     99 olcModulePath: $TESTWD/../servers/slapd/overlays
    100 EOF
    101   if [ "$SYNCPROV" = syncprovmod ]; then
    102   echo "olcModuleLoad: syncprov.la" >> $TMP
    103   fi
    104   if [ "$ACCESSLOG" = accesslogmod ]; then
    105   echo "olcModuleLoad: accesslog.la" >> $TMP
    106   fi
    107   echo "" >> $TMP
    108 fi
    109 
    110 if [ "$BACKENDTYPE" = mod ]; then
    111 cat <<EOF >> $TMP
    112 dn: cn=module,cn=config
    113 objectClass: olcModuleList
    114 cn: module
    115 olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
    116 olcModuleLoad: back_$BACKEND.la
    117 
    118 EOF
    119 fi
    120 
    121 MYURI=`eval echo '$URI'$n`
    122 PROVIDERURI=`eval echo '$URI'$o`
    123 if test $INDEXDB = indexdb ; then
    124 INDEX1="olcDbIndex: objectClass,entryCSN,reqStart,reqDN,reqResult eq"
    125 INDEX2="olcDbIndex: objectClass,entryCSN,entryUUID eq"
    126 else
    127 INDEX1=
    128 INDEX2=
    129 fi
    130 cat >> $TMP <<EOF
    131 dn: cn=schema,cn=config
    132 objectclass: olcSchemaconfig
    133 cn: schema
    134 
    135 include: file://$ABS_SCHEMADIR/core.ldif
    136 
    137 include: file://$ABS_SCHEMADIR/cosine.ldif
    138 
    139 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
    140 
    141 include: file://$ABS_SCHEMADIR/openldap.ldif
    142 
    143 include: file://$ABS_SCHEMADIR/nis.ldif
    144 
    145 dn: olcDatabase={0}config,cn=config
    146 objectClass: olcDatabaseConfig
    147 olcDatabase: {0}config
    148 olcRootPW:< file://$CONFIGPWF
    149 
    150 dn: olcDatabase={1}$BACKEND,cn=config
    151 objectClass: olcDatabaseConfig
    152 ${nullExclude}objectClass: olc${BACKEND}Config
    153 olcDatabase: {1}$BACKEND
    154 olcSuffix: cn=log
    155 ${nullExclude}olcDbDirectory: ${DBDIR}.1
    156 olcRootDN: $MANAGERDN
    157 $INDEX1
    158 
    159 dn: olcOverlay=syncprov,olcDatabase={1}$BACKEND,cn=config
    160 objectClass: olcOverlayConfig
    161 objectClass: olcSyncProvConfig
    162 olcOverlay: syncprov
    163 olcSpNoPresent: TRUE
    164 olcSpReloadHint: TRUE
    165 
    166 dn: olcDatabase={2}$BACKEND,cn=config
    167 objectClass: olcDatabaseConfig
    168 ${nullExclude}objectClass: olc${BACKEND}Config
    169 olcDatabase: {2}$BACKEND
    170 olcSuffix: $BASEDN
    171 ${nullExclude}olcDbDirectory: ${DBDIR}.2
    172 olcRootDN: $MANAGERDN
    173 olcRootPW: $PASSWD
    174 EOF
    175 
    176 o=1
    177 while [ $o -le $MPR ]; do
    178 PORT=`expr $BASEPORT + $o`
    179 URI="ldap://${LOCALHOST}:$PORT/"
    180 cat >>$TMP <<EOF
    181 olcSyncRepl: rid=00$o provider=$URI binddn="$MANAGERDN" bindmethod=simple
    182   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
    183   retry="3 +" timeout=3 logbase="cn=log"
    184   logfilter="(&(objectclass=auditWriteObject)(reqresult=0))"
    185   syncdata=accesslog
    186 EOF
    187 o=`expr $o + 1`
    188 done
    189 
    190 cat >> $TMP <<EOF
    191 olcMultiProvider: TRUE
    192 $INDEX2
    193 
    194 dn: olcOverlay=syncprov,olcDatabase={2}$BACKEND,cn=config
    195 objectClass: olcOverlayConfig
    196 objectClass: olcSyncProvConfig
    197 olcOverlay: syncprov
    198 
    199 dn: olcOverlay=accesslog,olcDatabase={2}$BACKEND,cn=config
    200 objectClass: olcOverlayConfig
    201 objectClass: olcAccessLogConfig
    202 olcOverlay: accesslog
    203 olcAccessLogDB: cn=log
    204 olcAccessLogOps: writes
    205 olcAccessLogSuccess: TRUE
    206 
    207 EOF
    208 cat <<EOF >> $TMP
    209 dn: olcDatabase={3}monitor,cn=config
    210 objectClass: olcDatabaseConfig
    211 objectClass: olcmonitorConfig
    212 olcDatabase: {3}monitor
    213 
    214 EOF
    215 
    216 $SLAPADD -F $CFDIR -n 0  -d-1< $TMP > $TESTOUT 2>&1
    217 PORT=`eval echo '$PORT'$n`
    218 echo "Starting server $n on TCP/IP port $PORT..."
    219 cd ${XDIR}${n}
    220 LOG=`eval echo '$LOG'$n`
    221 $SLAPD -F slapd.d -h $MYURI -d $LVL > $LOG 2>&1 &
    222 PID=$!
    223 if test $WAIT != 0 ; then
    224     echo PID $PID
    225     read foo
    226 fi
    227 KILLPIDS="$PID $KILLPIDS"
    228 cd $TESTWD
    229 
    230 echo "Using ldapsearch to check that server $n is running..."
    231 sleep 1
    232 for i in 0 1 2 3 4 5; do
    233 	$LDAPSEARCH -s base -b "" -H $MYURI \
    234 		'objectclass=*' > /dev/null 2>&1
    235 	RC=$?
    236 	if test $RC = 0 ; then
    237 		break
    238 	fi
    239 	echo "Waiting 5 seconds for slapd to start..."
    240 	sleep 5
    241 done
    242 
    243 if test $RC != 0 ; then
    244 	echo "ldapsearch failed ($RC)!"
    245 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    246 	exit $RC
    247 fi
    248 
    249 if [ $n = 1 ]; then
    250 echo "Using ldapadd for context on server 1..."
    251 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDEREDCP \
    252 	>> $TESTOUT 2>&1
    253 RC=$?
    254 if test $RC != 0 ; then
    255 	echo "ldapadd failed for server $n database ($RC)!"
    256 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    257 	exit $RC
    258 fi
    259 fi
    260 
    261 n=`expr $n + 1`
    262 done
    263 
    264 echo "Using ldapadd to populate server 1..."
    265 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDEREDNOCP \
    266 	>> $TESTOUT 2>&1
    267 RC=$?
    268 if test $RC != 0 ; then
    269 	echo "ldapadd failed for server $n database ($RC)!"
    270 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    271 	exit $RC
    272 fi
    273 
    274 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    275 sleep $SLEEP1
    276 
    277 n=1
    278 while [ $n -le $MPR ]; do
    279 PORT=`expr $BASEPORT + $n`
    280 URI="ldap://${LOCALHOST}:$PORT/"
    281 
    282 echo "Using ldapsearch to read all the entries from server $n..."
    283 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
    284 	'objectclass=*' > $TESTDIR/server$n.out 2>&1
    285 RC=$?
    286 
    287 if test $RC != 0 ; then
    288 	echo "ldapsearch failed at server $n ($RC)!"
    289 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    290 	exit $RC
    291 fi
    292 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
    293 n=`expr $n + 1`
    294 done
    295 
    296 n=2
    297 while [ $n -le $MPR ]; do
    298 echo "Comparing retrieved entries from server 1 and server $n..."
    299 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
    300 
    301 if test $? != 0 ; then
    302 	echo "test failed - server 1 and server $n databases differ"
    303 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    304 	exit 1
    305 fi
    306 n=`expr $n + 1`
    307 done
    308 
    309 echo "Using ldapadd to populate server 2..."
    310 cp $LDIFADD1 $TESTDIR/add.ldif
    311 echo "displayName: The other" >>$TESTDIR/add.ldif
    312 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $TESTDIR/add.ldif \
    313 	>> $TESTOUT 2>&1
    314 RC=$?
    315 if test $RC != 0 ; then
    316 	echo "ldapadd failed for server 2 database ($RC)!"
    317 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    318 	exit $RC
    319 fi
    320 
    321 THEDN="cn=James A Jones 2,ou=Alumni Association,ou=People,dc=example,dc=com"
    322 sleep 1
    323 for i in 1 2 3; do
    324 	$LDAPSEARCH -S "" -b "$THEDN" -H $URI1 \
    325 		-s base '(objectClass=*)' entryCSN > "${PROVIDEROUT}.$i" 2>&1
    326 	RC=$?
    327 
    328 	if test $RC = 0 ; then
    329 		break
    330 	fi
    331 
    332 	if test $RC != 32 ; then
    333 		echo "ldapsearch failed at consumer ($RC)!"
    334 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
    335 		exit $RC
    336 	fi
    337 
    338 	echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    339 	sleep $SLEEP1
    340 done
    341 
    342 n=1
    343 while [ $n -le $MPR ]; do
    344 PORT=`expr $BASEPORT + $n`
    345 URI="ldap://${LOCALHOST}:$PORT/"
    346 
    347 echo "Using ldapsearch to read all the entries from server $n..."
    348 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
    349 	'objectclass=*' > $TESTDIR/server$n.out 2>&1
    350 RC=$?
    351 
    352 if test $RC != 0 ; then
    353 	echo "ldapsearch failed at server $n ($RC)!"
    354 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    355 	exit $RC
    356 fi
    357 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
    358 n=`expr $n + 1`
    359 done
    360 
    361 n=2
    362 while [ $n -le $MPR ]; do
    363 echo "Comparing retrieved entries from server 1 and server $n..."
    364 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
    365 
    366 if test $? != 0 ; then
    367 	echo "test failed - server 1 and server $n databases differ"
    368 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    369 	exit 1
    370 fi
    371 n=`expr $n + 1`
    372 done
    373 
    374 echo "Breaking replication between server 1 and 2..."
    375 n=1
    376 while [ $n -le 2 ]; do
    377 MYURI=`eval echo '$URI'$n`
    378 o=`expr $n - 1`
    379 $LDAPMODIFY -D cn=config -H $MYURI -y $CONFIGPWF > $TESTOUT 2>&1 <<EOF
    380 dn: olcDatabase={2}$BACKEND,cn=config
    381 changetype: modify
    382 delete: olcSyncRepl
    383 -
    384 
    385 EOF
    386 RC=$?
    387 if test $RC != 0 ; then
    388 	echo "ldapmodify failed for server $n config ($RC)!"
    389 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    390 	exit $RC
    391 fi
    392 n=`expr $n + 1`
    393 done
    394 
    395 echo "Using ldapmodify to force conflicts between server 1 and 2..."
    396 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
    397 	>> $TESTOUT 2>&1 << EOF
    398 dn: $THEDN
    399 changetype: modify
    400 add: description
    401 description: Amazing
    402 -
    403 add: displayName
    404 displayName: James the Second
    405 -
    406 delete: displayName
    407 displayName: The other
    408 
    409 EOF
    410 RC=$?
    411 if test $RC != 0 ; then
    412 	echo "ldapmodify failed for server 1 database ($RC)!"
    413 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    414 	exit $RC
    415 fi
    416 
    417 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
    418 	>> $TESTOUT 2>&1 << EOF
    419 dn: $THEDN
    420 changetype: modify
    421 replace: employeetype
    422 -
    423 add: description
    424 description: Stupendous
    425 -
    426 add: displayName
    427 displayName: James II
    428 -
    429 delete: displayName
    430 displayName: The other
    431 
    432 EOF
    433 RC=$?
    434 if test $RC != 0 ; then
    435 	echo "ldapmodify failed for server 2 database ($RC)!"
    436 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    437 	exit $RC
    438 fi
    439 
    440 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
    441 	>> $TESTOUT 2>&1 << EOF
    442 dn: $THEDN
    443 changetype: modify
    444 delete: description
    445 description: Outstanding
    446 -
    447 add: description
    448 description: Mindboggling
    449 
    450 EOF
    451 RC=$?
    452 if test $RC != 0 ; then
    453 	echo "ldapmodify failed for server 1 database ($RC)!"
    454 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    455 	exit $RC
    456 fi
    457 
    458 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
    459 	>> $TESTOUT 2>&1 << EOF
    460 dn: $THEDN
    461 changetype: modify
    462 delete: description
    463 description: OutStanding
    464 -
    465 add: description
    466 description: Bizarre
    467 
    468 EOF
    469 RC=$?
    470 if test $RC != 0 ; then
    471 	echo "ldapmodify failed for server 2 database ($RC)!"
    472 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    473 	exit $RC
    474 fi
    475 
    476 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
    477 	>> $TESTOUT 2>&1 << EOF
    478 dn: $THEDN
    479 changetype: modify
    480 add: carLicense
    481 carLicense: 123-XYZ
    482 -
    483 add: employeeNumber
    484 employeeNumber: 32
    485 
    486 EOF
    487 RC=$?
    488 if test $RC != 0 ; then
    489 	echo "ldapmodify failed for server 1 database ($RC)!"
    490 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    491 	exit $RC
    492 fi
    493 
    494 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
    495 	>> $TESTOUT 2>&1 << EOF
    496 dn: $THEDN
    497 changetype: modify
    498 add: employeeType
    499 employeeType: deadwood
    500 -
    501 add: employeeNumber
    502 employeeNumber: 64
    503 
    504 EOF
    505 RC=$?
    506 if test $RC != 0 ; then
    507 	echo "ldapmodify failed for server 2 database ($RC)!"
    508 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    509 	exit $RC
    510 fi
    511 
    512 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
    513 	>> $TESTOUT 2>&1 << EOF
    514 dn: $THEDN
    515 changetype: modify
    516 replace: sn
    517 sn: Replaced later
    518 -
    519 replace: sn
    520 sn: Surname
    521 EOF
    522 RC=$?
    523 if test $RC != 0 ; then
    524 	echo "ldapmodify failed for server 1 database ($RC)!"
    525 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    526 	exit $RC
    527 fi
    528 
    529 echo "Restoring replication between server 1 and 2..."
    530 cat > $TMP <<EOF
    531 dn: olcDatabase={2}$BACKEND,cn=config
    532 changetype: modify
    533 add: olcSyncRepl
    534 EOF
    535 n=1
    536 while [ $n -le $MPR ]; do
    537 MYURI=`eval echo '$URI'$n`
    538 PROVIDERURI=`eval echo '$URI'$n`
    539 cat >> $TMP <<EOF
    540 olcSyncRepl: rid=00$n provider=$PROVIDERURI binddn="$MANAGERDN" bindmethod=simple
    541   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
    542   retry="3 +" timeout=3 logbase="cn=log"
    543   logfilter="(&(objectclass=auditWriteObject)(reqresult=0))"
    544   syncdata=accesslog
    545 EOF
    546 n=`expr $n + 1`
    547 done
    548 cat >> $TMP <<EOF
    549 -
    550 replace: olcMultiProvider
    551 olcMultiProvider: TRUE
    552 EOF
    553 n=1
    554 while [ $n -le 2 ]; do
    555 MYURI=`eval echo '$URI'$n`
    556 $LDAPMODIFY -D cn=config -H $MYURI -y $CONFIGPWF > $TESTOUT 2>&1 <$TMP
    557 RC=$?
    558 if test $RC != 0 ; then
    559 	echo "ldapmodify failed for server $n config ($RC)!"
    560 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    561 	exit $RC
    562 fi
    563 n=`expr $n + 1`
    564 done
    565 
    566 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    567 sleep $SLEEP1
    568 
    569 n=1
    570 while [ $n -le $MPR ]; do
    571 PORT=`expr $BASEPORT + $n`
    572 URI="ldap://${LOCALHOST}:$PORT/"
    573 
    574 echo "Using ldapsearch to read all the entries from server $n..."
    575 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD  \
    576 	'objectclass=*' > $TESTDIR/server$n.out 2>&1
    577 RC=$?
    578 
    579 if test $RC != 0 ; then
    580 	echo "ldapsearch failed at server $n ($RC)!"
    581 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    582 	exit $RC
    583 fi
    584 $LDIFFILTER -s a < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
    585 n=`expr $n + 1`
    586 done
    587 
    588 n=2
    589 while [ $n -le $MPR ]; do
    590 echo "Comparing retrieved entries from server 1 and server $n..."
    591 $CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT
    592 
    593 if test $? != 0 ; then
    594 	echo "test failed - server 1 and server $n databases differ"
    595 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    596 	exit 1
    597 fi
    598 n=`expr $n + 1`
    599 done
    600 
    601 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    602 
    603 echo ">>>>> Test succeeded"
    604 
    605 test $KILLSERVERS != no && wait
    606 
    607 exit 0
    608