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