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