]> git.sur5r.net Git - openldap/blob - tests/scripts/test053-syncprov-glue
s/ldap_sync.h/ldap.h/
[openldap] / tests / scripts / test053-syncprov-glue
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2008 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 # This script tests a bug where syncprov used on a glue database
17 # with a subordinate syncrepl consumer database looses a read-lock
18 # on the glue suffix entry when a modification is received on the
19 # syncrepl consumer.  The bug is only triggered when there is an
20 # active syncrepl consumers of the glue suffix entry.
21
22 echo "running defines.sh"
23 . $SRCDIR/scripts/defines.sh
24
25 if test $SYNCPROV = syncprovno; then 
26         echo "Syncrepl provider overlay not available, test skipped"
27         exit 0
28 fi 
29
30 PRODDIR=$TESTDIR/prod
31 PRO2DIR=$TESTDIR/pro2
32 CONSDIR=$TESTDIR/cons
33 CFPROD=$PRODDIR/slapd.d
34 CFPRO2=$PRO2DIR/slapd.d
35 CFCONS=$CONSDIR/slapd.d
36
37 mkdir -p $TESTDIR
38 mkdir -p $PRODDIR $CFPROD $PRODDIR/db $PRODDIR/ou1
39 mkdir -p $PRO2DIR $CFPRO2 $PRO2DIR/db
40 mkdir -p $CONSDIR $CFCONS $CONSDIR/db 
41
42 cd $TESTDIR
43
44 KILLPIDS=
45
46 $SLAPPASSWD -g -n >$CONFIGPWF
47
48 echo "Initializing producer configurations..."
49 $SLAPADD -F $CFPROD -n 0 <<EOF
50 dn: cn=config
51 objectClass: olcGlobal
52 cn: config
53 olcServerID: 1
54
55 dn: olcDatabase={0}config,cn=config
56 objectClass: olcDatabaseConfig
57 olcDatabase: {0}config
58 olcRootPW:< file://$CONFIGPWF
59
60 EOF
61
62 echo "Initializing producer2 configurations..."
63 $SLAPADD -F $CFPRO2 -n 0 <<EOF
64 dn: cn=config
65 objectClass: olcGlobal
66 cn: config
67
68 dn: olcDatabase={0}config,cn=config
69 objectClass: olcDatabaseConfig
70 olcDatabase: {0}config
71 olcRootPW:< file://$CONFIGPWF
72
73 EOF
74
75 $SLAPADD -F $CFCONS -n 0 <<EOF
76 dn: cn=config
77 objectClass: olcGlobal
78 cn: config
79
80 dn: olcDatabase={0}config,cn=config
81 objectClass: olcDatabaseConfig
82 olcDatabase: {0}config
83 olcRootPW:< file://$CONFIGPWF
84 EOF
85
86 echo "Starting producer slapd on TCP/IP port $PORT1..."
87 cd $PRODDIR
88 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
89 PID=$!
90 if test $WAIT != 0 ; then
91     echo PID $PID
92     read foo
93 fi
94 KILLPIDS="$KILLPIDS $PID"
95 cd $TESTWD
96 sleep 1
97 echo "Using ldapsearch to check that producer slapd is running..."
98 for i in 0 1 2 3 4 5; do
99         $LDAPSEARCH -s base -b "" -H $URI1 \
100                 'objectclass=*' > /dev/null 2>&1
101         RC=$?
102         if test $RC = 0 ; then
103                 break
104         fi
105         echo "Waiting 5 seconds for slapd to start..."
106         sleep 5
107 done
108 if test $RC != 0 ; then
109         echo "ldapsearch failed ($RC)!"
110         test $KILLSERVERS != no && kill -HUP $KILLPIDS
111         exit $RC
112 fi
113
114 echo "Starting producer2 slapd on TCP/IP port $PORT2..."
115 cd $PRO2DIR
116 $SLAPD -F slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
117 PID=$!
118 if test $WAIT != 0 ; then
119     echo PID $PID
120     read foo
121 fi
122 KILLPIDS="$KILLPIDS $PID"
123 cd $TESTWD
124 sleep 1
125 echo "Using ldapsearch to check that producer slapd is running..."
126 for i in 0 1 2 3 4 5; do
127         $LDAPSEARCH -s base -b "" -H $URI2 \
128                 'objectclass=*' > /dev/null 2>&1
129         RC=$?
130         if test $RC = 0 ; then
131                 break
132         fi
133         echo "Waiting 5 seconds for slapd to start..."
134         sleep 5
135 done
136 if test $RC != 0 ; then
137         echo "ldapsearch failed ($RC)!"
138         test $KILLSERVERS != no && kill -HUP $KILLPIDS
139         exit $RC
140 fi
141
142 echo "Starting consumer slapd on TCP/IP port $PORT3..."
143 cd $CONSDIR
144 $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
145 PID=$!
146 if test $WAIT != 0 ; then
147     echo PID $PID
148     read foo
149 fi
150 KILLPIDS="$KILLPIDS $PID"
151 cd $TESTWD
152 sleep 1
153 echo "Using ldapsearch to check that consumer slapd is running..."
154 for i in 0 1 2 3 4 5; do
155         $LDAPSEARCH -s base -b "" -H $URI3 \
156                 'objectclass=*' > /dev/null 2>&1
157         RC=$?
158         if test $RC = 0 ; then
159                 break
160         fi
161         echo "Waiting 5 seconds for slapd to start..."
162         sleep 5
163 done
164 if test $RC != 0 ; then
165         echo "ldapsearch failed ($RC)!"
166         test $KILLSERVERS != no && kill -HUP $KILLPIDS
167         exit $RC
168 fi
169
170 for uri in $URI1 $URI2 $URI3; do
171         echo "Adding schema on $uri..."
172         $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
173 include: file://$ABS_SCHEMADIR/core.ldif
174
175 include: file://$ABS_SCHEMADIR/cosine.ldif
176
177 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
178
179 include: file://$ABS_SCHEMADIR/openldap.ldif
180
181 include: file://$ABS_SCHEMADIR/nis.ldif
182 EOF
183         RC=$?
184         if test $RC != 0 ; then
185                 echo "ldapadd failed for schema config ($RC)!"
186                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
187                 exit $RC
188         fi
189
190         [ "$BACKENDTYPE" = mod ] || continue
191
192         echo "Adding backend module on $uri..."
193         $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
194 dn: cn=module,cn=config
195 objectClass: olcModuleList
196 cn: module
197 olcModulePath: ../../../servers/slapd/back-$BACKEND
198 olcModuleLoad: back_$BACKEND.la
199 EOF
200         RC=$?
201         if test $RC != 0 ; then
202                 echo "ldapadd failed for backend module ($RC)!"
203                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
204                 exit $RC
205         fi
206 done
207
208 echo "Adding databases on producer..."
209 if [ "$SYNCPROV" = syncprovmod ]; then
210         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
211 dn: cn=module,cn=config
212 objectClass: olcModuleList
213 cn: module
214 olcModulePath: ../../../servers/slapd/overlays
215 olcModuleLoad: syncprov.la
216
217 EOF
218         RC=$?
219         if test $RC != 0 ; then
220                 echo "ldapadd failed for moduleLoad ($RC)!"
221                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
222                 exit $RC
223         fi
224 fi
225
226 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
227 dn: olcDatabase={1}$BACKEND,cn=config
228 objectClass: olcDatabaseConfig
229 objectClass: olc${BACKEND}Config
230 olcDatabase: {1}$BACKEND
231 olcDbDirectory: $PRODDIR/db
232 olcSuffix: $BASEDN
233 olcRootDN: $MANAGERDN
234 olcRootPW: $PASSWD
235
236 EOF
237 RC=$?
238 if test $RC != 0 ; then
239         echo "ldapadd failed for producer database config1 ($RC)!"
240         test $KILLSERVERS != no && kill -HUP $KILLPIDS
241         exit $RC
242 fi
243
244 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
245 dn: olcOverlay={0}glue,olcDatabase={1}$BACKEND,cn=config
246 objectClass: olcOverlayConfig
247 olcOverlay: {0}glue
248
249 dn: olcOverlay={1}syncprov,olcDatabase={1}$BACKEND,cn=config
250 objectClass: olcOverlayConfig
251 objectClass: olcSyncProvConfig
252 olcOverlay: {1}syncprov
253
254 dn: olcDatabase={1}$BACKEND,cn=config
255 objectClass: olcDatabaseConfig
256 objectClass: olc${BACKEND}Config
257 olcDatabase: {1}$BACKEND
258 olcDbDirectory: $PRODDIR/ou1
259 olcSubordinate: TRUE
260 olcSuffix: ou=ou1,$BASEDN
261 olcRootDN: $MANAGERDN
262
263 EOF
264 RC=$?
265 if test $RC != 0 ; then
266         echo "ldapadd failed for producer database config ($RC)!"
267         test $KILLSERVERS != no && kill -HUP $KILLPIDS
268         exit $RC
269 fi
270
271 echo "Adding databases on producer2..."
272 if [ "$SYNCPROV" = syncprovmod ]; then
273         $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
274 dn: cn=module,cn=config
275 objectClass: olcModuleList
276 cn: module
277 olcModulePath: ../../../servers/slapd/overlays
278 olcModuleLoad: syncprov.la
279
280 EOF
281         RC=$?
282         if test $RC != 0 ; then
283                 echo "ldapadd failed for moduleLoad ($RC)!"
284                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
285                 exit $RC
286         fi
287 fi
288
289 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
290 dn: olcDatabase={1}$BACKEND,cn=config
291 objectClass: olcDatabaseConfig
292 objectClass: olc${BACKEND}Config
293 olcDatabase: {1}$BACKEND
294 olcDbDirectory: $PRO2DIR/db
295 olcSuffix: $BASEDN
296 olcRootDN: $MANAGERDN
297 olcRootPW: $PASSWD
298
299 dn: olcOverlay={0}syncprov,olcDatabase={1}$BACKEND,cn=config
300 objectClass: olcOverlayConfig
301 objectClass: olcSyncProvConfig
302 olcOverlay: {0}syncprov
303
304 EOF
305 RC=$?
306 if test $RC != 0 ; then
307         echo "ldapadd failed for producer database config ($RC)!"
308         test $KILLSERVERS != no && kill -HUP $KILLPIDS
309         exit $RC
310 fi
311
312 echo "Adding databases on consumer..."
313 $LDAPADD -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
314 dn: olcDatabase={1}$BACKEND,cn=config
315 objectClass: olcDatabaseConfig
316 objectClass: olc${BACKEND}Config
317 olcDatabase: {1}$BACKEND
318 olcDbDirectory: $CONSDIR/db
319 olcSuffix: $BASEDN
320 olcRootDN: $MANAGERDN
321
322 EOF
323 RC=$?
324 if test $RC != 0 ; then
325         echo "ldapadd failed for consumer database config ($RC)!"
326         test $KILLSERVERS != no && kill -HUP $KILLPIDS
327         exit $RC
328 fi
329
330 echo "Populating producer..."
331 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
332 dn: dc=example,dc=com
333 objectClass: top
334 objectClass: organization
335 objectClass: dcObject
336 dc: example
337 o: Example, Inc
338
339 dn: ou=ou1,dc=example,dc=com
340 objectClass: top
341 objectClass: organizationalUnit
342 ou: ou1
343
344 EOF
345 RC=$?
346 if test $RC != 0 ; then
347         echo "ldapadd failed to populate producer entry ($RC)!"
348         test $KILLSERVERS != no && kill -HUP $KILLPIDS
349         exit $RC
350 fi
351
352 echo "Populating producer2..."
353 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
354 dn: dc=example,dc=com
355 objectClass: top
356 objectClass: organization
357 objectClass: dcObject
358 dc: example
359 o: Example, Inc
360
361 dn: ou=ou1,dc=example,dc=com
362 objectClass: top
363 objectClass: organizationalUnit
364 ou: ou1
365
366 EOF
367 RC=$?
368 if test $RC != 0 ; then
369         echo "ldapadd failed to populate producer entry ($RC)!"
370         test $KILLSERVERS != no && kill -HUP $KILLPIDS
371         exit $RC
372 fi
373
374 echo "Adding syncrepl on producer..."
375 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
376 dn: olcDatabase={1}$BACKEND,cn=config
377 changetype: modify
378 add: olcSyncRepl
379 olcSyncRepl: rid=1 provider=$URI2 searchbase="ou=ou1,$BASEDN"
380   binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
381   type=refreshAndPersist retry="5 5 300 5" timeout=1
382
383 EOF
384 RC=$?
385 if test $RC != 0 ; then
386         echo "ldapmodify failed to add syncrepl consumer ($RC)!"
387         test $KILLSERVERS != no && kill -HUP $KILLPIDS
388         exit $RC
389 fi
390
391 echo "Adding syncrepl consumer on consumer..."
392 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
393 dn: olcDatabase={1}$BACKEND,cn=config
394 changetype: modify
395 add: olcSyncRepl
396 olcSyncRepl: rid=1 provider=$URI1 searchbase="$BASEDN"
397   binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
398   type=refreshAndPersist retry="5 5 300 5" timeout=1
399
400 EOF
401 RC=$?
402 if test $RC != 0 ; then
403         echo "ldapmodify failed to add syncrepl consumer ($RC)!"
404         test $KILLSERVERS != no && kill -HUP $KILLPIDS
405         exit $RC
406 fi
407
408 echo "Using ldapsearch to check that consumer received changes..."
409 RC=32
410 for i in 0 1 2 3 4 5; do
411         RESULT=`$LDAPSEARCH -H $URI3 \
412                 -s base -b "ou=ou1,$BASEDN" \
413                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
414         if test "x$RESULT" = "xOK" ; then
415                 RC=0
416                 break
417         fi
418         echo "Waiting 5 seconds for syncrepl to receive changes..."
419         sleep 5
420 done
421 if test $RC != 0 ; then
422         echo "ldapsearch failed ($RC)!"
423         test $KILLSERVERS != no && kill -HUP $KILLPIDS
424         exit $RC
425 fi
426
427 echo "Using ldapmodify to modify producer2..."
428 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
429 dn: ou=ou1,dc=example,dc=com
430 changetype: modify
431 add: description
432 description: Modify1
433
434 EOF
435 RC=$?
436 if test $RC != 0 ; then
437         echo "ldapmodify failed ($RC)!"
438         test $KILLSERVERS != no && kill -HUP $KILLPIDS
439         exit $RC
440 fi
441
442 sleep 1
443
444 echo "Using ldapsearch to check that consumer received changes..."
445 RC=32
446 for i in 0 1 2 3 4 5; do
447         RESULT=`$LDAPSEARCH -H $URI3 \
448                 -s base -b "ou=ou1,$BASEDN" \
449                 '(description=Modify1)' 2>&1 | awk '/^dn:/ {print "OK"}'`
450         if test "x$RESULT" = "xOK" ; then
451                 RC=0
452                 break
453         fi
454         echo "Waiting 5 seconds for syncrepl to receive changes..."
455         sleep 5
456 done
457 if test $RC != 0 ; then
458         echo "ldapsearch failed ($RC)!"
459         test $KILLSERVERS != no && kill -HUP $KILLPIDS
460         exit $RC
461 fi
462
463 type db_stat >/dev/null 2>&1
464 RC=$?
465 if test $RC != 0 ; then
466         echo "Could not find db_stat ($RC)!"
467         lock_bug=1
468 elif db_stat -E -h $PRODDIR/db | egrep -q 'HELD .* len:'; then
469         echo "WARNING: Glue lock bug hit, next modify could deadlock"
470         lock_bug=2
471 else
472         echo "Glue lock bug not found :-)"
473         lock_bug=0
474 fi
475
476 echo "Using ldapmodify to modify glue suffix on producer..."
477 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
478 dn: dc=example,dc=com
479 changetype: modify
480 add: description
481 description: Test1
482
483 EOF
484 RC=$?
485 if test $RC != 0 ; then
486         echo "ldapadd failed to modify suffix ($RC)!"
487         test $KILLSERVERS != no && kill -HUP $KILLPIDS
488         exit $RC
489 fi
490
491 test $KILLSERVERS != no && kill -HUP $KILLPIDS
492 test "$lock_bug" = 2    && exit 2
493
494 echo ">>>>> Test succeeded"
495
496 exit 0