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