3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2007 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"
33 mkdir -p $TESTDIR $PRODIR $CONDIR $DBPRO $DBCON $CFPRO $CFCON
36 # Test replication of dynamic config:
39 # - configure over ldap
40 # - populate over ldap
41 # - configure syncrepl over ldap
42 # - retrieve database over ldap and compare against expected results
45 echo "Initializing server configurations..."
46 $SLAPADD -F $CFPRO -n 0 -l $DYNAMICCONF
47 $SLAPADD -F $CFCON -n 0 -l $DYNAMICCONF
49 echo "Starting producer slapd on TCP/IP port $PORT1..."
51 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING > ../$LOG1 2>&1 &
53 if test $WAIT != 0 ; then
62 echo "Using ldapsearch to check that producer slapd is running..."
63 for i in 0 1 2 3 4 5; do
64 $LDAPSEARCH -s base -b "" -H $URI1 \
65 'objectclass=*' > /dev/null 2>&1
67 if test $RC = 0 ; then
70 echo "Waiting 5 seconds for slapd to start..."
74 if test $RC != 0 ; then
75 echo "ldapsearch failed ($RC)!"
76 test $KILLSERVERS != no && kill -HUP $KILLPIDS
80 echo "Inserting syncprov overlay on producer..."
81 if [ "$SYNCPROV" = syncprovmod ]; then
82 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
83 dn: cn=module,cn=config
84 objectClass: olcModuleList
86 olcModulePath: ../../../servers/slapd/overlays
87 olcModuleLoad: syncprov.la
90 if test $RC != 0 ; then
91 echo "ldapadd failed for moduleLoad ($RC)!"
92 test $KILLSERVERS != no && kill -HUP $KILLPIDS
97 # Note that we configure a timeout here; it's possible for both
98 # servers to attempt to bind to each other while a modify to
99 # cn=config is in progress. When the modify pauses the thread pool
100 # neither server will progress. The timeout will drop the syncrepl
101 # attempt and allow the modifies to complete.
103 # Setting the ServerIDs after the fact is bogus; the entries that
104 # were created before this point all have SID 0 in their CSNs. Still
105 # that should be harmless.
107 CONFIGPW=`cat $CONFIGPWF`
108 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
115 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
117 objectClass: olcOverlayConfig
118 objectClass: olcSyncProvConfig
121 dn: olcDatabase={0}config,cn=config
124 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
125 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
126 retry="5 5 300 5" timeout=1
127 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
128 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
129 retry="5 5 300 5" timeout=1
135 if test $RC != 0 ; then
136 echo "ldapmodify failed for syncrepl config ($RC)!"
137 test $KILLSERVERS != no && kill -HUP $KILLPIDS
141 echo "Starting consumer slapd on TCP/IP port $PORT2..."
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="5 5 300 5" timeout=1
180 olcSyncRepl: rid=002 provider=$URI2 binddn="cn=config" bindmethod=simple
181 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
182 retry="5 5 300 5" timeout=1
188 echo "Adding schema and databases on producer..."
189 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
190 include: file:$SCHEMADIR/core.ldif
192 include: file:$SCHEMADIR/cosine.ldif
194 include: file:$SCHEMADIR/inetorgperson.ldif
196 include: file:$SCHEMADIR/openldap.ldif
198 include: file:$SCHEMADIR/nis.ldif
201 if test $RC != 0 ; then
202 echo "ldapadd failed for schema config ($RC)!"
203 test $KILLSERVERS != no && kill -HUP $KILLPIDS
207 if [ "$BACKENDTYPE" = mod ]; then
208 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
209 dn: cn=module,cn=config
210 objectClass: olcModuleList
212 olcModulePath: ../../../servers/slapd/back-$BACKEND
213 olcModuleLoad: back_$BACKEND.la
216 if test $RC != 0 ; then
217 echo "ldapadd failed for backend config ($RC)!"
218 test $KILLSERVERS != no && kill -HUP $KILLPIDS
223 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
224 dn: olcDatabase={1}$BACKEND,cn=config
225 objectClass: olcDatabaseConfig
226 objectClass: olc${BACKEND}Config
227 olcDatabase: {1}$BACKEND
230 olcRootDN: $MANAGERDN
232 olcSyncRepl: rid=003 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
233 credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
234 interval=00:00:00:10 retry="5 5 300 5"
235 olcSyncRepl: rid=004 provider=$URI2 binddn="$MANAGERDN" bindmethod=simple
236 credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
237 interval=00:00:00:10 retry="5 5 300 5"
240 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
242 objectClass: olcOverlayConfig
243 objectClass: olcSyncProvConfig
247 if test $RC != 0 ; then
248 echo "ldapadd failed for database config ($RC)!"
249 test $KILLSERVERS != no && kill -HUP $KILLPIDS
253 echo "Using ldapadd to populate producer..."
254 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
257 if test $RC != 0 ; then
258 echo "ldapadd failed for database config ($RC)!"
259 test $KILLSERVERS != no && kill -HUP $KILLPIDS
264 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
267 echo "Using ldapsearch to check that syncrepl received database changes..."
269 for i in 0 1 2 3 4 5; do
270 RESULT=`$LDAPSEARCH -H $URI2 \
271 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
272 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
273 if test "x$RESULT" = "xOK" ; then
277 echo "Waiting 5 seconds for syncrepl to receive changes..."
281 if test $RC != 0 ; then
282 echo "ldapsearch failed ($RC)!"
283 test $KILLSERVERS != no && kill -HUP $KILLPIDS
287 echo "Using ldapsearch to read config from the producer..."
288 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \
289 'objectclass=*' > $MASTEROUT 2>&1
292 if test $RC != 0 ; then
293 echo "ldapsearch failed at producer ($RC)!"
294 test $KILLSERVERS != no && kill -HUP $KILLPIDS
298 echo "Using ldapsearch to read config from the consumer..."
299 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
300 'objectclass=*' > $SLAVEOUT 2>&1
303 if test $RC != 0 ; then
304 echo "ldapsearch failed at consumer ($RC)!"
305 test $KILLSERVERS != no && kill -HUP $KILLPIDS
309 echo "Filtering producer results..."
310 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
311 echo "Filtering consumer results..."
312 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
314 echo "Comparing retrieved configs from producer and consumer..."
315 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
317 if test $? != 0 ; then
318 echo "test failed - producer and consumer configs differ"
319 test $KILLSERVERS != no && kill -HUP $KILLPIDS
323 echo "Using ldapsearch to read all the entries from the producer..."
324 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
325 'objectclass=*' > $MASTEROUT 2>&1
328 if test $RC != 0 ; then
329 echo "ldapsearch failed at producer ($RC)!"
330 test $KILLSERVERS != no && kill -HUP $KILLPIDS
334 echo "Using ldapsearch to read all the entries from the consumer..."
335 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
336 'objectclass=*' > $SLAVEOUT 2>&1
339 if test $RC != 0 ; then
340 echo "ldapsearch failed at consumer ($RC)!"
341 test $KILLSERVERS != no && kill -HUP $KILLPIDS
345 test $KILLSERVERS != no && kill -HUP $KILLPIDS
347 echo "Filtering producer results..."
348 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
349 echo "Filtering consumer results..."
350 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
352 echo "Comparing retrieved entries from producer and consumer..."
353 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
355 if test $? != 0 ; then
356 echo "test failed - producer and consumer databases differ"
360 test $KILLSERVERS != no && wait
362 echo "Restarting servers..."
363 echo "Starting producer slapd on TCP/IP port $PORT1..."
365 echo "======================= RESTART =======================" >> ../$LOG1
366 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING >> ../$LOG1 2>&1 &
368 if test $WAIT != 0 ; then
374 echo "Using ldapsearch to check that producer slapd is running..."
375 for i in 0 1 2 3 4 5; do
376 $LDAPSEARCH -s base -b "" -H $URI1 \
377 'objectclass=*' > /dev/null 2>&1
379 if test $RC = 0 ; then
382 echo "Waiting 5 seconds for slapd to start..."
386 if test $RC != 0 ; then
387 echo "ldapsearch failed ($RC)!"
388 test $KILLSERVERS != no && kill -HUP $KILLPIDS
392 echo "Starting consumer slapd on TCP/IP port $PORT2..."
394 echo "======================= RESTART =======================" >> ../$LOG2
395 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING >> ../$LOG2 2>&1 &
397 if test $WAIT != 0 ; then
398 echo SLAVEPID $SLAVEPID
401 KILLPIDS="$KILLPIDS $SLAVEPID"
406 echo "Using ldapsearch to check that consumer slapd is running..."
407 for i in 0 1 2 3 4 5; do
408 $LDAPSEARCH -s base -b "" -H $URI2 \
409 'objectclass=*' > /dev/null 2>&1
411 if test $RC = 0 ; then
414 echo "Waiting 5 seconds for slapd to start..."
418 if test $RC != 0 ; then
419 echo "ldapsearch failed ($RC)!"
420 test $KILLSERVERS != no && kill -HUP $KILLPIDS
424 # Insert modifications and more tests here.
426 echo "Waiting $SLEEP seconds for servers to resync..."
429 test $KILLSERVERS != no && kill -HUP $KILLPIDS
431 echo ">>>>> Test succeeded"
433 test $KILLSERVERS != no && wait