]> git.sur5r.net Git - openldap/blob - tests/scripts/test018-syncreplication-persist
Update copyright notices
[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-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 if test "$BACKEND" != "bdb" && test "$BACKEND" != "hdb" && test "$BACKEND" != "ldif"; 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 $SLEEP1 seconds for syncrepl to receive changes..."
122 sleep $SLEEP1
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 echo "Waiting $SLEEP1 seconds for consumer to reconnect..."
152 sleep $SLEEP1
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 producer 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 "Using ldappasswd to change some passwords..."
247 $LDAPPASSWD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
248         'cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com' \
249         > $TESTOUT 2>&1
250 RC=$?
251 if test $RC != 0 ; then
252         echo "ldapmodify failed ($RC)!"
253         test $KILLSERVERS != no && kill -HUP $KILLPIDS
254         exit $RC
255 fi
256
257 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
258 sleep $SLEEP1
259
260 echo "Stopping consumer to test recovery..."
261 kill -HUP $SLAVEPID
262 wait $SLAVEPID
263
264 echo "Modifying more entries on the producer..."
265 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
266         $TESTOUT 2>&1 << EOMODS
267 dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
268 changetype: delete
269
270 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
271 changetype: modify
272 add: drink
273 drink: Mad Dog 20/20
274
275 dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
276 changetype: add
277 objectclass: OpenLDAPperson
278 sn: Coltrane
279 uid: rosco
280 cn: Rosco P. Coltrane
281
282 EOMODS
283
284 echo "Restarting consumer..."
285 echo "RESTART" >> $LOG4
286 $SLAPD -f $CONF4 -h $URI4 -d $LVL $TIMING >> $LOG4 2>&1 &
287 SLAVEPID=$!
288 if test $WAIT != 0 ; then
289     echo SLAVEPID $SLAVEPID
290     read foo
291 fi
292 KILLPIDS="$PID $SLAVEPID"
293
294 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
295 sleep $SLEEP1
296
297 if test ! $BACKLDAP = "ldapno" ; then
298         echo "Try updating the consumer slapd..."
299         $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT4 -w $PASSWD > \
300                 $TESTOUT 2>&1 << EOMODS
301 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
302 changetype: modify
303 add: description
304 description: This write must fail because directed to a shadow context,
305 description: unless the chain overlay is configured appropriately ;)
306
307 EOMODS
308
309         RC=$?
310         if test $RC != 0 ; then
311                 echo "ldapmodify failed ($RC)!"
312                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
313                 exit $RC
314         fi
315
316         # ITS#4964
317         echo "Trying to change some passwords on the consumer..."
318         $LDAPPASSWD -D "$MANAGERDN" -h $LOCALHOST -p $PORT4 -w $PASSWD \
319                 'cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com' \
320                 > $TESTOUT 2>&1
321         RC=$?
322         if test $RC != 0 ; then
323                 echo "ldapmodify failed ($RC)!"
324                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
325                 exit $RC
326         fi
327
328         echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
329         sleep $SLEEP1
330 fi
331
332 OPATTRS="entryUUID creatorsName createTimestamp modifiersName modifyTimestamp"
333
334 echo "Using ldapsearch to read all the entries from the producer..."
335 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
336         '(objectclass=*)' '*' $OPATTRS > $MASTEROUT 2>&1
337 RC=$?
338
339 if test $RC != 0 ; then
340         echo "ldapsearch failed at producer ($RC)!"
341         test $KILLSERVERS != no && kill -HUP $KILLPIDS
342         exit $RC
343 fi
344
345 echo "Using ldapsearch to read all the entries from the consumer..."
346 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT4 \
347         '(objectclass=*)' '*' $OPATTRS > $SLAVEOUT 2>&1
348 RC=$?
349
350 if test $RC != 0 ; then
351         echo "ldapsearch failed at consumer ($RC)!"
352         test $KILLSERVERS != no && kill -HUP $KILLPIDS
353         exit $RC
354 fi
355
356 test $KILLSERVERS != no && kill -HUP $KILLPIDS
357
358 echo "Filtering producer results..."
359 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
360 echo "Filtering consumer results..."
361 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
362
363 echo "Comparing retrieved entries from producer and consumer..."
364 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
365
366 if test $? != 0 ; then
367         echo "test failed - producer and consumer databases differ"
368         exit 1
369 fi
370
371 echo ">>>>> Test succeeded"
372
373 test $KILLSERVERS != no && wait
374
375 exit 0