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