1#! /bin/sh 2# OpenLDAP: pkg/ldap/tests/scripts/test048-syncrepl-multiproxy,v 1.1.2.13 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 $BACKLDAP = ldapno; then 20 echo "LDAP backend not available, test skipped" 21 exit 0 22fi 23 24if test $SYNCPROV = syncprovno; then 25 echo "Syncrepl provider overlay not available, test skipped" 26 exit 0 27fi 28 29if test $MONITORDB = no; then 30 echo "Monitor backend not available, test skipped" 31 exit 0 32fi 33 34if test $THREADS = threadsno ; then 35 echo "Need threads support, test skipped" 36 exit 0 37fi 38 39mkdir -p $TESTDIR $DBDIR1 $DBDIR2 $DBDIR3 40 41# 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 49# 50 51echo "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 & 54MASTERPID=$! 55if test $WAIT != 0 ; then 56 echo MASTERPID $MASTERPID 57 read foo 58fi 59KILLPIDS="$MASTERPID" 60 61sleep 1 62 63echo "Using ldapsearch to check that master slapd is running..." 64for 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 70 fi 71 echo "Waiting 5 seconds for slapd to start..." 72 sleep 5 73done 74 75if test $RC != 0 ; then 76 echo "ldapsearch failed ($RC)!" 77 test $KILLSERVERS != no && kill -HUP $KILLPIDS 78 exit $RC 79fi 80 81echo "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 84RC=$? 85if test $RC != 0 ; then 86 echo "ldapadd failed ($RC)!" 87 test $KILLSERVERS != no && kill -HUP $KILLPIDS 88 exit $RC 89fi 90 91echo "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 & 94P1SLAVEPID=$! 95if test $WAIT != 0 ; then 96 echo P1SLAVEPID $P1SLAVEPID 97 read foo 98fi 99KILLPIDS="$MASTERPID $P1SLAVEPID" 100 101sleep 1 102 103echo "Using ldapsearch to check that P1 slave slapd is running..." 104for 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 110 fi 111 echo "Waiting 5 seconds for slapd to start..." 112 sleep 5 113done 114 115if test $RC != 0 ; then 116 echo "ldapsearch failed ($RC)!" 117 test $KILLSERVERS != no && kill -HUP $KILLPIDS 118 exit $RC 119fi 120 121echo "Starting R1 slave slapd on TCP/IP port $PORT3..." 122. $CONFFILTER $BACKEND $MONITORDB < $RSLAVECONF | sed -e 's;\.2\.\([^/]*\)$;.3.\1;' > $CONF3 123$SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 & 124R1SLAVEPID=$! 125if test $WAIT != 0 ; then 126 echo R1SLAVEPID $R1SLAVEPID 127 read foo 128fi 129KILLPIDS="$MASTERPID $P1SLAVEPID $R1SLAVEPID" 130 131sleep 1 132 133echo "Using ldapsearch to check that R1 slave slapd is running..." 134for 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 140 fi 141 echo "Waiting 5 seconds for slapd to start..." 142 sleep 5 143done 144 145if test $RC != 0 ; then 146 echo "ldapsearch failed ($RC)!" 147 test $KILLSERVERS != no && kill -HUP $KILLPIDS 148 exit $RC 149fi 150 151CHECK=1 152echo "$CHECK > Using ldapadd to populate the master directory..." 153$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \ 154 $LDIFORDEREDNOCP > /dev/null 2>&1 155RC=$? 156if test $RC != 0 ; then 157 echo "ldapadd failed ($RC)!" 158 test $KILLSERVERS != no && kill -HUP $KILLPIDS 159 exit $RC 160fi 161 162echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 163sleep $SLEEP1 164 165#echo "Using ldapsearch to read all the entries from the master..." 166$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 167 '(objectClass=*)' > "${MASTEROUT}.1" 2>&1 168RC=$? 169 170if test $RC != 0 ; then 171 echo "ldapsearch failed at master ($RC)!" 172 test $KILLSERVERS != no && kill -HUP $KILLPIDS 173 exit $RC 174fi 175 176#echo "Using ldapsearch to read all the entries from the P1 slave..." 177$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \ 178 '(objectClass=*)' > "${SLAVEOUT}.1" 2>&1 179RC=$? 180 181if test $RC != 0 ; then 182 echo "ldapsearch failed at P1 slave ($RC)!" 183 test $KILLSERVERS != no && kill -HUP $KILLPIDS 184 exit $RC 185fi 186 187#echo "Filtering master results..." 188$LDIFFILTER < "${MASTEROUT}.1" > $MASTERFLT 189#echo "Filtering slave results..." 190$LDIFFILTER < "${SLAVEOUT}.1" > $SLAVEFLT 191 192echo "$CHECK < Comparing retrieved entries from master and P1 slave..." 193$CMP $MASTERFLT $SLAVEFLT > $CMPOUT 194 195if test $? != 0 ; then 196 echo "test failed - master and P1 slave databases differ" 197 test $KILLSERVERS != no && kill -HUP $KILLPIDS 198 exit 1 199fi 200 201#echo "Using ldapsearch to read all the entries from the R1 slave..." 202$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \ 203 '(objectClass=*)' > "${SLAVEOUT}.1" 2>&1 204RC=$? 205 206if test $RC != 0 ; then 207 echo "ldapsearch failed at R1 slave ($RC)!" 208 test $KILLSERVERS != no && kill -HUP $KILLPIDS 209 exit $RC 210fi 211 212#echo "Filtering slave results..." 213$LDIFFILTER < "${SLAVEOUT}.1" > $SLAVEFLT 214 215echo "$CHECK < Comparing retrieved entries from master and R1 slave..." 216$CMP $MASTERFLT $SLAVEFLT > $CMPOUT 217 218if test $? != 0 ; then 219 echo "test failed - master and R1 slave databases differ" 220 test $KILLSERVERS != no && kill -HUP $KILLPIDS 221 exit 1 222fi 223 224CHECK=`expr $CHECK + 1` 225echo "$CHECK > Stopping the provider, sleeping $SLEEP2 seconds and restarting it..." 226kill -HUP "$MASTERPID" 227wait $MASTERPID 228sleep $SLEEP2 229 230echo "======================= RESTART =======================" >> $LOG1 231$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 & 232MASTERPID=$! 233if test $WAIT != 0 ; then 234 echo MASTERPID $MASTERPID 235 read foo 236fi 237KILLPIDS="$MASTERPID $P1SLAVEPID $R1SLAVEPID" 238 239sleep 1 240 241echo "Using ldapsearch to check that master slapd is running..." 242for i in 0 1 2 3 4 5; do 243 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \ 244 '(objectClass=*)' > /dev/null 2>&1 245 RC=$? 246 if test $RC = 0 ; then 247 break 248 fi 249 echo "Waiting 5 seconds for slapd to start..." 250 sleep 5 251done 252 253if test $RC != 0 ; then 254 echo "ldapsearch failed ($RC)!" 255 test $KILLSERVERS != no && kill -HUP $KILLPIDS 256 exit $RC 257fi 258 259echo "Using ldapmodify to modify master directory..." 260 261# 262# Do some modifications 263# 264 265$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \ 266 $TESTOUT 2>&1 << EOMODS 267dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com 268changetype: modify 269add: drink 270drink: Orange Juice 271- 272delete: sn 273sn: Jones 274- 275add: sn 276sn: Jones 277 278dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 279changetype: modify 280replace: drink 281drink: Iced Tea 282 283dn: cn=ITD Staff,ou=Groups,dc=example,dc=com 284changetype: modify 285delete: uniquemember 286uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com 287uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 288- 289add: uniquemember 290uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com 291uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com 292 293dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc 294 =com 295changetype: modify 296delete: cn 297cn: Biiff Jensen 298 299dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 300changetype: add 301objectclass: OpenLDAPperson 302cn: Gern Jensen 303sn: Jensen 304uid: gjensen 305title: Chief Investigator, ITD 306postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103 307seealso: cn=All Staff, ou=Groups, dc=example,dc=com 308drink: Coffee 309homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104 310description: Very odd 311facsimiletelephonenumber: +1 313 555 7557 312telephonenumber: +1 313 555 8343 313mail: gjensen@mailgw.example.com 314homephone: +1 313 555 8844 315 316dn: ou=Retired, ou=People, dc=example,dc=com 317changetype: add 318objectclass: organizationalUnit 319ou: Retired 320 321dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com 322changetype: add 323objectclass: OpenLDAPperson 324cn: Rosco P. Coltrane 325sn: Coltrane 326uid: rosco 327description: Fat tycoon 328 329dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com 330changetype: modrdn 331newrdn: cn=Rosco P. Coltrane 332deleteoldrdn: 1 333newsuperior: ou=Retired, ou=People, dc=example,dc=com 334 335dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com 336changetype: delete 337EOMODS 338 339RC=$? 340if test $RC != 0 ; then 341 echo "ldapmodify failed ($RC)!" 342 test $KILLSERVERS != no && kill -HUP $KILLPIDS 343 exit $RC 344fi 345 346echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 347sleep $SLEEP1 348 349#echo "Using ldapsearch to read all the entries from the master..." 350$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 351 '(objectClass=*)' > "${MASTEROUT}.2" 2>&1 352RC=$? 353 354if test $RC != 0 ; then 355 echo "ldapsearch failed at master ($RC)!" 356 test $KILLSERVERS != no && kill -HUP $KILLPIDS 357 exit $RC 358fi 359 360#echo "Using ldapsearch to read all the entries from the P1 slave..." 361$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \ 362 '(objectClass=*)' > "${SLAVEOUT}.2" 2>&1 363RC=$? 364 365if test $RC != 0 ; then 366 echo "ldapsearch failed at P1 slave ($RC)!" 367 test $KILLSERVERS != no && kill -HUP $KILLPIDS 368 exit $RC 369fi 370 371#echo "Filtering master results..." 372$LDIFFILTER < "${MASTEROUT}.2" > $MASTERFLT 373#echo "Filtering P1 slave results..." 374$LDIFFILTER < "${SLAVEOUT}.2" > $SLAVEFLT 375 376echo "$CHECK < Comparing retrieved entries from master and P1 slave..." 377$CMP $MASTERFLT $SLAVEFLT > $CMPOUT 378 379if test $? != 0 ; then 380 echo "test failed - master and P1 slave databases differ" 381 test $KILLSERVERS != no && kill -HUP $KILLPIDS 382 exit 1 383fi 384 385#echo "Using ldapsearch to read all the entries from the R1 slave..." 386$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \ 387 '(objectClass=*)' > "${SLAVEOUT}.2" 2>&1 388RC=$? 389 390if test $RC != 0 ; then 391 echo "ldapsearch failed at R1 slave ($RC)!" 392 test $KILLSERVERS != no && kill -HUP $KILLPIDS 393 exit $RC 394fi 395 396#echo "Filtering slave results..." 397$LDIFFILTER < "${SLAVEOUT}.2" > $SLAVEFLT 398 399echo "$CHECK < Comparing retrieved entries from master and R1 slave..." 400$CMP $MASTERFLT $SLAVEFLT > $CMPOUT 401 402if test $? != 0 ; then 403 echo "test failed - master and R1 slave databases differ" 404 test $KILLSERVERS != no && kill -HUP $KILLPIDS 405 exit 1 406fi 407 408CHECK=`expr $CHECK + 1` 409echo "$CHECK > Stopping slaves to test recovery..." 410kill -HUP $P1SLAVEPID $R1SLAVEPID 411wait $P1SLAVEPID 412wait $R1SLAVEPID 413 414echo "Modifying more entries on the master..." 415$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \ 416 $TESTOUT 2>&1 << EOMODS 417dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 418changetype: modify 419add: description 420description: r1 slave is down... 421 422dn: cn=James T. Kirk, ou=Retired, ou=People, dc=example,dc=com 423changetype: add 424objectclass: OpenLDAPperson 425sn: Kirk 426uid: jtk 427cn: James T. Kirk 428 429dn: cn=Tiberius J. Hooker, ou=Retired, ou=People, dc=example,dc=com 430changetype: add 431objectclass: OpenLDAPperson 432sn: Hooker 433uid: tjh 434cn: Tiberius J. Hooker 435 436EOMODS 437 438echo "Restarting P1 slave..." 439echo "======================= RESTART =======================" >> $LOG3 440$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 & 441P1SLAVEPID=$! 442if test $WAIT != 0 ; then 443 echo P1SLAVEPID $P1SLAVEPID 444 read foo 445fi 446 447echo "Restarting R1 slave..." 448echo "======================= RESTART =======================" >> $LOG3 449$SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 & 450R1SLAVEPID=$! 451if test $WAIT != 0 ; then 452 echo R1SLAVEPID $R1SLAVEPID 453 read foo 454fi 455KILLPIDS="$MASTERPID $P1SLAVEPID $R1SLAVEPID" 456 457echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..." 458sleep $SLEEP2 459 460#echo "Using ldapsearch to read all the entries from the master..." 461$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 462 '(objectClass=*)' > "${MASTEROUT}.3" 2>&1 463RC=$? 464 465if test $RC != 0 ; then 466 echo "ldapsearch failed at master ($RC)!" 467 test $KILLSERVERS != no && kill -HUP $KILLPIDS 468 exit $RC 469fi 470 471#echo "Using ldapsearch to read all the entries from the P1 slave..." 472$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \ 473 '(objectClass=*)' > "${SLAVEOUT}.3" 2>&1 474RC=$? 475 476if test $RC != 0 ; then 477 echo "ldapsearch failed at slave ($RC)!" 478 test $KILLSERVERS != no && kill -HUP $KILLPIDS 479 exit $RC 480fi 481 482#echo "Filtering master results..." 483$LDIFFILTER < "${MASTEROUT}.3" > $MASTERFLT 484#echo "Filtering slave results..." 485$LDIFFILTER < "${SLAVEOUT}.3" > $SLAVEFLT 486 487echo "$CHECK < Comparing retrieved entries from master and P1 slave..." 488$CMP $MASTERFLT $SLAVEFLT > $CMPOUT 489 490if test $? != 0 ; then 491 echo "test failed - master and slave databases differ" 492 test $KILLSERVERS != no && kill -HUP $KILLPIDS 493 exit 1 494fi 495 496#echo "Using ldapsearch to read all the entries from the R1 slave..." 497$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \ 498 '(objectClass=*)' > "${SLAVEOUT}.3" 2>&1 499RC=$? 500 501if test $RC != 0 ; then 502 echo "ldapsearch failed at slave ($RC)!" 503 test $KILLSERVERS != no && kill -HUP $KILLPIDS 504 exit $RC 505fi 506 507#echo "Filtering slave results..." 508$LDIFFILTER < "${SLAVEOUT}.3" > $SLAVEFLT 509 510echo "$CHECK < Comparing retrieved entries from master and R1 slave..." 511$CMP $MASTERFLT $SLAVEFLT > $CMPOUT 512 513if test $? != 0 ; then 514 echo "test failed - master and slave databases differ" 515 test $KILLSERVERS != no && kill -HUP $KILLPIDS 516 exit 1 517fi 518 519CHECK=`expr $CHECK + 1` 520echo "$CHECK > Try updating the P1 slave slapd..." 521$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \ 522 $TESTOUT 2>&1 << EOMODS 523dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com 524changetype: modify 525add: description 526description: This write must fail because directed to a shadow context, 527description: unless the chain overlay is configured appropriately ;) 528 529EOMODS 530 531RC=$? 532if test $RC != 0 ; then 533 echo "ldapmodify failed ($RC)!" 534 test $KILLSERVERS != no && kill -HUP $KILLPIDS 535 exit $RC 536fi 537 538echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 539sleep $SLEEP1 540 541#echo "Using ldapsearch to read all the entries from the master..." 542$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 543 '(objectClass=*)' > "${MASTEROUT}.4" 2>&1 544RC=$? 545 546if test $RC != 0 ; then 547 echo "ldapsearch failed at master ($RC)!" 548 test $KILLSERVERS != no && kill -HUP $KILLPIDS 549 exit $RC 550fi 551 552#echo "Using ldapsearch to read all the entries from the P1 slave..." 553$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \ 554'(objectClass=*)' > "${SLAVEOUT}.4" 2>&1 555RC=$? 556 557if test $RC != 0 ; then 558 echo "ldapsearch failed at slave ($RC)!" 559 test $KILLSERVERS != no && kill -HUP $KILLPIDS 560 exit $RC 561fi 562 563#echo "Filtering master results..." 564$LDIFFILTER < "${MASTEROUT}.4" > $MASTERFLT 565#echo "Filtering slave results..." 566$LDIFFILTER < "${SLAVEOUT}.4" > $SLAVEFLT 567 568echo "$CHECK < Comparing retrieved entries from master and P1 slave..." 569$CMP $MASTERFLT $SLAVEFLT > $CMPOUT 570 571if test $? != 0 ; then 572 echo "test failed - master and P1 slave databases differ" 573 test $KILLSERVERS != no && kill -HUP $KILLPIDS 574 exit 1 575fi 576 577#echo "Using ldapsearch to read all the entries from the R1 slave..." 578$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \ 579'(objectClass=*)' > "${SLAVEOUT}.4" 2>&1 580RC=$? 581 582if test $RC != 0 ; then 583 echo "ldapsearch failed at slave ($RC)!" 584 test $KILLSERVERS != no && kill -HUP $KILLPIDS 585 exit $RC 586fi 587 588#echo "Filtering slave results..." 589$LDIFFILTER < "${SLAVEOUT}.4" > $SLAVEFLT 590 591echo "$CHECK < Comparing retrieved entries from master and R1 slave..." 592$CMP $MASTERFLT $SLAVEFLT > $CMPOUT 593 594if test $? != 0 ; then 595 echo "test failed - master and R1 slave databases differ" 596 test $KILLSERVERS != no && kill -HUP $KILLPIDS 597 exit 1 598fi 599 600test $KILLSERVERS != no && kill -HUP $KILLPIDS 601 602echo ">>>>> Test succeeded" 603 604test $KILLSERVERS != no && wait 605 606exit 0 607