test049-sync-config revision 1.1.1.2
1#! /bin/sh 2# OpenLDAP: pkg/ldap/tests/scripts/test049-sync-config,v 1.4.2.11 2009/03/05 23:32:21 quanah Exp 3## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4## 5## Copyright 1998-2009 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 16echo "running defines.sh" 17. $SRCDIR/scripts/defines.sh 18 19if test $SYNCPROV = syncprovno; then 20 echo "Syncrepl provider overlay not available, test skipped" 21 exit 0 22fi 23 24PRODIR=$TESTDIR/pro 25CONDIR=$TESTDIR/con1 26DBPRO=$PRODIR/db 27DBCON=$CONDIR/db 28CFPRO=$PRODIR/slapd.d 29CFCON=$CONDIR/slapd.d 30 31mkdir -p $TESTDIR $PRODIR $CONDIR $DBPRO $DBCON $CFPRO $CFCON 32 33$SLAPPASSWD -g -n >$CONFIGPWF 34 35if test x"$SYNCMODE" = x ; then 36 SYNCMODE=rp 37fi 38case "$SYNCMODE" in 39 ro) 40 SYNCTYPE="type=refreshOnly interval=00:00:00:03" 41 ;; 42 rp) 43 SYNCTYPE="type=refreshAndPersist" 44 ;; 45 *) 46 echo "unknown sync mode $SYNCMODE" 47 exit 1; 48 ;; 49esac 50 51# 52# Test replication of dynamic config: 53# - start producer 54# - start consumer 55# - configure over ldap 56# - populate over ldap 57# - configure syncrepl over ldap 58# - retrieve database over ldap and compare against expected results 59# 60 61echo "Starting producer slapd on TCP/IP port $PORT1..." 62. $CONFFILTER $BACKEND $MONITORDB < $DYNAMICCONF > $CONFLDIF 63$SLAPADD -F $CFPRO -n 0 -l $CONFLDIF 64cd $PRODIR 65$SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 & 66PID=$! 67if test $WAIT != 0 ; then 68 echo PID $PID 69 read foo 70fi 71KILLPIDS="$PID" 72cd $TESTWD 73 74sleep 1 75 76echo "Using ldapsearch to check that producer slapd is running..." 77for i in 0 1 2 3 4 5; do 78 $LDAPSEARCH -s base -b "" -H $URI1 \ 79 'objectclass=*' > /dev/null 2>&1 80 RC=$? 81 if test $RC = 0 ; then 82 break 83 fi 84 echo "Waiting 5 seconds for slapd to start..." 85 sleep 5 86done 87 88if test $RC != 0 ; then 89 echo "ldapsearch failed ($RC)!" 90 test $KILLSERVERS != no && kill -HUP $KILLPIDS 91 exit $RC 92fi 93 94echo "Inserting syncprov overlay on producer..." 95if [ "$SYNCPROV" = syncprovmod ]; then 96 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1 97dn: cn=module,cn=config 98objectClass: olcModuleList 99cn: module 100olcModulePath: ../../../servers/slapd/overlays 101olcModuleLoad: syncprov.la 102EOF 103 RC=$? 104 if test $RC != 0 ; then 105 echo "ldapadd failed for moduleLoad ($RC)!" 106 test $KILLSERVERS != no && kill -HUP $KILLPIDS 107 exit $RC 108 fi 109fi 110read CONFIGPW < $CONFIGPWF 111$LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1 112dn: olcDatabase={0}config,cn=config 113changetype: modify 114add: olcSyncRepl 115olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple 116 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist 117 retry="3 5 300 5" timeout=3 118- 119add: olcUpdateRef 120olcUpdateRef: $URI1 121 122dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config 123changetype: add 124objectClass: olcOverlayConfig 125objectClass: olcSyncProvConfig 126olcOverlay: syncprov 127EOF 128RC=$? 129if test $RC != 0 ; then 130 echo "ldapmodify failed for syncrepl config ($RC)!" 131 test $KILLSERVERS != no && kill -HUP $KILLPIDS 132 exit $RC 133fi 134 135echo "Starting consumer slapd on TCP/IP port $PORT2..." 136$SLAPADD -F $CFCON -n 0 -l $CONFLDIF 137cd $CONDIR 138$SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 & 139SLAVEPID=$! 140if test $WAIT != 0 ; then 141 echo SLAVEPID $SLAVEPID 142 read foo 143fi 144KILLPIDS="$KILLPIDS $SLAVEPID" 145cd $TESTWD 146 147sleep 1 148 149echo "Using ldapsearch to check that consumer slapd is running..." 150for i in 0 1 2 3 4 5; do 151 $LDAPSEARCH -s base -b "" -H $URI2 \ 152 'objectclass=*' > /dev/null 2>&1 153 RC=$? 154 if test $RC = 0 ; then 155 break 156 fi 157 echo "Waiting 5 seconds for slapd to start..." 158 sleep 5 159done 160 161if test $RC != 0 ; then 162 echo "ldapsearch failed ($RC)!" 163 test $KILLSERVERS != no && kill -HUP $KILLPIDS 164 exit $RC 165fi 166 167echo "Configuring syncrepl on consumer..." 168$LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1 169dn: olcDatabase={0}config,cn=config 170changetype: modify 171add: olcSyncRepl 172olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple 173 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist 174 retry="3 5 300 5" timeout=3 175- 176add: olcUpdateRef 177olcUpdateRef: $URI1 178EOF 179 180echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 181sleep $SLEEP1 182 183echo "Using ldapsearch to check that syncrepl received config changes..." 184RC=32 185for i in 0 1 2 3 4 5; do 186 RESULT=`$LDAPSEARCH -H $URI2 -D cn=config -y $CONFIGPWF \ 187 -s base -b "olcDatabase={0}config,cn=config" \ 188 '(olcUpdateRef=*)' 2>&1 | awk '/^dn:/ {print "OK"}'` 189 if test "x$RESULT" = "xOK" ; then 190 RC=0 191 break 192 fi 193 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 194 sleep $SLEEP1 195done 196 197if test $RC != 0 ; then 198 echo "ldapsearch failed ($RC)!" 199 test $KILLSERVERS != no && kill -HUP $KILLPIDS 200 exit $RC 201fi 202 203echo "Adding schema and databases on producer..." 204$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1 205include: file://$ABS_SCHEMADIR/core.ldif 206 207include: file://$ABS_SCHEMADIR/cosine.ldif 208 209include: file://$ABS_SCHEMADIR/inetorgperson.ldif 210 211include: file://$ABS_SCHEMADIR/openldap.ldif 212 213include: file://$ABS_SCHEMADIR/nis.ldif 214EOF 215RC=$? 216if test $RC != 0 ; then 217 echo "ldapadd failed for schema config ($RC)!" 218 test $KILLSERVERS != no && kill -HUP $KILLPIDS 219 exit $RC 220fi 221 222if [ "$BACKENDTYPE" = mod ]; then 223 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1 224dn: cn=module,cn=config 225objectClass: olcModuleList 226cn: module 227olcModulePath: ../../../servers/slapd/back-$BACKEND 228olcModuleLoad: back_$BACKEND.la 229EOF 230 RC=$? 231 if test $RC != 0 ; then 232 echo "ldapadd failed for backend config ($RC)!" 233 test $KILLSERVERS != no && kill -HUP $KILLPIDS 234 exit $RC 235 fi 236fi 237 238$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1 239dn: olcDatabase={1}$BACKEND,cn=config 240objectClass: olcDatabaseConfig 241objectClass: olc${BACKEND}Config 242olcDatabase: {1}$BACKEND 243olcSuffix: $BASEDN 244olcDbDirectory: ./db 245olcRootDN: $MANAGERDN 246olcRootPW: $PASSWD 247olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple 248 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE 249 retry="3 5 300 5" timeout=3 250olcUpdateRef: $URI1 251 252dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config 253changetype: add 254objectClass: olcOverlayConfig 255objectClass: olcSyncProvConfig 256olcOverlay: syncprov 257EOF 258RC=$? 259if test $RC != 0 ; then 260 echo "ldapadd failed for database config ($RC)!" 261 test $KILLSERVERS != no && kill -HUP $KILLPIDS 262 exit $RC 263fi 264 265case $BACKEND in 266bdb | hdb) 267 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1 268dn: olcDatabase={1}$BACKEND,cn=config 269changetype: modify 270add: olcDbIndex 271olcDbIndex: objectClass,entryUUID,entryCSN eq 272olcDbIndex: cn,uid pres,eq,sub 273EOF 274 RC=$? 275 if test $RC != 0 ; then 276 echo "ldapadd modify for database config ($RC)!" 277 test $KILLSERVERS != no && kill -HUP $KILLPIDS 278 exit $RC 279 fi 280 ;; 281esac 282 283echo "Using ldapadd to populate producer..." 284$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \ 285 >> $TESTOUT 2>&1 286RC=$? 287if test $RC != 0 ; then 288 echo "ldapadd failed for database config ($RC)!" 289 test $KILLSERVERS != no && kill -HUP $KILLPIDS 290 exit $RC 291fi 292 293echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 294sleep $SLEEP1 295 296echo "Using ldapsearch to check that syncrepl received database changes..." 297RC=32 298for i in 0 1 2 3 4 5; do 299 RESULT=`$LDAPSEARCH -H $URI2 \ 300 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \ 301 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'` 302 if test "x$RESULT" = "xOK" ; then 303 RC=0 304 break 305 fi 306 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 307 sleep $SLEEP1 308done 309 310if test $RC != 0 ; then 311 echo "ldapsearch failed ($RC)!" 312 test $KILLSERVERS != no && kill -HUP $KILLPIDS 313 exit $RC 314fi 315 316echo "Replacing olcSyncrepl on producer..." 317$LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1 318dn: olcDatabase={0}config,cn=config 319changetype: modify 320replace: olcSyncRepl 321olcSyncRepl: rid=002 provider=$URI1 binddn="cn=config" bindmethod=simple 322 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist 323 retry="3 5 300 5" timeout=3 324EOF 325echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 326sleep $SLEEP1 327 328echo "Using ldapsearch to read config from the producer..." 329$LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \ 330 'objectclass=*' > $MASTEROUT 2>&1 331RC=$? 332 333if test $RC != 0 ; then 334 echo "ldapsearch failed at producer ($RC)!" 335 test $KILLSERVERS != no && kill -HUP $KILLPIDS 336 exit $RC 337fi 338 339echo "Using ldapsearch to read config from the consumer..." 340$LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \ 341 'objectclass=*' > $SLAVEOUT 2>&1 342RC=$? 343 344if test $RC != 0 ; then 345 echo "ldapsearch failed at consumer ($RC)!" 346 test $KILLSERVERS != no && kill -HUP $KILLPIDS 347 exit $RC 348fi 349 350echo "Filtering producer results..." 351. $LDIFFILTER < $MASTEROUT > $MASTERFLT 352echo "Filtering consumer results..." 353. $LDIFFILTER < $SLAVEOUT > $SLAVEFLT 354 355echo "Comparing retrieved configs from producer and consumer..." 356$CMP $MASTERFLT $SLAVEFLT > $CMPOUT 357 358if test $? != 0 ; then 359 echo "test failed - producer and consumer configs differ" 360 test $KILLSERVERS != no && kill -HUP $KILLPIDS 361 exit 1 362fi 363 364echo "Using ldapsearch to read all the entries from the producer..." 365$LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \ 366 'objectclass=*' > $MASTEROUT 2>&1 367RC=$? 368 369if test $RC != 0 ; then 370 echo "ldapsearch failed at producer ($RC)!" 371 test $KILLSERVERS != no && kill -HUP $KILLPIDS 372 exit $RC 373fi 374 375echo "Using ldapsearch to read all the entries from the consumer..." 376$LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \ 377 'objectclass=*' > $SLAVEOUT 2>&1 378RC=$? 379 380if test $RC != 0 ; then 381 echo "ldapsearch failed at consumer ($RC)!" 382 test $KILLSERVERS != no && kill -HUP $KILLPIDS 383 exit $RC 384fi 385 386test $KILLSERVERS != no && kill -HUP $KILLPIDS 387 388echo "Filtering producer results..." 389. $LDIFFILTER < $MASTEROUT > $MASTERFLT 390echo "Filtering consumer results..." 391. $LDIFFILTER < $SLAVEOUT > $SLAVEFLT 392 393echo "Comparing retrieved entries from producer and consumer..." 394$CMP $MASTERFLT $SLAVEFLT > $CMPOUT 395 396if test $? != 0 ; then 397 echo "test failed - producer and consumer databases differ" 398 exit 1 399fi 400 401echo ">>>>> Test succeeded" 402 403test $KILLSERVERS != no && wait 404 405exit 0 406