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