]> git.sur5r.net Git - openldap/blob - tests/scripts/test043-delta-syncrepl
large X (for version.sh)
[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 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 < \
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 slave 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 slave 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 master 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 master 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 master 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
239 RC=$?
240 if test $RC != 0 ; then
241         echo "ldapmodify failed ($RC)!"
242         test $KILLSERVERS != no && kill -HUP $KILLPIDS
243         exit $RC
244 fi
245
246 echo "Waiting 15 seconds for syncrepl to receive changes..."
247 sleep 15
248
249 echo "Stopping consumer to test recovery..."
250 kill -HUP $SLAVEPID
251 sleep 10
252
253 echo "Modifying more entries on the master..."
254 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
255         $TESTOUT 2>&1 << EOMODS
256 dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
257 changetype: delete
258
259 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
260 changetype: modify
261 add: drink
262 drink: Mad Dog 20/20
263
264 dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
265 changetype: add
266 objectclass: OpenLDAPperson
267 sn: Coltrane
268 uid: rosco
269 cn: Rosco P. Coltrane
270
271 dn: cn=Mark Elliot,ou=Alumni Association,ou=People,dc=example,dc=com
272 changetype: modify
273 replace: drink
274 EOMODS
275
276 echo "Restarting consumer..."
277 echo "RESTART" >> $LOG2
278 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
279 SLAVEPID=$!
280 if test $WAIT != 0 ; then
281     echo SLAVEPID $SLAVEPID
282     read foo
283 fi
284 KILLPIDS="$PID $SLAVEPID"
285
286 echo "Waiting 25 seconds for syncrepl to receive changes..."
287 sleep 25
288
289 if test ! $BACKLDAP = "ldapno" ; then
290         echo "Try updating the slave slapd..."
291         $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
292                 $TESTOUT 2>&1 << EOMODS
293 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
294 changetype: modify
295 add: description
296 description: This write must fail because directed to a shadow context,
297 description: unless the chain overlay is configured appropriately ;)
298
299 EOMODS
300
301         RC=$?
302         if test $RC != 0 ; then
303                 echo "ldapmodify failed ($RC)!"
304                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
305                 exit $RC
306         fi
307
308         echo "Waiting 15 seconds for syncrepl to receive changes..."
309         sleep 15
310 fi
311
312 echo "Using ldapsearch to read all the entries from the master..."
313 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
314         'objectclass=*' > $MASTEROUT 2>&1
315 RC=$?
316
317 if test $RC != 0 ; then
318         echo "ldapsearch failed at master ($RC)!"
319         test $KILLSERVERS != no && kill -HUP $KILLPIDS
320         exit $RC
321 fi
322
323 echo "Using ldapsearch to read all the entries from the slave..."
324 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
325         'objectclass=*' > $SLAVEOUT 2>&1
326 RC=$?
327
328 if test $RC != 0 ; then
329         echo "ldapsearch failed at slave ($RC)!"
330         test $KILLSERVERS != no && kill -HUP $KILLPIDS
331         exit $RC
332 fi
333
334 test $KILLSERVERS != no && kill -HUP $KILLPIDS
335
336 echo "Filtering master results..."
337 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
338 echo "Filtering slave results..."
339 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
340
341 echo "Comparing retrieved entries from master and slave..."
342 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
343
344 if test $? != 0 ; then
345         echo "test failed - master and slave databases differ"
346         exit 1
347 fi
348
349 echo ">>>>> Test succeeded"
350 exit 0