1#! /bin/sh 2# OpenLDAP: pkg/ldap/tests/scripts/test054-syncreplication-parallel-load,v 1.1.2.5 2010/04/19 19:14:36 quanah Exp 3## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4## 5## Copyright 1998-2010 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 24mkdir -p $TESTDIR $DBDIR1 $DBDIR4 25 26# 27# Test replication: 28# - start producer 29# - start consumer 30# - populate over ldap 31# - perform some modifies and deleted 32# - attempt to modify the consumer (referral or chain) 33# - retrieve database over ldap and compare against expected results 34# 35 36echo "Starting producer slapd on TCP/IP port $PORT1..." 37. $CONFFILTER $BACKEND $MONITORDB < $SRMASTERCONF > $CONF1 38$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 & 39PID=$! 40if test $WAIT != 0 ; then 41 echo PID $PID 42 read foo 43fi 44KILLPIDS="$PID" 45 46sleep 1 47 48echo "Using ldapsearch to check that producer slapd is running..." 49for i in 0 1 2 3 4 5; do 50 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \ 51 'objectclass=*' > /dev/null 2>&1 52 RC=$? 53 if test $RC = 0 ; then 54 break 55 fi 56 echo "Waiting 5 seconds for slapd to start..." 57 sleep 5 58done 59 60if test $RC != 0 ; then 61 echo "ldapsearch failed ($RC)!" 62 test $KILLSERVERS != no && kill -HUP $KILLPIDS 63 exit $RC 64fi 65 66echo "Using ldapadd to create the context prefix entry in the producer..." 67$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \ 68 $LDIFORDEREDCP > /dev/null 2>&1 69RC=$? 70if test $RC != 0 ; then 71 echo "ldapadd failed ($RC)!" 72 test $KILLSERVERS != no && kill -HUP $KILLPIDS 73 exit $RC 74fi 75 76echo "Starting consumer slapd on TCP/IP port $PORT4..." 77. $CONFFILTER $BACKEND $MONITORDB < $P1SRSLAVECONF > $CONF4 78$SLAPD -f $CONF4 -h $URI4 -d $LVL $TIMING > $LOG4 2>&1 & 79SLAVEPID=$! 80if test $WAIT != 0 ; then 81 echo SLAVEPID $SLAVEPID 82 read foo 83fi 84KILLPIDS="$KILLPIDS $SLAVEPID" 85 86sleep 1 87 88echo "Using ldapsearch to check that consumer slapd is running..." 89for i in 0 1 2 3 4 5; do 90 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT4 \ 91 'objectclass=*' > /dev/null 2>&1 92 RC=$? 93 if test $RC = 0 ; then 94 break 95 fi 96 echo "Waiting 5 seconds for slapd to start..." 97 sleep 5 98done 99 100if test $RC != 0 ; then 101 echo "ldapsearch failed ($RC)!" 102 test $KILLSERVERS != no && kill -HUP $KILLPIDS 103 exit $RC 104fi 105 106MORELDIF=$TESTDIR/more.ldif 107TESTOUT1=$TESTDIR/testout1.out 108TESTOUT2=$TESTDIR/testout2.out 109sed -e 's/[Oo][Uu]=/ou=More /g' -e 's/^[Oo][Uu]: /ou: More /' \ 110 -e 's/cn=Manager/cn=More Manager/g' \ 111 -e 's/^cn: Manager/cn: More Manager/' \ 112 $LDIFORDEREDNOCP > $MORELDIF 113 114echo "Using ldapadd to populate the producer directory..." 115$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \ 116 $LDIFORDEREDNOCP > $TESTOUT1 2>&1 & 117C1PID=$! 118$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \ 119 $MORELDIF > $TESTOUT2 2>&1 & 120C2PID=$! 121wait $C1PID $C2PID 122 123echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 124sleep $SLEEP1 125 126echo "Stopping the provider, sleeping 10 seconds and restarting it..." 127kill -HUP "$PID" 128wait $PID 129sleep 10 130echo "RESTART" >> $LOG1 131$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 & 132PID=$! 133if test $WAIT != 0 ; then 134 echo PID $PID 135 read foo 136fi 137KILLPIDS="$PID $SLAVEPID" 138 139sleep 1 140 141echo "Using ldapsearch to check that producer slapd is running..." 142for i in 0 1 2 3 4 5; do 143 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \ 144 'objectclass=*' > /dev/null 2>&1 145 RC=$? 146 if test $RC = 0 ; then 147 break 148 fi 149 echo "Waiting 5 seconds for slapd to start..." 150 sleep 5 151done 152 153if test $RC != 0 ; then 154 echo "ldapsearch failed ($RC)!" 155 test $KILLSERVERS != no && kill -HUP $KILLPIDS 156 exit $RC 157fi 158 159echo "Waiting 10 seconds to let the system catch up" 160sleep 10 161 162echo "Using ldapmodify to modify producer directory..." 163 164# 165# Do some modifications 166# 167 168$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \ 169 $TESTOUT 2>&1 << EOMODS 170dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com 171changetype: modify 172add: drink 173drink: Orange Juice 174- 175delete: sn 176sn: Jones 177- 178add: sn 179sn: Jones 180 181dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 182changetype: modify 183replace: drink 184drink: Iced Tea 185 186dn: cn=ITD Staff,ou=Groups,dc=example,dc=com 187changetype: modify 188delete: uniquemember 189uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com 190uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 191- 192add: uniquemember 193uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com 194uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com 195 196dn: cn=All Staff,ou=Groups,dc=example,dc=com 197changetype: modify 198delete: description 199 200dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 201changetype: add 202objectclass: OpenLDAPperson 203cn: Gern Jensen 204sn: Jensen 205uid: gjensen 206title: Chief Investigator, ITD 207postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103 208seealso: cn=All Staff, ou=Groups, dc=example,dc=com 209drink: Coffee 210homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104 211description: Very odd 212facsimiletelephonenumber: +1 313 555 7557 213telephonenumber: +1 313 555 8343 214mail: gjensen@mailgw.example.com 215homephone: +1 313 555 8844 216 217dn: ou=Retired, ou=People, dc=example,dc=com 218changetype: add 219objectclass: organizationalUnit 220ou: Retired 221 222dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com 223changetype: add 224objectclass: OpenLDAPperson 225cn: Rosco P. Coltrane 226sn: Coltrane 227uid: rosco 228description: Fat tycoon 229 230dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com 231changetype: modrdn 232newrdn: cn=Rosco P. Coltrane 233deleteoldrdn: 1 234newsuperior: ou=Retired, ou=People, dc=example,dc=com 235 236dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com 237changetype: delete 238 239EOMODS 240 241RC=$? 242if test $RC != 0 ; then 243 echo "ldapmodify failed ($RC)!" 244 test $KILLSERVERS != no && kill -HUP $KILLPIDS 245 exit $RC 246fi 247 248echo "Using ldappasswd to change some passwords..." 249$LDAPPASSWD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \ 250 'cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com' \ 251 > $TESTOUT 2>&1 252RC=$? 253if test $RC != 0 ; then 254 echo "ldapmodify failed ($RC)!" 255 test $KILLSERVERS != no && kill -HUP $KILLPIDS 256 exit $RC 257fi 258 259echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 260sleep $SLEEP1 261 262echo "Stopping consumer to test recovery..." 263kill -HUP $SLAVEPID 264wait $SLAVEPID 265 266echo "Modifying more entries on the producer..." 267$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \ 268 $TESTOUT 2>&1 << EOMODS 269dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com 270changetype: delete 271 272dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 273changetype: modify 274add: drink 275drink: Mad Dog 20/20 276 277dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com 278changetype: add 279objectclass: OpenLDAPperson 280sn: Coltrane 281uid: rosco 282cn: Rosco P. Coltrane 283 284EOMODS 285 286echo "Restarting consumer..." 287echo "RESTART" >> $LOG4 288$SLAPD -f $CONF4 -h $URI4 -d $LVL $TIMING >> $LOG4 2>&1 & 289SLAVEPID=$! 290if test $WAIT != 0 ; then 291 echo SLAVEPID $SLAVEPID 292 read foo 293fi 294KILLPIDS="$PID $SLAVEPID" 295 296echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 297sleep $SLEEP1 298 299if test ! $BACKLDAP = "ldapno" ; then 300 echo "Try updating the consumer slapd..." 301 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT4 -w $PASSWD > \ 302 $TESTOUT 2>&1 << EOMODS 303dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com 304changetype: modify 305add: description 306description: This write must fail because directed to a shadow context, 307description: unless the chain overlay is configured appropriately ;) 308 309EOMODS 310 311 RC=$? 312 if test $RC != 0 ; then 313 echo "ldapmodify failed ($RC)!" 314 test $KILLSERVERS != no && kill -HUP $KILLPIDS 315 exit $RC 316 fi 317 318 # ITS#4964 319 echo "Trying to change some passwords on the consumer..." 320 $LDAPPASSWD -D "$MANAGERDN" -h $LOCALHOST -p $PORT4 -w $PASSWD \ 321 'cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com' \ 322 > $TESTOUT 2>&1 323 RC=$? 324 if test $RC != 0 ; then 325 echo "ldapmodify failed ($RC)!" 326 test $KILLSERVERS != no && kill -HUP $KILLPIDS 327 exit $RC 328 fi 329 330 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 331 sleep $SLEEP1 332fi 333 334OPATTRS="entryUUID creatorsName createTimestamp modifiersName modifyTimestamp" 335 336echo "Using ldapsearch to read all the entries from the producer..." 337$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 338 '(objectclass=*)' '*' $OPATTRS > $MASTEROUT 2>&1 339RC=$? 340 341if test $RC != 0 ; then 342 echo "ldapsearch failed at producer ($RC)!" 343 test $KILLSERVERS != no && kill -HUP $KILLPIDS 344 exit $RC 345fi 346 347echo "Using ldapsearch to read all the entries from the consumer..." 348$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT4 \ 349 '(objectclass=*)' '*' $OPATTRS > $SLAVEOUT 2>&1 350RC=$? 351 352if test $RC != 0 ; then 353 echo "ldapsearch failed at consumer ($RC)!" 354 test $KILLSERVERS != no && kill -HUP $KILLPIDS 355 exit $RC 356fi 357 358test $KILLSERVERS != no && kill -HUP $KILLPIDS 359 360echo "Filtering producer results..." 361$LDIFFILTER < $MASTEROUT > $MASTERFLT 362echo "Filtering consumer results..." 363$LDIFFILTER < $SLAVEOUT > $SLAVEFLT 364 365echo "Comparing retrieved entries from producer and consumer..." 366$CMP $MASTERFLT $SLAVEFLT > $CMPOUT 367 368if test $? != 0 ; then 369 echo "test failed - producer and consumer databases differ" 370 exit 1 371fi 372 373echo ">>>>> Test succeeded" 374 375test $KILLSERVERS != no && wait 376 377exit 0 378