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