]> git.sur5r.net Git - openldap/blob - tests/scripts/test043-delta-syncrepl
Happy new year (belated)
[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-2014 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 if test $BACKEND = ldif ; then
28         # Onelevel search does not return entries in order of creation or CSN.
29         echo "$BACKEND backend unsuitable for syncprov logdb, test skipped"
30         exit 0
31 fi
32
33 mkdir -p $TESTDIR $DBDIR1A $DBDIR1B $DBDIR2
34
35 #
36 # Test replication:
37 # - start provider
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 provider 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 provider 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 provider..."
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 provider 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 $SLEEP1 seconds for syncrepl to receive changes..."
126 sleep $SLEEP1
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 provider 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 provider 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 $SLEEP1 seconds for syncrepl to receive changes..."
246 sleep $SLEEP1
247
248 echo "Using ldapsearch to read all the entries from the provider..."
249 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
250         'objectclass=*' \* + > $MASTEROUT 2>&1
251 RC=$?
252
253 if test $RC != 0 ; then
254         echo "ldapsearch failed at provider ($RC)!"
255         test $KILLSERVERS != no && kill -HUP $KILLPIDS
256         exit $RC
257 fi
258
259 echo "Using ldapsearch to read all the entries from the consumer..."
260 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
261         'objectclass=*' \* + > $SLAVEOUT 2>&1
262 RC=$?
263
264 if test $RC != 0 ; then
265         echo "ldapsearch failed at consumer ($RC)!"
266         test $KILLSERVERS != no && kill -HUP $KILLPIDS
267         exit $RC
268 fi
269
270 echo "Filtering provider results..."
271 $LDIFFILTER -s bdb=a,hdb=a < $MASTEROUT | grep -iv "^auditcontext:" > $MASTERFLT
272 echo "Filtering consumer results..."
273 $LDIFFILTER -s bdb=a,hdb=a < $SLAVEOUT | grep -iv "^auditcontext:" > $SLAVEFLT
274
275 echo "Comparing retrieved entries from provider and consumer..."
276 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
277
278 if test $? != 0 ; then
279         echo "test failed - provider and consumer databases differ"
280         test $KILLSERVERS != no && kill -HUP $KILLPIDS
281         exit 1
282 fi
283
284 echo "Stopping consumer to test recovery..."
285 kill -HUP $SLAVEPID
286 sleep 10
287
288 echo "Modifying more entries on the provider..."
289 $LDAPMODIFY -v -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
290         $TESTOUT 2>&1 << EOMODS
291 dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
292 changetype: delete
293
294 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
295 changetype: modify
296 add: drink
297 drink: Mad Dog 20/20
298
299 dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
300 changetype: add
301 objectclass: OpenLDAPperson
302 sn: Coltrane
303 uid: rosco
304 cn: Rosco P. Coltrane
305
306 dn: cn=Mark Elliot,ou=Alumni Association,ou=People,dc=example,dc=com
307 changetype: modify
308 replace: drink
309
310 dn: cn=All Staff,ou=Groups,dc=example,dc=com
311 changetype: modrdn
312 newrdn: cn=Some Staff
313 deleteoldrdn: 1
314
315 EOMODS
316
317 echo "Restarting consumer..."
318 echo "RESTART" >> $LOG2
319 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
320 SLAVEPID=$!
321 if test $WAIT != 0 ; then
322     echo SLAVEPID $SLAVEPID
323     read foo
324 fi
325 KILLPIDS="$PID $SLAVEPID"
326
327 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
328 sleep $SLEEP1
329
330 if test ! $BACKLDAP = "ldapno" ; then
331         echo "Try updating the consumer slapd..."
332         $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
333                 $TESTOUT 2>&1 << EOMODS
334 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
335 changetype: modify
336 add: description
337 description: This write must fail because directed to a shadow context,
338 description: unless the chain overlay is configured appropriately ;)
339
340 EOMODS
341
342         RC=$?
343         if test $RC != 0 ; then
344                 echo "ldapmodify failed ($RC)!"
345                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
346                 exit $RC
347         fi
348
349         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
350         sleep $SLEEP1
351 fi
352
353 echo "Using ldapsearch to read all the entries from the provider..."
354 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
355         'objectclass=*' \* + > $MASTEROUT 2>&1
356 RC=$?
357
358 if test $RC != 0 ; then
359         echo "ldapsearch failed at provider ($RC)!"
360         test $KILLSERVERS != no && kill -HUP $KILLPIDS
361         exit $RC
362 fi
363
364 echo "Using ldapsearch to read all the entries from the consumer..."
365 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
366         'objectclass=*' \* + > $SLAVEOUT 2>&1
367 RC=$?
368
369 if test $RC != 0 ; then
370         echo "ldapsearch failed at consumer ($RC)!"
371         test $KILLSERVERS != no && kill -HUP $KILLPIDS
372         exit $RC
373 fi
374
375 test $KILLSERVERS != no && kill -HUP $KILLPIDS
376
377 echo "Filtering provider results..."
378 $LDIFFILTER -s bdb=a,hdb=a < $MASTEROUT | grep -iv "^auditcontext:" > $MASTERFLT
379 echo "Filtering consumer results..."
380 $LDIFFILTER -s bdb=a,hdb=a < $SLAVEOUT | grep -iv "^auditcontext:" > $SLAVEFLT
381
382 echo "Comparing retrieved entries from provider and consumer..."
383 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
384
385 if test $? != 0 ; then
386         echo "test failed - provider and consumer databases differ"
387         exit 1
388 fi
389
390 echo ">>>>> Test succeeded"
391
392 test $KILLSERVERS != no && wait
393
394 exit 0