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