]> git.sur5r.net Git - openldap/blob - tests/scripts/test007-replication
a8a7a31f79981b1837eb18941ba5fe1aad085555
[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
9 . $SRCDIR/scripts/args.sh
10
11 echo "running defines.sh"
12 . $SRCDIR/scripts/defines.sh
13
14 #
15 # Test replication:
16 # - start master
17 # - start slave
18 # - start slurpd
19 # - populate over ldap
20 # - perform some modifies and deleted
21 # - retrieve database over ldap and compare against expected results
22 #
23
24 if test ! -x $SLURPD ; then
25         echo ">>>>> $SLURPD is not executable or do not exist."
26         echo ">>>>> Test skipped."
27         exit 0
28 fi
29
30 echo "Cleaning up in $DBDIR..."
31 rm -f $DBDIR/[!C]*
32 echo "Cleaning up in $REPLDIR..."
33 rm -rf $REPLDIR/[!C]*
34
35 echo "Starting master slapd on TCP/IP port $PORT..."
36 . $CONFFILTER $BACKEND $MONITORDB < $MASTERCONF > $DBCONF
37 $SLAPD -f $DBCONF -h $MASTERURI -d $LVL $TIMING > $MASTERLOG 2>&1 &
38 PID=$!
39 if test $WAIT != 0 ; then
40     echo PID $PID
41     read foo
42 fi
43
44 echo "Starting slave slapd on TCP/IP port $SLAVEPORT..."
45 . $CONFFILTER $BACKEND $MONITORDB < $SLAVECONF > $REPLCONF
46 $SLAPD -f $REPLCONF -h $SLAVEURI -d $LVL $TIMING > $SLAVELOG 2>&1 &
47 SLAVEPID=$!
48 if test $WAIT != 0 ; then
49     echo SLAVEPID $SLAVEPID
50     read foo
51 fi
52
53 echo "Using ldapsearch to check that master slapd is running..."
54 for i in 0 1 2 3 4 5; do
55         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT \
56                 'objectclass=*' > /dev/null 2>&1
57         RC=$?
58         if test $RC = 0 ; then
59                 break
60         fi
61         echo "Waiting 5 seconds for slapd to start..."
62         sleep 5
63 done
64
65 echo "Using ldapsearch to check that slave slapd is running..."
66 for i in 0 1 2 3 4 5; do
67         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $SLAVEPORT \
68                 'objectclass=*' > /dev/null 2>&1
69         RC=$?
70         if test $RC = 0 ; then
71                 break
72         fi
73         echo "Waiting 5 seconds for slapd to start..."
74         sleep 5
75 done
76
77 echo "Starting slurpd..."
78 $SLURPD -f $MASTERCONF -d ${SLURPD_DEBUG-5} -t $REPLDIR > $SLURPLOG 2>&1 &
79 SLURPPID=$!
80 if test $WAIT != 0 ; then
81     echo SLURPPID $SLURPPID
82     read foo
83 fi
84
85 echo "Using ldapadd to populate the master directory..."
86 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT -w $PASSWD < \
87         $LDIFORDERED > /dev/null 2>&1
88 RC=$?
89 if test $RC != 0 ; then
90         echo "ldapadd failed ($RC)!"
91         kill -HUP $PID $SLAVEPID
92         kill -HUP $SLURPPID
93         exit $RC
94 fi
95
96 echo "Waiting 15 seconds for slurpd to send changes..."
97 sleep 15
98
99 echo "Using ldapmodify to modify master directory..."
100
101 #
102 # Do some modifications
103 #
104
105 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT -w $PASSWD > \
106         $TESTOUT 2>&1 << EOMODS
107 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, o=University of Michigan, c=US
108 changetype: modify
109 add: drink
110 drink: Orange Juice
111 -
112 delete: sn
113 sn: Jones
114 -
115 add: sn
116 sn: Jones
117
118 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
119 changetype: modify
120 replace: drink
121 drink: Iced Tea
122 drink: Mad Dog 20/20
123
124 dn: cn=ITD Staff,ou=Groups,o=University of Michigan,c=US
125 changetype: modify
126 delete: member
127 member: cn=James A Jones 2, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
128 member: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
129 -
130 add: member
131 member: cn=Dorothy Stevens, ou=Alumni Association, ou=People, o=University of Michigan, c=US
132 member: cn=James A Jones 1, ou=Alumni Association, ou=People, o=University of Michigan, c=US
133
134 dn: cn=All Staff,ou=Groups,o=University of Michigan,c=US
135 changetype: modify
136 delete: description
137
138 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
139 changetype: add
140 objectclass: OpenLDAPperson
141 cn: Gern Jensen
142 sn: Jensen
143 uid: gjensen
144 title: Chief Investigator, ITD
145 postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
146 seealso: cn=All Staff, ou=Groups, o=University of Michigan, c=US
147 drink: Coffee
148 homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
149 description: Very odd
150 facsimiletelephonenumber: +1 313 555 7557
151 telephonenumber: +1 313 555 8343
152 mail: gjensen@mailgw.example.com
153 homephone: +1 313 555 8844
154
155 dn: ou=Retired, ou=People, o=University of Michigan, c=US
156 changetype: add
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: OpenLDAPperson
163 cn: Rosco P. Coltrane
164 sn: Coltrane
165 uid: rosco
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 -HUP $PID $SLAVEPID
189         kill -HUP $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 -HUP $PID $SLAVEPID
201         kill -HUP $SLURPPID
202         exit $RC
203 fi
204
205 kill -HUP $PID $SLAVEPID
206 kill -HUP $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