]> git.sur5r.net Git - openldap/blob - tests/scripts/test033-glue-syncrepl
7e1f878f31892ff51114e4f96fa12b48032a15fc
[openldap] / tests / scripts / test033-glue-syncrepl
1 #! /bin/sh
2 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
3 ##
4 ## Copyright 1998-2005 The OpenLDAP Foundation.
5 ## All rights reserved.
6 ##
7 ## Redistribution and use in source and binary forms, with or without
8 ## modification, are permitted only as authorized by the OpenLDAP
9 ## Public License.
10 ##
11 ## A copy of this license is available in the file LICENSE in the
12 ## top-level directory of the distribution or, alternatively, at
13 ## <http://www.OpenLDAP.org/license.html>.
14
15 if test "$BACKEND" != "bdb" && test "$BACKEND" != "hdb" ; then
16         echo "Test does not support $BACKEND"
17         exit 0
18 fi
19
20 echo "running defines.sh"
21 . $SRCDIR/scripts/defines.sh
22
23 mkdir -p $TESTDIR $DBDIR1A $DBDIR1B $DBDIR1C $DBDIR2A $DBDIR2B
24
25 echo "Running slapadd to build glued slapd databases..."
26 . $CONFFILTER $BACKEND $MONITORDB < $GLUECONF > $CONF1
27 $SLAPADD -d $LVL -f $CONF1 -l $LDIFORDERED > $SLAPADDLOG1 2>&1
28 RC=$?
29 if test $RC != 0 ; then
30         echo "slapadd failed ($RC)!"
31         exit $RC
32 fi
33
34 rm -f $DBDIR1A/* $DBDIR1B/*
35 cp -pr $DBDIR1C $DBDIR2C
36
37 echo "Starting slapd 1 on TCP/IP port $PORT1..."
38 . $CONFFILTER $BACKEND $MONITORDB < $GLUESYNCCONF1 > $CONF1
39 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
40 PID=$!
41 if test $WAIT != 0 ; then
42     echo PID $PID
43     read foo
44 fi
45 KILLPIDS="$PID"
46
47 sleep 1
48
49 echo "Using ldapsearch to check that slapd 1 is running..."
50 for i in 0 1 2 3 4 5; do
51         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
52                 '(objectclass=*)' > /dev/null 2>&1
53         RC=$?
54         if test $RC = 0 ; then
55                 break
56         fi
57         echo "Waiting 5 seconds for slapd to start..."
58         sleep 5
59 done
60
61 echo "Starting slapd 2 on TCP/IP port $PORT2..."
62 . $CONFFILTER $BACKEND $MONITORDB < $GLUESYNCCONF2 > $CONF2
63 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
64 PID=$!
65 if test $WAIT != 0 ; then
66     echo PID $PID
67     read foo
68 fi
69 KILLPIDS="$KILLPIDS $PID"
70
71 sleep 1
72
73 echo "Using ldapsearch to check that slapd 2 is running..."
74 for i in 0 1 2 3 4 5; do
75         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
76                 '(objectclass=*)' > /dev/null 2>&1
77         RC=$?
78         if test $RC = 0 ; then
79                 break
80         fi
81         echo "Waiting 5 seconds for slapd to start..."
82         sleep 5
83 done
84
85 SUBTREE1="ou=Information Technology Division,ou=People,dc=example,dc=com"
86 SUBTREE2="ou=Groups,dc=example,dc=com"
87
88 echo "Using ldapadd to populate subtree=\"${SUBTREE1}\" on port $PORT1..."
89 $LDAPADD -D "cn=Manager 1,$BASEDN" -w $PASSWD -h $LOCALHOST -p $PORT1 \
90         -f $LDIFORDERED -c \
91         > /dev/null 2>&1
92 RC=$?
93 case $RC in
94 0)
95         echo "ldapadd should have failed ($RC)!"
96         test $KILLSERVERS != no && kill -HUP $KILLPIDS
97         exit -1
98         ;;
99 10|68)
100         # Fine if we get alreadyExists or referrals
101         ;;
102 *)
103         echo "ldapadd failed ($RC)!"
104         test $KILLSERVERS != no && kill -HUP $KILLPIDS
105         exit $RC
106         ;;
107 esac
108
109 echo "Using ldapadd to populate subtree=\"${SUBTREE2}\" on port $PORT2..."
110 $LDAPADD -D "cn=Manager 2,$BASEDN" -w $PASSWD -h $LOCALHOST -p $PORT2 \
111         -f $LDIFORDERED -c \
112         > /dev/null 2>&1
113 RC=$?
114 case $RC in
115 0)
116         echo "ldapadd should have failed ($RC)!"
117         test $KILLSERVERS != no && kill -HUP $KILLPIDS
118         exit -1
119         ;;
120 10|68)
121         # Fine if we get alreadyExists or referrals
122         ;;
123 *)
124         echo "ldapadd failed ($RC)!"
125         test $KILLSERVERS != no && kill -HUP $KILLPIDS
126         exit $RC
127         ;;
128 esac
129
130 SLEEP=15
131 echo "Waiting $SLEEP seconds for shadow subtrees to sync..."
132 sleep $SLEEP
133
134 echo "Filtering original ldif used to create database..."
135 . $LDIFFILTER < $GLUESYNCOUT > $LDIFFLT
136
137 for P in $PORT1 $PORT2 ; do
138         echo "Using ldapsearch to read all the entries from port $P..."
139         $LDAPSEARCH -b "$BASEDN" -h $LOCALHOST -p $P \
140                 -S "" '(objectclass=*)' > "${SEARCHOUT}.${P}" 2>&1
141         RC=$?
142
143         if test $RC != 0 ; then
144                 echo "ldapsearch failed ($RC)!"
145                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
146                 exit $RC
147         fi
148
149         echo "Filtering ldapsearch results..."
150         . $LDIFFILTER < "${SEARCHOUT}.${P}" > $SEARCHFLT
151         echo "Comparing filter output..."
152         $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
153
154         if test $? != 0 ; then
155                 echo "comparison failed - database was not created correctly"
156                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
157                 exit 1
158         fi
159 done
160
161 test $KILLSERVERS != no && kill -HUP $KILLPIDS
162
163 echo ">>>>> Test succeeded"
164 exit 0