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