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