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