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