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