]> git.sur5r.net Git - openldap/blob - tests/scripts/test018-syncreplication-persist
f923341950cb06bec58f572f2be6425c753c4865
[openldap] / tests / scripts / test018-syncreplication-persist
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2010 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 OPATTRS="entryUUID creatorsName createTimestamp modifiersName modifyTimestamp"
20
21 if test $SYNCPROV = syncprovno; then 
22         echo "Syncrepl provider overlay not available, test skipped"
23         exit 0
24 fi 
25
26 mkdir -p $TESTDIR $DBDIR1 $DBDIR4
27
28 #
29 # Test replication:
30 # - start producer
31 # - start consumer
32 # - populate over ldap
33 # - perform some modifies and deleted
34 # - attempt to modify the consumer (referral or chain)
35 # - retrieve database over ldap and compare against expected results
36 #
37
38 echo "Starting producer slapd on TCP/IP port $PORT1..."
39 . $CONFFILTER $BACKEND $MONITORDB < $SRMASTERCONF > $CONF1
40 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
41 PID=$!
42 if test $WAIT != 0 ; then
43     echo PID $PID
44     read foo
45 fi
46 KILLPIDS="$PID"
47
48 sleep 1
49
50 echo "Using ldapsearch to check that producer slapd is running..."
51 for i in 0 1 2 3 4 5; do
52         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
53                 'objectclass=*' > /dev/null 2>&1
54         RC=$?
55         if test $RC = 0 ; then
56                 break
57         fi
58         echo "Waiting 5 seconds for slapd to start..."
59         sleep 5
60 done
61
62 if test $RC != 0 ; then
63         echo "ldapsearch failed ($RC)!"
64         test $KILLSERVERS != no && kill -HUP $KILLPIDS
65         exit $RC
66 fi
67
68 echo "Using ldapadd to create the context prefix entry in the producer..."
69 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
70         $LDIFORDEREDCP > /dev/null 2>&1
71 RC=$?
72 if test $RC != 0 ; then
73         echo "ldapadd failed ($RC)!"
74         test $KILLSERVERS != no && kill -HUP $KILLPIDS
75         exit $RC
76 fi
77
78 echo "Starting consumer slapd on TCP/IP port $PORT4..."
79 . $CONFFILTER $BACKEND $MONITORDB < $P1SRSLAVECONF > $CONF4
80 $SLAPD -f $CONF4 -h $URI4 -d $LVL $TIMING > $LOG4 2>&1 &
81 SLAVEPID=$!
82 if test $WAIT != 0 ; then
83     echo SLAVEPID $SLAVEPID
84     read foo
85 fi
86 KILLPIDS="$KILLPIDS $SLAVEPID"
87
88 sleep 1
89
90 echo "Using ldapsearch to check that consumer slapd is running..."
91 for i in 0 1 2 3 4 5; do
92         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT4 \
93                 'objectclass=*' > /dev/null 2>&1
94         RC=$?
95         if test $RC = 0 ; then
96                 break
97         fi
98         echo "Waiting 5 seconds for slapd to start..."
99         sleep 5
100 done
101
102 if test $RC != 0 ; then
103         echo "ldapsearch failed ($RC)!"
104         test $KILLSERVERS != no && kill -HUP $KILLPIDS
105         exit $RC
106 fi
107
108 echo "Using ldapadd to populate the producer directory..."
109 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
110         $LDIFORDEREDNOCP > /dev/null 2>&1
111 RC=$?
112 if test $RC != 0 ; then
113         echo "ldapadd failed ($RC)!"
114         test $KILLSERVERS != no && kill -HUP $KILLPIDS
115         exit $RC
116 fi
117
118 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
119 sleep $SLEEP1
120
121 echo "Using ldapsearch to read all the entries from the producer..."
122 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
123         '(objectclass=*)' '*' $OPATTRS > $MASTEROUT 2>&1
124 RC=$?
125
126 if test $RC != 0 ; then
127         echo "ldapsearch failed at producer ($RC)!"
128         test $KILLSERVERS != no && kill -HUP $KILLPIDS
129         exit $RC
130 fi
131
132 echo "Using ldapsearch to read all the entries from the consumer..."
133 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT4 \
134         '(objectclass=*)' '*' $OPATTRS > $SLAVEOUT 2>&1
135 RC=$?
136
137 if test $RC != 0 ; then
138         echo "ldapsearch failed at consumer ($RC)!"
139         test $KILLSERVERS != no && kill -HUP $KILLPIDS
140         exit $RC
141 fi
142
143 echo "Filtering producer results..."
144 $LDIFFILTER < $MASTEROUT > $MASTERFLT
145 echo "Filtering consumer results..."
146 $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
147
148 echo "Comparing retrieved entries from producer and consumer..."
149 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
150
151 if test $? != 0 ; then
152         echo "test failed - producer and consumer databases differ"
153         test $KILLSERVERS != no && kill -HUP $KILLPIDS
154         exit 1
155 fi
156
157 echo "Stopping the provider, sleeping 10 seconds and restarting it..."
158 kill -HUP "$PID"
159 wait $PID
160 sleep 10
161 echo "RESTART" >> $LOG1
162 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
163 PID=$!
164 if test $WAIT != 0 ; then
165     echo PID $PID
166     read foo
167 fi
168 KILLPIDS="$PID $SLAVEPID"
169
170 sleep 1
171
172 echo "Using ldapsearch to check that producer slapd is running..."
173 for i in 0 1 2 3 4 5; do
174         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
175                 'objectclass=*' > /dev/null 2>&1
176         RC=$?
177         if test $RC = 0 ; then
178                 break
179         fi
180         echo "Waiting 5 seconds for slapd to start..."
181         sleep 5
182 done
183
184 echo "Waiting $SLEEP1 seconds for consumer to reconnect..."
185 sleep $SLEEP1
186
187 if test $RC != 0 ; then
188         echo "ldapsearch failed ($RC)!"
189         test $KILLSERVERS != no && kill -HUP $KILLPIDS
190         exit $RC
191 fi
192
193 echo "Using ldapmodify to modify producer directory..."
194
195 #
196 # Do some modifications
197 #
198
199 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
200         $TESTOUT 2>&1 << EOMODS
201 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
202 changetype: modify
203 add: drink
204 drink: Orange Juice
205 -
206 delete: sn
207 sn: Jones
208 -
209 add: sn
210 sn: Jones
211
212 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
213 changetype: modify
214 replace: drink
215 drink: Iced Tea
216
217 dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
218 changetype: modify
219 delete: uniquemember
220 uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
221 uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
222 -
223 add: uniquemember
224 uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
225 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
226
227 dn: cn=All Staff,ou=Groups,dc=example,dc=com
228 changetype: modify
229 delete: description
230
231 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
232 changetype: add
233 objectclass: OpenLDAPperson
234 cn: Gern Jensen
235 sn: Jensen
236 uid: gjensen
237 title: Chief Investigator, ITD
238 postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
239 seealso: cn=All Staff, ou=Groups, dc=example,dc=com
240 drink: Coffee
241 homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
242 description: Very odd
243 facsimiletelephonenumber: +1 313 555 7557
244 facsimiletelephonenumber: +1 313 555 9998
245 facsimiletelephonenumber: +1 313 555 9999
246 telephonenumber: +1 313 555 8343
247 mail: gjensen@mailgw.example.com
248 homephone: +1 313 555 8844
249
250 # modify attribute with no matching rule (ITS#6458)
251 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
252 changetype: modify
253 replace: facsimiletelephonenumber
254 facsimiletelephonenumber: +1 313 555 9998
255 facsimiletelephonenumber: +1 313 555 9999
256
257 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
258 changetype: modify
259 replace: facsimiletelephonenumber
260 facsimiletelephonenumber: +1 313 555 9998
261 facsimiletelephonenumber: +1 313 555 9999
262 facsimiletelephonenumber: +1 313 555 7557
263
264 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
265 changetype: modify
266 replace: facsimiletelephonenumber
267 facsimiletelephonenumber: +1 313 555 9998
268 facsimiletelephonenumber: +1 313 555 9999
269
270 dn: ou=Retired, ou=People, dc=example,dc=com
271 changetype: add
272 objectclass: organizationalUnit
273 ou: Retired
274
275 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
276 changetype: add
277 objectclass: OpenLDAPperson
278 cn: Rosco P. Coltrane
279 sn: Coltrane
280 uid: rosco
281 description: Fat tycoon
282
283 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
284 changetype: modrdn
285 newrdn: cn=Rosco P. Coltrane
286 deleteoldrdn: 1
287 newsuperior: ou=Retired, ou=People, dc=example,dc=com
288
289 dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
290 changetype: delete
291
292 dn: dc=testdomain1,dc=example,dc=com
293 changetype: modrdn
294 newrdn: dc=itsdomain1
295 deleteoldrdn: 1
296
297 dn: dc=itsdomain1,dc=example,dc=com
298 changetype: modify
299 replace: description
300 description: Example, Inc. ITS test domain
301
302 dn: dc=testdomain2,dc=example,dc=com
303 changetype: modrdn
304 newrdn: dc=itsdomain2
305 deleteoldrdn: 1
306
307 EOMODS
308
309 RC=$?
310 if test $RC != 0 ; then
311         echo "ldapmodify failed ($RC)!"
312         test $KILLSERVERS != no && kill -HUP $KILLPIDS
313         exit $RC
314 fi
315
316 echo "Using ldappasswd to change some passwords..."
317 $LDAPPASSWD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
318         'cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com' \
319         > $TESTOUT 2>&1
320 RC=$?
321 if test $RC != 0 ; then
322         echo "ldapmodify failed ($RC)!"
323         test $KILLSERVERS != no && kill -HUP $KILLPIDS
324         exit $RC
325 fi
326
327 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
328 sleep $SLEEP1
329
330 echo "Using ldapsearch to read all the entries from the producer..."
331 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
332         '(objectclass=*)' '*' $OPATTRS > $MASTEROUT 2>&1
333 RC=$?
334
335 if test $RC != 0 ; then
336         echo "ldapsearch failed at producer ($RC)!"
337         test $KILLSERVERS != no && kill -HUP $KILLPIDS
338         exit $RC
339 fi
340
341 echo "Using ldapsearch to read all the entries from the consumer..."
342 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT4 \
343         '(objectclass=*)' '*' $OPATTRS > $SLAVEOUT 2>&1
344 RC=$?
345
346 if test $RC != 0 ; then
347         echo "ldapsearch failed at consumer ($RC)!"
348         test $KILLSERVERS != no && kill -HUP $KILLPIDS
349         exit $RC
350 fi
351
352 echo "Filtering producer results..."
353 $LDIFFILTER < $MASTEROUT > $MASTERFLT
354 echo "Filtering consumer results..."
355 $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
356
357 echo "Comparing retrieved entries from producer and consumer..."
358 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
359
360 if test $? != 0 ; then
361         echo "test failed - producer and consumer databases differ"
362         test $KILLSERVERS != no && kill -HUP $KILLPIDS
363         exit 1
364 fi
365
366 echo "Stopping consumer to test recovery..."
367 kill -HUP $SLAVEPID
368 wait $SLAVEPID
369
370 echo "Modifying more entries on the producer..."
371 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
372         $TESTOUT 2>&1 << EOMODS
373 dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
374 changetype: delete
375
376 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
377 changetype: modify
378 add: drink
379 drink: Mad Dog 20/20
380
381 dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
382 changetype: add
383 objectclass: OpenLDAPperson
384 sn: Coltrane
385 uid: rosco
386 cn: Rosco P. Coltrane
387
388 dn: dc=itsdomain2,dc=example,dc=com
389 changetype: modify
390 replace: description
391 description: Example, Inc. itsdomain2 test domain
392
393 EOMODS
394
395 RC=$?
396 if test $RC != 0 ; then
397         echo "ldapmodify failed ($RC)!"
398         test $KILLSERVERS != no && kill -HUP $KILLPIDS
399         exit $RC
400 fi
401
402 echo "Restarting consumer..."
403 echo "RESTART" >> $LOG4
404 $SLAPD -f $CONF4 -h $URI4 -d $LVL $TIMING >> $LOG4 2>&1 &
405 SLAVEPID=$!
406 if test $WAIT != 0 ; then
407     echo SLAVEPID $SLAVEPID
408     read foo
409 fi
410 KILLPIDS="$PID $SLAVEPID"
411
412 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
413 sleep $SLEEP1
414
415 echo "Using ldapsearch to read all the entries from the producer..."
416 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
417         '(objectclass=*)' '*' $OPATTRS > $MASTEROUT 2>&1
418 RC=$?
419
420 if test $RC != 0 ; then
421         echo "ldapsearch failed at producer ($RC)!"
422         test $KILLSERVERS != no && kill -HUP $KILLPIDS
423         exit $RC
424 fi
425
426 echo "Using ldapsearch to read all the entries from the consumer..."
427 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT4 \
428         '(objectclass=*)' '*' $OPATTRS > $SLAVEOUT 2>&1
429 RC=$?
430
431 if test $RC != 0 ; then
432         echo "ldapsearch failed at consumer ($RC)!"
433         test $KILLSERVERS != no && kill -HUP $KILLPIDS
434         exit $RC
435 fi
436
437 echo "Filtering producer results..."
438 $LDIFFILTER < $MASTEROUT > $MASTERFLT
439 echo "Filtering consumer results..."
440 $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
441
442 echo "Comparing retrieved entries from producer and consumer..."
443 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
444
445 if test $? != 0 ; then
446         echo "test failed - producer and consumer databases differ"
447         test $KILLSERVERS != no && kill -HUP $KILLPIDS
448         exit 1
449 fi
450
451 if test ! $BACKLDAP = "ldapno" ; then
452         echo "Try updating the consumer slapd..."
453         $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT4 -w $PASSWD > \
454                 $TESTOUT 2>&1 << EOMODS
455 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
456 changetype: modify
457 add: description
458 description: This write must fail because directed to a shadow context,
459 description: unless the chain overlay is configured appropriately ;)
460
461 EOMODS
462
463         RC=$?
464         if test $RC != 0 ; then
465                 echo "ldapmodify failed ($RC)!"
466                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
467                 exit $RC
468         fi
469
470         # ITS#4964
471         echo "Trying to change some passwords on the consumer..."
472         $LDAPPASSWD -D "$MANAGERDN" -h $LOCALHOST -p $PORT4 -w $PASSWD \
473                 'cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com' \
474                 > $TESTOUT 2>&1
475         RC=$?
476         if test $RC != 0 ; then
477                 echo "ldapmodify failed ($RC)!"
478                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
479                 exit $RC
480         fi
481
482         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
483         sleep $SLEEP1
484 fi
485
486 echo "Using ldapsearch to read all the entries from the producer..."
487 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
488         '(objectclass=*)' '*' $OPATTRS > $MASTEROUT 2>&1
489 RC=$?
490
491 if test $RC != 0 ; then
492         echo "ldapsearch failed at producer ($RC)!"
493         test $KILLSERVERS != no && kill -HUP $KILLPIDS
494         exit $RC
495 fi
496
497 echo "Using ldapsearch to read all the entries from the consumer..."
498 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT4 \
499         '(objectclass=*)' '*' $OPATTRS > $SLAVEOUT 2>&1
500 RC=$?
501
502 if test $RC != 0 ; then
503         echo "ldapsearch failed at consumer ($RC)!"
504         test $KILLSERVERS != no && kill -HUP $KILLPIDS
505         exit $RC
506 fi
507
508 echo "Filtering producer results..."
509 $LDIFFILTER < $MASTEROUT > $MASTERFLT
510 echo "Filtering consumer results..."
511 $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
512
513 echo "Comparing retrieved entries from producer and consumer..."
514 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
515
516 if test $? != 0 ; then
517         echo "test failed - producer and consumer databases differ"
518         test $KILLSERVERS != no && kill -HUP $KILLPIDS
519         exit 1
520 fi
521
522 test $KILLSERVERS != no && kill -HUP $KILLPIDS
523
524 echo ">>>>> Test succeeded"
525
526 test $KILLSERVERS != no && wait
527
528 exit 0