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