Home | History | Annotate | Line # | Download | only in scripts
test049-sync-config revision 1.1
      1  1.1  lukem #! /bin/sh
      2  1.1  lukem # $OpenLDAP: pkg/ldap/tests/scripts/test049-sync-config,v 1.4.2.4 2008/02/11 23:26:51 kurt Exp $
      3  1.1  lukem ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4  1.1  lukem ##
      5  1.1  lukem ## Copyright 1998-2008 The OpenLDAP Foundation.
      6  1.1  lukem ## All rights reserved.
      7  1.1  lukem ##
      8  1.1  lukem ## Redistribution and use in source and binary forms, with or without
      9  1.1  lukem ## modification, are permitted only as authorized by the OpenLDAP
     10  1.1  lukem ## Public License.
     11  1.1  lukem ##
     12  1.1  lukem ## A copy of this license is available in the file LICENSE in the
     13  1.1  lukem ## top-level directory of the distribution or, alternatively, at
     14  1.1  lukem ## <http://www.OpenLDAP.org/license.html>.
     15  1.1  lukem 
     16  1.1  lukem echo "running defines.sh"
     17  1.1  lukem . $SRCDIR/scripts/defines.sh
     18  1.1  lukem 
     19  1.1  lukem if test $SYNCPROV = syncprovno; then 
     20  1.1  lukem 	echo "Syncrepl provider overlay not available, test skipped"
     21  1.1  lukem 	exit 0
     22  1.1  lukem fi 
     23  1.1  lukem 
     24  1.1  lukem PRODIR=$TESTDIR/pro
     25  1.1  lukem CONDIR=$TESTDIR/con
     26  1.1  lukem DBPRO=$PRODIR/db
     27  1.1  lukem DBCON=$CONDIR/db
     28  1.1  lukem CFPRO=$PRODIR/slapd.d
     29  1.1  lukem CFCON=$CONDIR/slapd.d
     30  1.1  lukem 
     31  1.1  lukem mkdir -p $TESTDIR $PRODIR $CONDIR $DBPRO $DBCON $CFPRO $CFCON
     32  1.1  lukem 
     33  1.1  lukem $SLAPPASSWD -g -n >$CONFIGPWF
     34  1.1  lukem 
     35  1.1  lukem #
     36  1.1  lukem # Test replication of dynamic config:
     37  1.1  lukem # - start producer
     38  1.1  lukem # - start consumer
     39  1.1  lukem # - configure over ldap
     40  1.1  lukem # - populate over ldap
     41  1.1  lukem # - configure syncrepl over ldap
     42  1.1  lukem # - retrieve database over ldap and compare against expected results
     43  1.1  lukem #
     44  1.1  lukem 
     45  1.1  lukem echo "Starting producer slapd on TCP/IP port $PORT1..."
     46  1.1  lukem . $CONFFILTER $BACKEND $MONITORDB < $DYNAMICCONF > $CONFLDIF
     47  1.1  lukem $SLAPADD -F $CFPRO -n 0 -l $CONFLDIF
     48  1.1  lukem cd $PRODIR
     49  1.1  lukem $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
     50  1.1  lukem PID=$!
     51  1.1  lukem if test $WAIT != 0 ; then
     52  1.1  lukem     echo PID $PID
     53  1.1  lukem     read foo
     54  1.1  lukem fi
     55  1.1  lukem KILLPIDS="$PID"
     56  1.1  lukem cd $TESTWD
     57  1.1  lukem 
     58  1.1  lukem sleep 1
     59  1.1  lukem 
     60  1.1  lukem echo "Using ldapsearch to check that producer slapd is running..."
     61  1.1  lukem for i in 0 1 2 3 4 5; do
     62  1.1  lukem 	$LDAPSEARCH -s base -b "" -H $URI1 \
     63  1.1  lukem 		'objectclass=*' > /dev/null 2>&1
     64  1.1  lukem 	RC=$?
     65  1.1  lukem 	if test $RC = 0 ; then
     66  1.1  lukem 		break
     67  1.1  lukem 	fi
     68  1.1  lukem 	echo "Waiting 5 seconds for slapd to start..."
     69  1.1  lukem 	sleep 5
     70  1.1  lukem done
     71  1.1  lukem 
     72  1.1  lukem if test $RC != 0 ; then
     73  1.1  lukem 	echo "ldapsearch failed ($RC)!"
     74  1.1  lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     75  1.1  lukem 	exit $RC
     76  1.1  lukem fi
     77  1.1  lukem 
     78  1.1  lukem echo "Inserting syncprov overlay on producer..."
     79  1.1  lukem if [ "$SYNCPROV" = syncprovmod ]; then
     80  1.1  lukem 	$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
     81  1.1  lukem dn: cn=module,cn=config
     82  1.1  lukem objectClass: olcModuleList
     83  1.1  lukem cn: module
     84  1.1  lukem olcModulePath: ../../../servers/slapd/overlays
     85  1.1  lukem olcModuleLoad: syncprov.la
     86  1.1  lukem EOF
     87  1.1  lukem 	RC=$?
     88  1.1  lukem 	if test $RC != 0 ; then
     89  1.1  lukem 		echo "ldapadd failed for moduleLoad ($RC)!"
     90  1.1  lukem 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
     91  1.1  lukem 		exit $RC
     92  1.1  lukem 	fi
     93  1.1  lukem fi
     94  1.1  lukem read CONFIGPW < $CONFIGPWF
     95  1.1  lukem $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
     96  1.1  lukem dn: olcDatabase={0}config,cn=config
     97  1.1  lukem changetype: modify
     98  1.1  lukem add: olcSyncRepl
     99  1.1  lukem olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
    100  1.1  lukem   credentials=$CONFIGPW searchbase="cn=config" type=refreshOnly
    101  1.1  lukem   interval=00:00:00:10
    102  1.1  lukem -
    103  1.1  lukem add: olcUpdateRef
    104  1.1  lukem olcUpdateRef: $URI1
    105  1.1  lukem 
    106  1.1  lukem dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
    107  1.1  lukem changetype: add
    108  1.1  lukem objectClass: olcOverlayConfig
    109  1.1  lukem objectClass: olcSyncProvConfig
    110  1.1  lukem olcOverlay: syncprov
    111  1.1  lukem EOF
    112  1.1  lukem RC=$?
    113  1.1  lukem if test $RC != 0 ; then
    114  1.1  lukem 	echo "ldapmodify failed for syncrepl config ($RC)!"
    115  1.1  lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    116  1.1  lukem 	exit $RC
    117  1.1  lukem fi
    118  1.1  lukem 
    119  1.1  lukem echo "Starting consumer slapd on TCP/IP port $PORT2..."
    120  1.1  lukem $SLAPADD -F $CFCON -n 0 -l $CONFLDIF
    121  1.1  lukem cd $CONDIR
    122  1.1  lukem $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
    123  1.1  lukem SLAVEPID=$!
    124  1.1  lukem if test $WAIT != 0 ; then
    125  1.1  lukem     echo SLAVEPID $SLAVEPID
    126  1.1  lukem     read foo
    127  1.1  lukem fi
    128  1.1  lukem KILLPIDS="$KILLPIDS $SLAVEPID"
    129  1.1  lukem cd $TESTWD
    130  1.1  lukem 
    131  1.1  lukem sleep 1
    132  1.1  lukem 
    133  1.1  lukem echo "Using ldapsearch to check that consumer slapd is running..."
    134  1.1  lukem for i in 0 1 2 3 4 5; do
    135  1.1  lukem 	$LDAPSEARCH -s base -b "" -H $URI2 \
    136  1.1  lukem 		'objectclass=*' > /dev/null 2>&1
    137  1.1  lukem 	RC=$?
    138  1.1  lukem 	if test $RC = 0 ; then
    139  1.1  lukem 		break
    140  1.1  lukem 	fi
    141  1.1  lukem 	echo "Waiting 5 seconds for slapd to start..."
    142  1.1  lukem 	sleep 5
    143  1.1  lukem done
    144  1.1  lukem 
    145  1.1  lukem if test $RC != 0 ; then
    146  1.1  lukem 	echo "ldapsearch failed ($RC)!"
    147  1.1  lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    148  1.1  lukem 	exit $RC
    149  1.1  lukem fi
    150  1.1  lukem 
    151  1.1  lukem echo "Configuring syncrepl on consumer..."
    152  1.1  lukem $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
    153  1.1  lukem dn: olcDatabase={0}config,cn=config
    154  1.1  lukem changetype: modify
    155  1.1  lukem add: olcSyncRepl
    156  1.1  lukem olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
    157  1.1  lukem   credentials=$CONFIGPW searchbase="cn=config" type=refreshOnly
    158  1.1  lukem   interval=00:00:00:10
    159  1.1  lukem -
    160  1.1  lukem add: olcUpdateRef
    161  1.1  lukem olcUpdateRef: $URI1
    162  1.1  lukem EOF
    163  1.1  lukem 
    164  1.1  lukem SLEEP=10
    165  1.1  lukem echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
    166  1.1  lukem sleep $SLEEP
    167  1.1  lukem 
    168  1.1  lukem echo "Using ldapsearch to check that syncrepl received config changes..."
    169  1.1  lukem RC=32
    170  1.1  lukem for i in 0 1 2 3 4 5; do
    171  1.1  lukem 	RESULT=`$LDAPSEARCH -H $URI2 -D cn=config -y $CONFIGPWF \
    172  1.1  lukem 		-s base -b "olcDatabase={0}config,cn=config" \
    173  1.1  lukem 		'(olcUpdateRef=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
    174  1.1  lukem 	if test "x$RESULT" = "xOK" ; then
    175  1.1  lukem 		RC=0
    176  1.1  lukem 		break
    177  1.1  lukem 	fi
    178  1.1  lukem 	echo "Waiting 5 seconds for syncrepl to receive changes..."
    179  1.1  lukem 	sleep 5
    180  1.1  lukem done
    181  1.1  lukem 
    182  1.1  lukem if test $RC != 0 ; then
    183  1.1  lukem 	echo "ldapsearch failed ($RC)!"
    184  1.1  lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    185  1.1  lukem 	exit $RC
    186  1.1  lukem fi
    187  1.1  lukem 
    188  1.1  lukem echo "Adding schema and databases on producer..."
    189  1.1  lukem $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
    190  1.1  lukem include: file://$ABS_SCHEMADIR/core.ldif
    191  1.1  lukem 
    192  1.1  lukem include: file://$ABS_SCHEMADIR/cosine.ldif
    193  1.1  lukem 
    194  1.1  lukem include: file://$ABS_SCHEMADIR/inetorgperson.ldif
    195  1.1  lukem 
    196  1.1  lukem include: file://$ABS_SCHEMADIR/openldap.ldif
    197  1.1  lukem 
    198  1.1  lukem include: file://$ABS_SCHEMADIR/nis.ldif
    199  1.1  lukem EOF
    200  1.1  lukem RC=$?
    201  1.1  lukem if test $RC != 0 ; then
    202  1.1  lukem 	echo "ldapadd failed for schema config ($RC)!"
    203  1.1  lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    204  1.1  lukem 	exit $RC
    205  1.1  lukem fi
    206  1.1  lukem 
    207  1.1  lukem if [ "$BACKENDTYPE" = mod ]; then
    208  1.1  lukem 	$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
    209  1.1  lukem dn: cn=module,cn=config
    210  1.1  lukem objectClass: olcModuleList
    211  1.1  lukem cn: module
    212  1.1  lukem olcModulePath: ../../../servers/slapd/back-$BACKEND
    213  1.1  lukem olcModuleLoad: back_$BACKEND.la
    214  1.1  lukem EOF
    215  1.1  lukem 	RC=$?
    216  1.1  lukem 	if test $RC != 0 ; then
    217  1.1  lukem 		echo "ldapadd failed for backend config ($RC)!"
    218  1.1  lukem 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
    219  1.1  lukem 		exit $RC
    220  1.1  lukem 	fi
    221  1.1  lukem fi
    222  1.1  lukem 
    223  1.1  lukem $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
    224  1.1  lukem dn: olcDatabase={1}$BACKEND,cn=config
    225  1.1  lukem objectClass: olcDatabaseConfig
    226  1.1  lukem objectClass: olc${BACKEND}Config
    227  1.1  lukem olcDatabase: {1}$BACKEND
    228  1.1  lukem olcSuffix: $BASEDN
    229  1.1  lukem olcDbDirectory: ./db
    230  1.1  lukem olcRootDN: $MANAGERDN
    231  1.1  lukem olcRootPW: $PASSWD
    232  1.1  lukem olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
    233  1.1  lukem   credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
    234  1.1  lukem   interval=00:00:00:10
    235  1.1  lukem olcUpdateRef: $URI1
    236  1.1  lukem 
    237  1.1  lukem dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
    238  1.1  lukem changetype: add
    239  1.1  lukem objectClass: olcOverlayConfig
    240  1.1  lukem objectClass: olcSyncProvConfig
    241  1.1  lukem olcOverlay: syncprov
    242  1.1  lukem EOF
    243  1.1  lukem RC=$?
    244  1.1  lukem if test $RC != 0 ; then
    245  1.1  lukem 	echo "ldapadd failed for database config ($RC)!"
    246  1.1  lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    247  1.1  lukem 	exit $RC
    248  1.1  lukem fi
    249  1.1  lukem 
    250  1.1  lukem echo "Using ldapadd to populate producer..."
    251  1.1  lukem $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
    252  1.1  lukem 	>> $TESTOUT 2>&1
    253  1.1  lukem RC=$?
    254  1.1  lukem if test $RC != 0 ; then
    255  1.1  lukem 	echo "ldapadd failed for database config ($RC)!"
    256  1.1  lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    257  1.1  lukem 	exit $RC
    258  1.1  lukem fi
    259  1.1  lukem 
    260  1.1  lukem SLEEP=20
    261  1.1  lukem echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
    262  1.1  lukem sleep $SLEEP
    263  1.1  lukem 
    264  1.1  lukem echo "Using ldapsearch to check that syncrepl received database changes..."
    265  1.1  lukem RC=32
    266  1.1  lukem for i in 0 1 2 3 4 5; do
    267  1.1  lukem 	RESULT=`$LDAPSEARCH -H $URI2 \
    268  1.1  lukem 		-s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
    269  1.1  lukem 		'(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
    270  1.1  lukem 	if test "x$RESULT" = "xOK" ; then
    271  1.1  lukem 		RC=0
    272  1.1  lukem 		break
    273  1.1  lukem 	fi
    274  1.1  lukem 	echo "Waiting 5 seconds for syncrepl to receive changes..."
    275  1.1  lukem 	sleep 5
    276  1.1  lukem done
    277  1.1  lukem 
    278  1.1  lukem if test $RC != 0 ; then
    279  1.1  lukem 	echo "ldapsearch failed ($RC)!"
    280  1.1  lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    281  1.1  lukem 	exit $RC
    282  1.1  lukem fi
    283  1.1  lukem 
    284  1.1  lukem echo "Using ldapsearch to read config from the producer..."
    285  1.1  lukem $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF  \
    286  1.1  lukem 	'objectclass=*' > $MASTEROUT 2>&1
    287  1.1  lukem RC=$?
    288  1.1  lukem 
    289  1.1  lukem if test $RC != 0 ; then
    290  1.1  lukem 	echo "ldapsearch failed at producer ($RC)!"
    291  1.1  lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    292  1.1  lukem 	exit $RC
    293  1.1  lukem fi
    294  1.1  lukem 
    295  1.1  lukem echo "Using ldapsearch to read config from the consumer..."
    296  1.1  lukem $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
    297  1.1  lukem 	'objectclass=*' > $SLAVEOUT 2>&1
    298  1.1  lukem RC=$?
    299  1.1  lukem 
    300  1.1  lukem if test $RC != 0 ; then
    301  1.1  lukem 	echo "ldapsearch failed at consumer ($RC)!"
    302  1.1  lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    303  1.1  lukem 	exit $RC
    304  1.1  lukem fi
    305  1.1  lukem 
    306  1.1  lukem echo "Filtering producer results..."
    307  1.1  lukem . $LDIFFILTER < $MASTEROUT > $MASTERFLT
    308  1.1  lukem echo "Filtering consumer results..."
    309  1.1  lukem . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
    310  1.1  lukem 
    311  1.1  lukem echo "Comparing retrieved configs from producer and consumer..."
    312  1.1  lukem $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
    313  1.1  lukem 
    314  1.1  lukem if test $? != 0 ; then
    315  1.1  lukem 	echo "test failed - producer and consumer configs differ"
    316  1.1  lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    317  1.1  lukem 	exit 1
    318  1.1  lukem fi
    319  1.1  lukem 
    320  1.1  lukem echo "Using ldapsearch to read all the entries from the producer..."
    321  1.1  lukem $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD  \
    322  1.1  lukem 	'objectclass=*' > $MASTEROUT 2>&1
    323  1.1  lukem RC=$?
    324  1.1  lukem 
    325  1.1  lukem if test $RC != 0 ; then
    326  1.1  lukem 	echo "ldapsearch failed at producer ($RC)!"
    327  1.1  lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    328  1.1  lukem 	exit $RC
    329  1.1  lukem fi
    330  1.1  lukem 
    331  1.1  lukem echo "Using ldapsearch to read all the entries from the consumer..."
    332  1.1  lukem $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD  \
    333  1.1  lukem 	'objectclass=*' > $SLAVEOUT 2>&1
    334  1.1  lukem RC=$?
    335  1.1  lukem 
    336  1.1  lukem if test $RC != 0 ; then
    337  1.1  lukem 	echo "ldapsearch failed at consumer ($RC)!"
    338  1.1  lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    339  1.1  lukem 	exit $RC
    340  1.1  lukem fi
    341  1.1  lukem 
    342  1.1  lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
    343  1.1  lukem 
    344  1.1  lukem echo "Filtering producer results..."
    345  1.1  lukem . $LDIFFILTER < $MASTEROUT > $MASTERFLT
    346  1.1  lukem echo "Filtering consumer results..."
    347  1.1  lukem . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
    348  1.1  lukem 
    349  1.1  lukem echo "Comparing retrieved entries from producer and consumer..."
    350  1.1  lukem $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
    351  1.1  lukem 
    352  1.1  lukem if test $? != 0 ; then
    353  1.1  lukem 	echo "test failed - producer and consumer databases differ"
    354  1.1  lukem 	exit 1
    355  1.1  lukem fi
    356  1.1  lukem 
    357  1.1  lukem echo ">>>>> Test succeeded"
    358  1.1  lukem 
    359  1.1  lukem test $KILLSERVERS != no && wait
    360  1.1  lukem 
    361  1.1  lukem exit 0
    362