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