3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2012 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"
31 mkdir -p $TESTDIR $PRODIR $CONDIR $DBPRO $DBCON $CFPRO $CFCON
33 $SLAPPASSWD -g -n >$CONFIGPWF
35 if test x"$SYNCMODE" = x ; then
40 SYNCTYPE="type=refreshOnly interval=00:00:00:03"
43 SYNCTYPE="type=refreshAndPersist"
46 echo "unknown sync mode $SYNCMODE"
52 # Test replication of dynamic config:
55 # - configure over ldap
56 # - populate over ldap
57 # - configure syncrepl over ldap
58 # - retrieve database over ldap and compare against expected results
61 echo "Starting provider slapd on TCP/IP port $PORT1..."
62 . $CONFFILTER $BACKEND $MONITORDB < $DYNAMICCONF > $CONFLDIF
63 $SLAPADD -F $CFPRO -n 0 -l $CONFLDIF
65 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
67 if test $WAIT != 0 ; then
76 echo "Using ldapsearch to check that provider slapd is running..."
77 for i in 0 1 2 3 4 5; do
78 $LDAPSEARCH -s base -b "" -H $URI1 \
79 'objectclass=*' > /dev/null 2>&1
81 if test $RC = 0 ; then
84 echo "Waiting 5 seconds for slapd to start..."
88 if test $RC != 0 ; then
89 echo "ldapsearch failed ($RC)!"
90 test $KILLSERVERS != no && kill -HUP $KILLPIDS
94 echo "Inserting syncprov overlay on provider..."
95 if [ "$SYNCPROV" = syncprovmod ]; then
96 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
97 dn: cn=module,cn=config
98 objectClass: olcModuleList
100 olcModulePath: $TESTWD/../servers/slapd/overlays
101 olcModuleLoad: syncprov.la
104 if test $RC != 0 ; then
105 echo "ldapadd failed for moduleLoad ($RC)!"
106 test $KILLSERVERS != no && kill -HUP $KILLPIDS
110 read CONFIGPW < $CONFIGPWF
111 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
112 dn: olcDatabase={0}config,cn=config
115 olcSyncRepl: 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
122 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
124 objectClass: olcOverlayConfig
125 objectClass: olcSyncProvConfig
129 if test $RC != 0 ; then
130 echo "ldapmodify failed for syncrepl config ($RC)!"
131 test $KILLSERVERS != no && kill -HUP $KILLPIDS
135 echo "Starting consumer slapd on TCP/IP port $PORT2..."
136 $SLAPADD -F $CFCON -n 0 -l $CONFLDIF
138 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
140 if test $WAIT != 0 ; then
141 echo SLAVEPID $SLAVEPID
144 KILLPIDS="$KILLPIDS $SLAVEPID"
149 echo "Using ldapsearch to check that consumer slapd is running..."
150 for i in 0 1 2 3 4 5; do
151 $LDAPSEARCH -s base -b "" -H $URI2 \
152 'objectclass=*' > /dev/null 2>&1
154 if test $RC = 0 ; then
157 echo "Waiting 5 seconds for slapd to start..."
161 if test $RC != 0 ; then
162 echo "ldapsearch failed ($RC)!"
163 test $KILLSERVERS != no && kill -HUP $KILLPIDS
167 echo "Configuring syncrepl on consumer..."
168 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
169 dn: olcDatabase={0}config,cn=config
172 olcSyncRepl: 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
180 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
183 echo "Using ldapsearch to check that syncrepl received config changes..."
185 for 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
193 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
197 if test $RC != 0 ; then
198 echo "ldapsearch failed ($RC)!"
199 test $KILLSERVERS != no && kill -HUP $KILLPIDS
203 echo "Adding schema and databases on provider..."
204 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
205 include: file://$ABS_SCHEMADIR/core.ldif
207 include: file://$ABS_SCHEMADIR/cosine.ldif
209 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
211 include: file://$ABS_SCHEMADIR/openldap.ldif
213 include: file://$ABS_SCHEMADIR/nis.ldif
216 if test $RC != 0 ; then
217 echo "ldapadd failed for schema config ($RC)!"
218 test $KILLSERVERS != no && kill -HUP $KILLPIDS
222 nullExclude="" nullOK=""
223 test $BACKEND = null && nullExclude="# " nullOK="OK"
225 if [ "$BACKENDTYPE" = mod ]; then
226 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
227 dn: cn=module,cn=config
228 objectClass: olcModuleList
230 olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
231 olcModuleLoad: back_$BACKEND.la
234 if test $RC != 0 ; then
235 echo "ldapadd failed for backend config ($RC)!"
236 test $KILLSERVERS != no && kill -HUP $KILLPIDS
241 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
242 dn: olcDatabase={1}$BACKEND,cn=config
243 objectClass: olcDatabaseConfig
244 ${nullExclude}objectClass: olc${BACKEND}Config
245 olcDatabase: {1}$BACKEND
247 ${nullExclude}olcDbDirectory: ./db
248 olcRootDN: $MANAGERDN
250 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
251 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
252 retry="3 5 300 5" timeout=3
255 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
257 objectClass: olcOverlayConfig
258 objectClass: olcSyncProvConfig
262 if test $RC != 0 ; then
263 echo "ldapadd failed for database config ($RC)!"
264 test $KILLSERVERS != no && kill -HUP $KILLPIDS
268 if test $INDEXDB = indexdb ; then
269 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
270 dn: olcDatabase={1}$BACKEND,cn=config
273 olcDbIndex: objectClass,entryUUID,entryCSN eq
274 olcDbIndex: cn,uid pres,eq,sub
277 if test $RC != 0 ; then
278 echo "ldapadd modify for database config ($RC)!"
279 test $KILLSERVERS != no && kill -HUP $KILLPIDS
284 echo "Using ldapadd to populate provider..."
285 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
288 if test $RC != 0 ; then
289 echo "ldapadd failed for database config ($RC)!"
290 test $KILLSERVERS != no && kill -HUP $KILLPIDS
294 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
297 echo "Using ldapsearch to check that syncrepl received database changes..."
299 for i in 0 1 2 3 4 5; do
300 RESULT=`$LDAPSEARCH -H $URI2 \
301 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
302 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
303 if test "x$RESULT$nullOK" = "xOK" ; then
307 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
311 if test $RC != 0 ; then
312 echo "ldapsearch failed ($RC)!"
313 test $KILLSERVERS != no && kill -HUP $KILLPIDS
317 echo "Replacing olcSyncrepl on provider..."
318 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
319 dn: olcDatabase={0}config,cn=config
322 olcSyncRepl: rid=002 provider=$URI1 binddn="cn=config" bindmethod=simple
323 credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
324 retry="3 5 300 5" timeout=3
326 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
329 echo "Using ldapsearch to read config from the provider..."
330 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \
331 'objectclass=*' > $MASTEROUT 2>&1
334 if test $RC != 0 ; then
335 echo "ldapsearch failed at provider ($RC)!"
336 test $KILLSERVERS != no && kill -HUP $KILLPIDS
340 echo "Using ldapsearch to read config from the consumer..."
341 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
342 'objectclass=*' > $SLAVEOUT 2>&1
345 if test $RC != 0 ; then
346 echo "ldapsearch failed at consumer ($RC)!"
347 test $KILLSERVERS != no && kill -HUP $KILLPIDS
351 echo "Filtering provider results..."
352 $LDIFFILTER < $MASTEROUT > $MASTERFLT
353 echo "Filtering consumer results..."
354 $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
356 echo "Comparing retrieved configs from provider and consumer..."
357 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
359 if test $? != 0 ; then
360 echo "test failed - provider and consumer configs differ"
361 test $KILLSERVERS != no && kill -HUP $KILLPIDS
365 echo "Using ldapsearch to read all the entries from the provider..."
366 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
367 'objectclass=*' > $MASTEROUT 2>&1
370 if test $RC != 0 ; then
371 echo "ldapsearch failed at provider ($RC)!"
372 test $KILLSERVERS != no && kill -HUP $KILLPIDS
376 echo "Using ldapsearch to read all the entries from the consumer..."
377 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
378 'objectclass=*' > $SLAVEOUT 2>&1
381 if test $RC != 0 ; then
382 echo "ldapsearch failed at consumer ($RC)!"
383 test $KILLSERVERS != no && kill -HUP $KILLPIDS
387 test $KILLSERVERS != no && kill -HUP $KILLPIDS
389 echo "Filtering provider results..."
390 $LDIFFILTER < $MASTEROUT > $MASTERFLT
391 echo "Filtering consumer results..."
392 $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
394 echo "Comparing retrieved entries from provider and consumer..."
395 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
397 if test $? != 0 ; then
398 echo "test failed - provider and consumer databases differ"
402 echo ">>>>> Test succeeded"
404 test $KILLSERVERS != no && wait