]> git.sur5r.net Git - openldap/blob - tests/scripts/test049-sync-config
ITS#5810: Skip test for back-null
[openldap] / tests / scripts / test049-sync-config
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2009 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
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 if test $SYNCPROV = syncprovno; then 
20         echo "Syncrepl provider overlay not available, test skipped"
21         exit 0
22 fi 
23
24 if test $BACKEND = null; then
25         echo "$BACKEND backend does not support cn=config, test skipped"
26         exit 0
27 fi
28
29 PRODIR=$TESTDIR/pro
30 CONDIR=$TESTDIR/con1
31 DBPRO=$PRODIR/db
32 DBCON=$CONDIR/db
33 CFPRO=$PRODIR/slapd.d
34 CFCON=$CONDIR/slapd.d
35
36 mkdir -p $TESTDIR $PRODIR $CONDIR $DBPRO $DBCON $CFPRO $CFCON
37
38 $SLAPPASSWD -g -n >$CONFIGPWF
39
40 if test x"$SYNCMODE" = x ; then
41         SYNCMODE=rp
42 fi
43 case "$SYNCMODE" in
44         ro)
45                 SYNCTYPE="type=refreshOnly interval=00:00:00:03"
46                 ;;
47         rp)
48                 SYNCTYPE="type=refreshAndPersist"
49                 ;;
50         *)
51                 echo "unknown sync mode $SYNCMODE"
52                 exit 1;
53                 ;;
54 esac
55
56 #
57 # Test replication of dynamic config:
58 # - start producer
59 # - start consumer
60 # - configure over ldap
61 # - populate over ldap
62 # - configure syncrepl over ldap
63 # - retrieve database over ldap and compare against expected results
64 #
65
66 echo "Starting producer slapd on TCP/IP port $PORT1..."
67 . $CONFFILTER $BACKEND $MONITORDB < $DYNAMICCONF > $CONFLDIF
68 $SLAPADD -F $CFPRO -n 0 -l $CONFLDIF
69 cd $PRODIR
70 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
71 PID=$!
72 if test $WAIT != 0 ; then
73     echo PID $PID
74     read foo
75 fi
76 KILLPIDS="$PID"
77 cd $TESTWD
78
79 sleep 1
80
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
85         RC=$?
86         if test $RC = 0 ; then
87                 break
88         fi
89         echo "Waiting 5 seconds for slapd to start..."
90         sleep 5
91 done
92
93 if test $RC != 0 ; then
94         echo "ldapsearch failed ($RC)!"
95         test $KILLSERVERS != no && kill -HUP $KILLPIDS
96         exit $RC
97 fi
98
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
104 cn: module
105 olcModulePath: ../../../servers/slapd/overlays
106 olcModuleLoad: syncprov.la
107 EOF
108         RC=$?
109         if test $RC != 0 ; then
110                 echo "ldapadd failed for moduleLoad ($RC)!"
111                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
112                 exit $RC
113         fi
114 fi
115 read CONFIGPW < $CONFIGPWF
116 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
117 dn: olcDatabase={0}config,cn=config
118 changetype: modify
119 add: olcSyncRepl
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
123 -
124 add: olcUpdateRef
125 olcUpdateRef: $URI1
126
127 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
128 changetype: add
129 objectClass: olcOverlayConfig
130 objectClass: olcSyncProvConfig
131 olcOverlay: syncprov
132 EOF
133 RC=$?
134 if test $RC != 0 ; then
135         echo "ldapmodify failed for syncrepl config ($RC)!"
136         test $KILLSERVERS != no && kill -HUP $KILLPIDS
137         exit $RC
138 fi
139
140 echo "Starting consumer slapd on TCP/IP port $PORT2..."
141 $SLAPADD -F $CFCON -n 0 -l $CONFLDIF
142 cd $CONDIR
143 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
144 SLAVEPID=$!
145 if test $WAIT != 0 ; then
146     echo SLAVEPID $SLAVEPID
147     read foo
148 fi
149 KILLPIDS="$KILLPIDS $SLAVEPID"
150 cd $TESTWD
151
152 sleep 1
153
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
158         RC=$?
159         if test $RC = 0 ; then
160                 break
161         fi
162         echo "Waiting 5 seconds for slapd to start..."
163         sleep 5
164 done
165
166 if test $RC != 0 ; then
167         echo "ldapsearch failed ($RC)!"
168         test $KILLSERVERS != no && kill -HUP $KILLPIDS
169         exit $RC
170 fi
171
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
175 changetype: modify
176 add: olcSyncRepl
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
180 -
181 add: olcUpdateRef
182 olcUpdateRef: $URI1
183 EOF
184
185 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
186 sleep $SLEEP1
187
188 echo "Using ldapsearch to check that syncrepl received config changes..."
189 RC=32
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
195                 RC=0
196                 break
197         fi
198         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
199         sleep $SLEEP1
200 done
201
202 if test $RC != 0 ; then
203         echo "ldapsearch failed ($RC)!"
204         test $KILLSERVERS != no && kill -HUP $KILLPIDS
205         exit $RC
206 fi
207
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
211
212 include: file://$ABS_SCHEMADIR/cosine.ldif
213
214 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
215
216 include: file://$ABS_SCHEMADIR/openldap.ldif
217
218 include: file://$ABS_SCHEMADIR/nis.ldif
219 EOF
220 RC=$?
221 if test $RC != 0 ; then
222         echo "ldapadd failed for schema config ($RC)!"
223         test $KILLSERVERS != no && kill -HUP $KILLPIDS
224         exit $RC
225 fi
226
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
231 cn: module
232 olcModulePath: ../../../servers/slapd/back-$BACKEND
233 olcModuleLoad: back_$BACKEND.la
234 EOF
235         RC=$?
236         if test $RC != 0 ; then
237                 echo "ldapadd failed for backend config ($RC)!"
238                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
239                 exit $RC
240         fi
241 fi
242
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
248 olcSuffix: $BASEDN
249 olcDbDirectory: ./db
250 olcRootDN: $MANAGERDN
251 olcRootPW: $PASSWD
252 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
253   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
254   retry="3 5 300 5" timeout=3
255 olcUpdateRef: $URI1
256
257 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
258 changetype: add
259 objectClass: olcOverlayConfig
260 objectClass: olcSyncProvConfig
261 olcOverlay: syncprov
262 EOF
263 RC=$?
264 if test $RC != 0 ; then
265         echo "ldapadd failed for database config ($RC)!"
266         test $KILLSERVERS != no && kill -HUP $KILLPIDS
267         exit $RC
268 fi
269
270 case $BACKEND in
271 bdb | hdb)
272         $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
273 dn: olcDatabase={1}$BACKEND,cn=config
274 changetype: modify
275 add: olcDbIndex
276 olcDbIndex: objectClass,entryUUID,entryCSN eq
277 olcDbIndex: cn,uid pres,eq,sub
278 EOF
279         RC=$?
280         if test $RC != 0 ; then
281                 echo "ldapadd modify for database config ($RC)!"
282                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
283                 exit $RC
284         fi
285         ;;
286 esac
287
288 echo "Using ldapadd to populate producer..."
289 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
290         >> $TESTOUT 2>&1
291 RC=$?
292 if test $RC != 0 ; then
293         echo "ldapadd failed for database config ($RC)!"
294         test $KILLSERVERS != no && kill -HUP $KILLPIDS
295         exit $RC
296 fi
297
298 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
299 sleep $SLEEP1
300
301 echo "Using ldapsearch to check that syncrepl received database changes..."
302 RC=32
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
308                 RC=0
309                 break
310         fi
311         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
312         sleep $SLEEP1
313 done
314
315 if test $RC != 0 ; then
316         echo "ldapsearch failed ($RC)!"
317         test $KILLSERVERS != no && kill -HUP $KILLPIDS
318         exit $RC
319 fi
320
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
324 changetype: modify
325 replace: olcSyncRepl
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
329 EOF
330 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
331 sleep $SLEEP1
332
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
336 RC=$?
337
338 if test $RC != 0 ; then
339         echo "ldapsearch failed at producer ($RC)!"
340         test $KILLSERVERS != no && kill -HUP $KILLPIDS
341         exit $RC
342 fi
343
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
347 RC=$?
348
349 if test $RC != 0 ; then
350         echo "ldapsearch failed at consumer ($RC)!"
351         test $KILLSERVERS != no && kill -HUP $KILLPIDS
352         exit $RC
353 fi
354
355 echo "Filtering producer results..."
356 $LDIFFILTER < $MASTEROUT > $MASTERFLT
357 echo "Filtering consumer results..."
358 $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
359
360 echo "Comparing retrieved configs from producer and consumer..."
361 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
362
363 if test $? != 0 ; then
364         echo "test failed - producer and consumer configs differ"
365         test $KILLSERVERS != no && kill -HUP $KILLPIDS
366         exit 1
367 fi
368
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
372 RC=$?
373
374 if test $RC != 0 ; then
375         echo "ldapsearch failed at producer ($RC)!"
376         test $KILLSERVERS != no && kill -HUP $KILLPIDS
377         exit $RC
378 fi
379
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
383 RC=$?
384
385 if test $RC != 0 ; then
386         echo "ldapsearch failed at consumer ($RC)!"
387         test $KILLSERVERS != no && kill -HUP $KILLPIDS
388         exit $RC
389 fi
390
391 test $KILLSERVERS != no && kill -HUP $KILLPIDS
392
393 echo "Filtering producer results..."
394 $LDIFFILTER < $MASTEROUT > $MASTERFLT
395 echo "Filtering consumer results..."
396 $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
397
398 echo "Comparing retrieved entries from producer and consumer..."
399 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
400
401 if test $? != 0 ; then
402         echo "test failed - producer and consumer databases differ"
403         exit 1
404 fi
405
406 echo ">>>>> Test succeeded"
407
408 test $KILLSERVERS != no && wait
409
410 exit 0