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