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