3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2009 The OpenLDAP Foundation.
6 ## All rights reserved.
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
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>.
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
19 if test $SYNCPROV = syncprovno; then
20 echo "Syncrepl provider overlay not available, test skipped"
24 if test $BACKEND = null; then
25 echo "$BACKEND backend does not support cn=config, test skipped"
36 mkdir -p $TESTDIR $PRODIR $CONDIR $DBPRO $DBCON $CFPRO $CFCON
38 $SLAPPASSWD -g -n >$CONFIGPWF
40 if test x"$SYNCMODE" = x ; then
45 SYNCTYPE="type=refreshOnly interval=00:00:00:03"
48 SYNCTYPE="type=refreshAndPersist"
51 echo "unknown sync mode $SYNCMODE"
57 # Test replication of dynamic config:
60 # - configure over ldap
61 # - populate over ldap
62 # - configure syncrepl over ldap
63 # - retrieve database over ldap and compare against expected results
66 echo "Starting producer slapd on TCP/IP port $PORT1..."
67 . $CONFFILTER $BACKEND $MONITORDB < $DYNAMICCONF > $CONFLDIF
68 $SLAPADD -F $CFPRO -n 0 -l $CONFLDIF
70 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
72 if test $WAIT != 0 ; then
81 echo "Using ldapsearch to check that producer slapd is running..."
82 for i in 0 1 2 3 4 5; do
83 $LDAPSEARCH -s base -b "" -H $URI1 \
84 'objectclass=*' > /dev/null 2>&1
86 if test $RC = 0 ; then
89 echo "Waiting 5 seconds for slapd to start..."
93 if test $RC != 0 ; then
94 echo "ldapsearch failed ($RC)!"
95 test $KILLSERVERS != no && kill -HUP $KILLPIDS
99 echo "Inserting syncprov overlay on producer..."
100 if [ "$SYNCPROV" = syncprovmod ]; then
101 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
102 dn: cn=module,cn=config
103 objectClass: olcModuleList
105 olcModulePath: ../../../servers/slapd/overlays
106 olcModuleLoad: syncprov.la
109 if test $RC != 0 ; then
110 echo "ldapadd failed for moduleLoad ($RC)!"
111 test $KILLSERVERS != no && kill -HUP $KILLPIDS
115 read CONFIGPW < $CONFIGPWF
116 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
117 dn: olcDatabase={0}config,cn=config
120 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
121 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
122 retry="3 5 300 5" timeout=3
127 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
129 objectClass: olcOverlayConfig
130 objectClass: olcSyncProvConfig
134 if test $RC != 0 ; then
135 echo "ldapmodify failed for syncrepl config ($RC)!"
136 test $KILLSERVERS != no && kill -HUP $KILLPIDS
140 echo "Starting consumer slapd on TCP/IP port $PORT2..."
141 $SLAPADD -F $CFCON -n 0 -l $CONFLDIF
143 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
145 if test $WAIT != 0 ; then
146 echo SLAVEPID $SLAVEPID
149 KILLPIDS="$KILLPIDS $SLAVEPID"
154 echo "Using ldapsearch to check that consumer slapd is running..."
155 for i in 0 1 2 3 4 5; do
156 $LDAPSEARCH -s base -b "" -H $URI2 \
157 'objectclass=*' > /dev/null 2>&1
159 if test $RC = 0 ; then
162 echo "Waiting 5 seconds for slapd to start..."
166 if test $RC != 0 ; then
167 echo "ldapsearch failed ($RC)!"
168 test $KILLSERVERS != no && kill -HUP $KILLPIDS
172 echo "Configuring syncrepl on consumer..."
173 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
174 dn: olcDatabase={0}config,cn=config
177 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
178 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
179 retry="3 5 300 5" timeout=3
185 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
188 echo "Using ldapsearch to check that syncrepl received config changes..."
190 for i in 0 1 2 3 4 5; do
191 RESULT=`$LDAPSEARCH -H $URI2 -D cn=config -y $CONFIGPWF \
192 -s base -b "olcDatabase={0}config,cn=config" \
193 '(olcUpdateRef=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
194 if test "x$RESULT" = "xOK" ; then
198 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
202 if test $RC != 0 ; then
203 echo "ldapsearch failed ($RC)!"
204 test $KILLSERVERS != no && kill -HUP $KILLPIDS
208 echo "Adding schema and databases on producer..."
209 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
210 include: file://$ABS_SCHEMADIR/core.ldif
212 include: file://$ABS_SCHEMADIR/cosine.ldif
214 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
216 include: file://$ABS_SCHEMADIR/openldap.ldif
218 include: file://$ABS_SCHEMADIR/nis.ldif
221 if test $RC != 0 ; then
222 echo "ldapadd failed for schema config ($RC)!"
223 test $KILLSERVERS != no && kill -HUP $KILLPIDS
227 if [ "$BACKENDTYPE" = mod ]; then
228 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
229 dn: cn=module,cn=config
230 objectClass: olcModuleList
232 olcModulePath: ../../../servers/slapd/back-$BACKEND
233 olcModuleLoad: back_$BACKEND.la
236 if test $RC != 0 ; then
237 echo "ldapadd failed for backend config ($RC)!"
238 test $KILLSERVERS != no && kill -HUP $KILLPIDS
243 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
244 dn: olcDatabase={1}$BACKEND,cn=config
245 objectClass: olcDatabaseConfig
246 objectClass: olc${BACKEND}Config
247 olcDatabase: {1}$BACKEND
250 olcRootDN: $MANAGERDN
252 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
253 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
254 retry="3 5 300 5" timeout=3
257 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
259 objectClass: olcOverlayConfig
260 objectClass: olcSyncProvConfig
264 if test $RC != 0 ; then
265 echo "ldapadd failed for database config ($RC)!"
266 test $KILLSERVERS != no && kill -HUP $KILLPIDS
272 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
273 dn: olcDatabase={1}$BACKEND,cn=config
276 olcDbIndex: objectClass,entryUUID,entryCSN eq
277 olcDbIndex: cn,uid pres,eq,sub
280 if test $RC != 0 ; then
281 echo "ldapadd modify for database config ($RC)!"
282 test $KILLSERVERS != no && kill -HUP $KILLPIDS
288 echo "Using ldapadd to populate producer..."
289 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
292 if test $RC != 0 ; then
293 echo "ldapadd failed for database config ($RC)!"
294 test $KILLSERVERS != no && kill -HUP $KILLPIDS
298 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
301 echo "Using ldapsearch to check that syncrepl received database changes..."
303 for i in 0 1 2 3 4 5; do
304 RESULT=`$LDAPSEARCH -H $URI2 \
305 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
306 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
307 if test "x$RESULT" = "xOK" ; then
311 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
315 if test $RC != 0 ; then
316 echo "ldapsearch failed ($RC)!"
317 test $KILLSERVERS != no && kill -HUP $KILLPIDS
321 echo "Replacing olcSyncrepl on producer..."
322 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
323 dn: olcDatabase={0}config,cn=config
326 olcSyncRepl: rid=002 provider=$URI1 binddn="cn=config" bindmethod=simple
327 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
328 retry="3 5 300 5" timeout=3
330 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
333 echo "Using ldapsearch to read config from the producer..."
334 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \
335 'objectclass=*' > $MASTEROUT 2>&1
338 if test $RC != 0 ; then
339 echo "ldapsearch failed at producer ($RC)!"
340 test $KILLSERVERS != no && kill -HUP $KILLPIDS
344 echo "Using ldapsearch to read config from the consumer..."
345 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
346 'objectclass=*' > $SLAVEOUT 2>&1
349 if test $RC != 0 ; then
350 echo "ldapsearch failed at consumer ($RC)!"
351 test $KILLSERVERS != no && kill -HUP $KILLPIDS
355 echo "Filtering producer results..."
356 $LDIFFILTER < $MASTEROUT > $MASTERFLT
357 echo "Filtering consumer results..."
358 $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
360 echo "Comparing retrieved configs from producer and consumer..."
361 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
363 if test $? != 0 ; then
364 echo "test failed - producer and consumer configs differ"
365 test $KILLSERVERS != no && kill -HUP $KILLPIDS
369 echo "Using ldapsearch to read all the entries from the producer..."
370 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
371 'objectclass=*' > $MASTEROUT 2>&1
374 if test $RC != 0 ; then
375 echo "ldapsearch failed at producer ($RC)!"
376 test $KILLSERVERS != no && kill -HUP $KILLPIDS
380 echo "Using ldapsearch to read all the entries from the consumer..."
381 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
382 'objectclass=*' > $SLAVEOUT 2>&1
385 if test $RC != 0 ; then
386 echo "ldapsearch failed at consumer ($RC)!"
387 test $KILLSERVERS != no && kill -HUP $KILLPIDS
391 test $KILLSERVERS != no && kill -HUP $KILLPIDS
393 echo "Filtering producer results..."
394 $LDIFFILTER < $MASTEROUT > $MASTERFLT
395 echo "Filtering consumer results..."
396 $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
398 echo "Comparing retrieved entries from producer and consumer..."
399 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
401 if test $? != 0 ; then
402 echo "test failed - producer and consumer databases differ"
406 echo ">>>>> Test succeeded"
408 test $KILLSERVERS != no && wait