3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2008 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:10"
43 SYNCTYPE="type=refreshAndPersist"
46 echo "unknown sync mode $SYNCMODE"
53 # Test replication of dynamic config:
56 # - configure over ldap
57 # - populate over ldap
58 # - configure syncrepl over ldap
59 # - retrieve database over ldap and compare against expected results
62 echo "Starting producer slapd on TCP/IP port $PORT1..."
63 . $CONFFILTER $BACKEND $MONITORDB < $DYNAMICCONF > $CONFLDIF
64 $SLAPADD -F $CFPRO -n 0 -l $CONFLDIF
66 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
68 if test $WAIT != 0 ; then
77 echo "Using ldapsearch to check that producer slapd is running..."
78 for i in 0 1 2 3 4 5; do
79 $LDAPSEARCH -s base -b "" -H $URI1 \
80 'objectclass=*' > /dev/null 2>&1
82 if test $RC = 0 ; then
85 echo "Waiting 5 seconds for slapd to start..."
89 if test $RC != 0 ; then
90 echo "ldapsearch failed ($RC)!"
91 test $KILLSERVERS != no && kill -HUP $KILLPIDS
95 echo "Inserting syncprov overlay on producer..."
96 if [ "$SYNCPROV" = syncprovmod ]; then
97 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
98 dn: cn=module,cn=config
99 objectClass: olcModuleList
101 olcModulePath: ../../../servers/slapd/overlays
102 olcModuleLoad: syncprov.la
105 if test $RC != 0 ; then
106 echo "ldapadd failed for moduleLoad ($RC)!"
107 test $KILLSERVERS != no && kill -HUP $KILLPIDS
111 read CONFIGPW < $CONFIGPWF
112 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
113 dn: olcDatabase={0}config,cn=config
116 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
117 credentials=$CONFIGPW searchbase="cn=config" $SYNCTYPE
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" $SYNCTYPE
180 echo "Waiting $SLEEP 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 5 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 producer..."
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 if [ "$BACKENDTYPE" = mod ]; then
223 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
224 dn: cn=module,cn=config
225 objectClass: olcModuleList
227 olcModulePath: ../../../servers/slapd/back-$BACKEND
228 olcModuleLoad: back_$BACKEND.la
231 if test $RC != 0 ; then
232 echo "ldapadd failed for backend config ($RC)!"
233 test $KILLSERVERS != no && kill -HUP $KILLPIDS
238 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
239 dn: olcDatabase={1}$BACKEND,cn=config
240 objectClass: olcDatabaseConfig
241 objectClass: olc${BACKEND}Config
242 olcDatabase: {1}$BACKEND
245 olcRootDN: $MANAGERDN
247 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
248 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
251 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
253 objectClass: olcOverlayConfig
254 objectClass: olcSyncProvConfig
258 if test $RC != 0 ; then
259 echo "ldapadd failed for database config ($RC)!"
260 test $KILLSERVERS != no && kill -HUP $KILLPIDS
264 echo "Using ldapadd to populate producer..."
265 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
268 if test $RC != 0 ; then
269 echo "ldapadd failed for database config ($RC)!"
270 test $KILLSERVERS != no && kill -HUP $KILLPIDS
275 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
278 echo "Using ldapsearch to check that syncrepl received database changes..."
280 for i in 0 1 2 3 4 5; do
281 RESULT=`$LDAPSEARCH -H $URI2 \
282 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
283 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
284 if test "x$RESULT" = "xOK" ; then
288 echo "Waiting 5 seconds for syncrepl to receive changes..."
292 if test $RC != 0 ; then
293 echo "ldapsearch failed ($RC)!"
294 test $KILLSERVERS != no && kill -HUP $KILLPIDS
298 echo "Using ldapsearch to read config from the producer..."
299 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \
300 'objectclass=*' > $MASTEROUT 2>&1
303 if test $RC != 0 ; then
304 echo "ldapsearch failed at producer ($RC)!"
305 test $KILLSERVERS != no && kill -HUP $KILLPIDS
309 echo "Using ldapsearch to read config from the consumer..."
310 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
311 'objectclass=*' > $SLAVEOUT 2>&1
314 if test $RC != 0 ; then
315 echo "ldapsearch failed at consumer ($RC)!"
316 test $KILLSERVERS != no && kill -HUP $KILLPIDS
320 echo "Filtering producer results..."
321 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
322 echo "Filtering consumer results..."
323 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
325 echo "Comparing retrieved configs from producer and consumer..."
326 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
328 if test $? != 0 ; then
329 echo "test failed - producer and consumer configs differ"
330 test $KILLSERVERS != no && kill -HUP $KILLPIDS
334 echo "Using ldapsearch to read all the entries from the producer..."
335 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
336 'objectclass=*' > $MASTEROUT 2>&1
339 if test $RC != 0 ; then
340 echo "ldapsearch failed at producer ($RC)!"
341 test $KILLSERVERS != no && kill -HUP $KILLPIDS
345 echo "Using ldapsearch to read all the entries from the consumer..."
346 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
347 'objectclass=*' > $SLAVEOUT 2>&1
350 if test $RC != 0 ; then
351 echo "ldapsearch failed at consumer ($RC)!"
352 test $KILLSERVERS != no && kill -HUP $KILLPIDS
356 test $KILLSERVERS != no && kill -HUP $KILLPIDS
358 echo "Filtering producer results..."
359 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
360 echo "Filtering consumer results..."
361 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
363 echo "Comparing retrieved entries from producer and consumer..."
364 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
366 if test $? != 0 ; then
367 echo "test failed - producer and consumer databases differ"
371 echo ">>>>> Test succeeded"
373 test $KILLSERVERS != no && wait