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