]> git.sur5r.net Git - openldap/blob - tests/scripts/test043-delta-syncrepl
c24e276307a4eb0c69ffb8516334ef4bc46e872c
[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-2009 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 if test $ACCESSLOG = accesslogno; then 
24         echo "Accesslog overlay not available, test skipped"
25         exit 0
26 fi 
27
28 mkdir -p $TESTDIR $DBDIR1A $DBDIR1B $DBDIR2
29
30 #
31 # Test replication:
32 # - start producer
33 # - start consumer
34 # - populate over ldap
35 # - perform some modifies and deleted
36 # - attempt to modify the consumer (referral or chain)
37 # - retrieve database over ldap and compare against expected results
38 #
39
40 echo "Starting producer slapd on TCP/IP port $PORT1..."
41 . $CONFFILTER $BACKEND $MONITORDB < $DSRMASTERCONF > $CONF1
42 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
43 PID=$!
44 if test $WAIT != 0 ; then
45     echo PID $PID
46     read foo
47 fi
48 KILLPIDS="$PID"
49
50 sleep 1
51
52 echo "Using ldapsearch to check that producer slapd is running..."
53 for i in 0 1 2 3 4 5; do
54         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
55                 'objectclass=*' > /dev/null 2>&1
56         RC=$?
57         if test $RC = 0 ; then
58                 break
59         fi
60         echo "Waiting 5 seconds for slapd to start..."
61         sleep 5
62 done
63
64 if test $RC != 0 ; then
65         echo "ldapsearch failed ($RC)!"
66         test $KILLSERVERS != no && kill -HUP $KILLPIDS
67         exit $RC
68 fi
69
70 echo "Using ldapadd to create the context prefix entries in the producer..."
71 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
72         $LDIFORDEREDCP > /dev/null 2>&1
73 RC=$?
74 if test $RC != 0 ; then
75         echo "ldapadd failed ($RC)!"
76         test $KILLSERVERS != no && kill -HUP $KILLPIDS
77         exit $RC
78 fi
79
80 echo "Starting consumer slapd on TCP/IP port $PORT2..."
81 . $CONFFILTER $BACKEND $MONITORDB < $DSRSLAVECONF > $CONF2
82 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
83 SLAVEPID=$!
84 if test $WAIT != 0 ; then
85     echo SLAVEPID $SLAVEPID
86     read foo
87 fi
88 KILLPIDS="$KILLPIDS $SLAVEPID"
89
90 sleep 1
91
92 echo "Using ldapsearch to check that consumer slapd is running..."
93 for i in 0 1 2 3 4 5; do
94         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
95                 'objectclass=*' > /dev/null 2>&1
96         RC=$?
97         if test $RC = 0 ; then
98                 break
99         fi
100         echo "Waiting 5 seconds for slapd to start..."
101         sleep 5
102 done
103
104 if test $RC != 0 ; then
105         echo "ldapsearch failed ($RC)!"
106         test $KILLSERVERS != no && kill -HUP $KILLPIDS
107         exit $RC
108 fi
109
110 echo "Using ldapadd to populate the producer directory..."
111 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
112         $LDIFORDEREDNOCP > /dev/null 2>&1
113 RC=$?
114 if test $RC != 0 ; then
115         echo "ldapadd failed ($RC)!"
116         test $KILLSERVERS != no && kill -HUP $KILLPIDS
117         exit $RC
118 fi
119
120 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
121 sleep $SLEEP1
122
123 echo "Stopping the provider, sleeping 10 seconds and restarting it..."
124 kill -HUP "$PID"
125 sleep 10
126 echo "RESTART" >> $LOG1
127 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
128 PID=$!
129 if test $WAIT != 0 ; then
130     echo PID $PID
131     read foo
132 fi
133 KILLPIDS="$PID $SLAVEPID"
134
135 sleep 1
136
137 echo "Using ldapsearch to check that producer slapd is running..."
138 for i in 0 1 2 3 4 5; do
139         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
140                 'objectclass=*' > /dev/null 2>&1
141         RC=$?
142         if test $RC = 0 ; then
143                 break
144         fi
145         echo "Waiting 5 seconds for slapd to start..."
146         sleep 5
147 done
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 EOMODS
233 RC=$?
234 if test $RC != 0 ; then
235         echo "ldapmodify failed ($RC)!"
236         test $KILLSERVERS != no && kill -HUP $KILLPIDS
237         exit $RC
238 fi
239
240 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
241 sleep $SLEEP1
242
243 echo "Stopping consumer to test recovery..."
244 kill -HUP $SLAVEPID
245 sleep 10
246
247 echo "Modifying more entries on the producer..."
248 $LDAPMODIFY -v -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
249         $TESTOUT 2>&1 << EOMODS
250 dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
251 changetype: delete
252
253 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
254 changetype: modify
255 add: drink
256 drink: Mad Dog 20/20
257
258 dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
259 changetype: add
260 objectclass: OpenLDAPperson
261 sn: Coltrane
262 uid: rosco
263 cn: Rosco P. Coltrane
264
265 dn: cn=Mark Elliot,ou=Alumni Association,ou=People,dc=example,dc=com
266 changetype: modify
267 replace: drink
268
269 dn: cn=All Staff,ou=Groups,dc=example,dc=com
270 changetype: modrdn
271 newrdn: cn=Some Staff
272 deleteoldrdn: 1
273
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 $SLEEP1 seconds for syncrepl to receive changes..."
287 sleep $SLEEP1
288
289 if test ! $BACKLDAP = "ldapno" ; then
290         echo "Try updating the consumer 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 $SLEEP1 seconds for syncrepl to receive changes..."
309         sleep $SLEEP1
310 fi
311
312 echo "Using ldapsearch to read all the entries from the producer..."
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 producer ($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 consumer..."
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 consumer ($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 producer results..."
337 $LDIFFILTER < $MASTEROUT | grep -iv "^auditcontext:" > $MASTERFLT
338 echo "Filtering consumer results..."
339 $LDIFFILTER < $SLAVEOUT | grep -iv "^auditcontext:" > $SLAVEFLT
340
341 echo "Comparing retrieved entries from producer and consumer..."
342 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
343
344 if test $? != 0 ; then
345         echo "test failed - producer and consumer databases differ"
346         exit 1
347 fi
348
349 echo ">>>>> Test succeeded"
350
351 test $KILLSERVERS != no && wait
352
353 exit 0