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