Home | History | Annotate | Line # | Download | only in scripts
test043-delta-syncrepl revision 1.1.1.6.6.1
      1 #! /bin/sh
      2 # $OpenLDAP$
      3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4 ##
      5 ## Copyright 1998-2019 The OpenLDAP Foundation.
      6 ## All rights reserved.
      7 ##
      8 ## Redistribution and use in source and binary forms, with or without
      9 ## modification, are permitted only as authorized by the OpenLDAP
     10 ## Public License.
     11 ##
     12 ## A copy of this license is available in the file LICENSE in the
     13 ## top-level directory of the distribution or, alternatively, at
     14 ## <http://www.OpenLDAP.org/license.html>.
     15 
     16 echo "running defines.sh"
     17 . $SRCDIR/scripts/defines.sh
     18 
     19 if test $SYNCPROV = syncprovno; then 
     20 	echo "Syncrepl provider overlay not available, test skipped"
     21 	exit 0
     22 fi 
     23 if test $ACCESSLOG = accesslogno; then 
     24 	echo "Accesslog overlay not available, test skipped"
     25 	exit 0
     26 fi 
     27 if test $BACKEND = ldif ; then
     28 	# Onelevel search does not return entries in order of creation or CSN.
     29 	echo "$BACKEND backend unsuitable for syncprov logdb, test skipped"
     30 	exit 0
     31 fi
     32 
     33 mkdir -p $TESTDIR $DBDIR1A $DBDIR1B $DBDIR2
     34 
     35 SPEC="mdb=a,bdb=a,hdb=a"
     36 
     37 #
     38 # Test replication:
     39 # - start provider
     40 # - start consumer
     41 # - populate over ldap
     42 # - perform some modifies and deleted
     43 # - attempt to modify the consumer (referral or chain)
     44 # - retrieve database over ldap and compare against expected results
     45 #
     46 
     47 echo "Starting provider slapd on TCP/IP port $PORT1..."
     48 . $CONFFILTER $BACKEND $MONITORDB < $DSRMASTERCONF > $CONF1
     49 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
     50 PID=$!
     51 if test $WAIT != 0 ; then
     52     echo PID $PID
     53     read foo
     54 fi
     55 KILLPIDS="$PID"
     56 
     57 sleep 1
     58 
     59 echo "Using ldapsearch to check that provider slapd is running..."
     60 for i in 0 1 2 3 4 5; do
     61 	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
     62 		'objectclass=*' > /dev/null 2>&1
     63 	RC=$?
     64 	if test $RC = 0 ; then
     65 		break
     66 	fi
     67 	echo "Waiting 5 seconds for slapd to start..."
     68 	sleep 5
     69 done
     70 
     71 if test $RC != 0 ; then
     72 	echo "ldapsearch failed ($RC)!"
     73 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     74 	exit $RC
     75 fi
     76 
     77 echo "Using ldapadd to create the context prefix entries in the provider..."
     78 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
     79 	$LDIFORDEREDCP > /dev/null 2>&1
     80 RC=$?
     81 if test $RC != 0 ; then
     82 	echo "ldapadd failed ($RC)!"
     83 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     84 	exit $RC
     85 fi
     86 
     87 echo "Starting consumer slapd on TCP/IP port $PORT2..."
     88 . $CONFFILTER $BACKEND $MONITORDB < $DSRSLAVECONF > $CONF2
     89 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
     90 SLAVEPID=$!
     91 if test $WAIT != 0 ; then
     92     echo SLAVEPID $SLAVEPID
     93     read foo
     94 fi
     95 KILLPIDS="$KILLPIDS $SLAVEPID"
     96 
     97 sleep 1
     98 
     99 echo "Using ldapsearch to check that consumer slapd is running..."
    100 for i in 0 1 2 3 4 5; do
    101 	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
    102 		'objectclass=*' > /dev/null 2>&1
    103 	RC=$?
    104 	if test $RC = 0 ; then
    105 		break
    106 	fi
    107 	echo "Waiting 5 seconds for slapd to start..."
    108 	sleep 5
    109 done
    110 
    111 if test $RC != 0 ; then
    112 	echo "ldapsearch failed ($RC)!"
    113 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    114 	exit $RC
    115 fi
    116 
    117 echo "Using ldapadd to populate the provider directory..."
    118 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
    119 	$LDIFORDEREDNOCP > /dev/null 2>&1
    120 RC=$?
    121 if test $RC != 0 ; then
    122 	echo "ldapadd failed ($RC)!"
    123 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    124 	exit $RC
    125 fi
    126 
    127 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    128 sleep $SLEEP1
    129 
    130 echo "Stopping the provider, sleeping 10 seconds and restarting it..."
    131 kill -HUP "$PID"
    132 sleep 10
    133 echo "RESTART" >> $LOG1
    134 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
    135 PID=$!
    136 if test $WAIT != 0 ; then
    137     echo PID $PID
    138     read foo
    139 fi
    140 KILLPIDS="$PID $SLAVEPID"
    141 
    142 sleep 1
    143 
    144 echo "Using ldapsearch to check that provider slapd is running..."
    145 for i in 0 1 2 3 4 5; do
    146 	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
    147 		'objectclass=*' > /dev/null 2>&1
    148 	RC=$?
    149 	if test $RC = 0 ; then
    150 		break
    151 	fi
    152 	echo "Waiting 5 seconds for slapd to start..."
    153 	sleep 5
    154 done
    155 
    156 if test $RC != 0 ; then
    157 	echo "ldapsearch failed ($RC)!"
    158 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    159 	exit $RC
    160 fi
    161 
    162 echo "Using ldapmodify to modify provider directory..."
    163 
    164 #
    165 # Do some modifications
    166 #
    167 
    168 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
    169 	$TESTOUT 2>&1 << EOMODS
    170 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
    171 changetype: modify
    172 add: drink
    173 drink: Orange Juice
    174 -
    175 delete: sn
    176 sn: Jones
    177 -
    178 add: sn
    179 sn: Jones
    180 
    181 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
    182 changetype: modify
    183 replace: drink
    184 drink: Iced Tea
    185 
    186 dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
    187 changetype: modify
    188 delete: uniquemember
    189 uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
    190 uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
    191 -
    192 add: uniquemember
    193 uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
    194 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
    195 
    196 dn: cn=All Staff,ou=Groups,dc=example,dc=com
    197 changetype: modify
    198 delete: description
    199 
    200 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
    201 changetype: add
    202 objectclass: OpenLDAPperson
    203 cn: Gern Jensen
    204 sn: Jensen
    205 uid: gjensen
    206 title: Chief Investigator, ITD
    207 postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
    208 seealso: cn=All Staff, ou=Groups, dc=example,dc=com
    209 drink: Coffee
    210 homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
    211 description: Very odd
    212 facsimiletelephonenumber: +1 313 555 7557
    213 telephonenumber: +1 313 555 8343
    214 mail: gjensen@mailgw.example.com
    215 homephone: +1 313 555 8844
    216 
    217 dn: ou=Retired, ou=People, dc=example,dc=com
    218 changetype: add
    219 objectclass: organizationalUnit
    220 ou: Retired
    221 
    222 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
    223 changetype: add
    224 objectclass: OpenLDAPperson
    225 cn: Rosco P. Coltrane
    226 sn: Coltrane
    227 uid: rosco
    228 description: Fat tycoon
    229 
    230 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
    231 changetype: modrdn
    232 newrdn: cn=Rosco P. Coltrane
    233 deleteoldrdn: 1
    234 newsuperior: ou=Retired, ou=People, dc=example,dc=com
    235 
    236 dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
    237 changetype: delete
    238 
    239 EOMODS
    240 RC=$?
    241 if test $RC != 0 ; then
    242 	echo "ldapmodify failed ($RC)!"
    243 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    244 	exit $RC
    245 fi
    246 
    247 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    248 sleep $SLEEP1
    249 
    250 echo "Using ldapsearch to read all the entries from the provider..."
    251 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
    252 	'objectclass=*' \* + > $MASTEROUT 2>&1
    253 RC=$?
    254 
    255 if test $RC != 0 ; then
    256 	echo "ldapsearch failed at provider ($RC)!"
    257 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    258 	exit $RC
    259 fi
    260 
    261 echo "Using ldapsearch to read all the entries from the consumer..."
    262 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
    263 	'objectclass=*' \* + > $SLAVEOUT 2>&1
    264 RC=$?
    265 
    266 if test $RC != 0 ; then
    267 	echo "ldapsearch failed at consumer ($RC)!"
    268 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    269 	exit $RC
    270 fi
    271 
    272 echo "Filtering provider results..."
    273 $LDIFFILTER -b $BACKEND -s $SPEC < $MASTEROUT | grep -iv "^auditcontext:" > $MASTERFLT
    274 echo "Filtering consumer results..."
    275 $LDIFFILTER -b $BACKEND -s $SPEC < $SLAVEOUT | grep -iv "^auditcontext:" > $SLAVEFLT
    276 
    277 echo "Comparing retrieved entries from provider and consumer..."
    278 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
    279 
    280 if test $? != 0 ; then
    281 	echo "test failed - provider and consumer databases differ"
    282 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    283 	exit 1
    284 fi
    285 
    286 echo "Stopping consumer to test recovery..."
    287 kill -HUP $SLAVEPID
    288 sleep 10
    289 
    290 echo "Modifying more entries on the provider..."
    291 $LDAPMODIFY -v -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
    292 	$TESTOUT 2>&1 << EOMODS
    293 dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
    294 changetype: delete
    295 
    296 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
    297 changetype: modify
    298 add: drink
    299 drink: Mad Dog 20/20
    300 
    301 dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
    302 changetype: add
    303 objectclass: OpenLDAPperson
    304 sn: Coltrane
    305 uid: rosco
    306 cn: Rosco P. Coltrane
    307 
    308 dn: cn=Mark Elliot,ou=Alumni Association,ou=People,dc=example,dc=com
    309 changetype: modify
    310 replace: drink
    311 drink: Red Wine
    312 -
    313 replace: drink
    314 
    315 dn: cn=All Staff,ou=Groups,dc=example,dc=com
    316 changetype: modrdn
    317 newrdn: cn=Some Staff
    318 deleteoldrdn: 1
    319 
    320 EOMODS
    321 
    322 echo "Restarting consumer..."
    323 echo "RESTART" >> $LOG2
    324 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
    325 SLAVEPID=$!
    326 if test $WAIT != 0 ; then
    327     echo SLAVEPID $SLAVEPID
    328     read foo
    329 fi
    330 KILLPIDS="$PID $SLAVEPID"
    331 
    332 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    333 sleep $SLEEP1
    334 
    335 if test ! $BACKLDAP = "ldapno" ; then
    336 	echo "Try updating the consumer slapd..."
    337 	$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
    338 		$TESTOUT 2>&1 << EOMODS
    339 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
    340 changetype: modify
    341 add: description
    342 description: This write must fail because directed to a shadow context,
    343 description: unless the chain overlay is configured appropriately ;)
    344 
    345 EOMODS
    346 
    347 	RC=$?
    348 	if test $RC != 0 ; then
    349 		echo "ldapmodify failed ($RC)!"
    350 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
    351 		exit $RC
    352 	fi
    353 
    354 	echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    355 	sleep $SLEEP1
    356 fi
    357 
    358 echo "Using ldapsearch to read all the entries from the provider..."
    359 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
    360 	'objectclass=*' \* + > $MASTEROUT 2>&1
    361 RC=$?
    362 
    363 if test $RC != 0 ; then
    364 	echo "ldapsearch failed at provider ($RC)!"
    365 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    366 	exit $RC
    367 fi
    368 
    369 echo "Using ldapsearch to read all the entries from the consumer..."
    370 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
    371 	'objectclass=*' \* + > $SLAVEOUT 2>&1
    372 RC=$?
    373 
    374 if test $RC != 0 ; then
    375 	echo "ldapsearch failed at consumer ($RC)!"
    376 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    377 	exit $RC
    378 fi
    379 
    380 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    381 
    382 echo "Filtering provider results..."
    383 $LDIFFILTER -b $BACKEND -s $SPEC < $MASTEROUT | grep -iv "^auditcontext:" > $MASTERFLT
    384 echo "Filtering consumer results..."
    385 $LDIFFILTER -b $BACKEND -s $SPEC < $SLAVEOUT | grep -iv "^auditcontext:" > $SLAVEFLT
    386 
    387 echo "Comparing retrieved entries from provider and consumer..."
    388 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
    389 
    390 if test $? != 0 ; then
    391 	echo "test failed - provider and consumer databases differ"
    392 	exit 1
    393 fi
    394 
    395 echo ">>>>> Test succeeded"
    396 
    397 test $KILLSERVERS != no && wait
    398 
    399 exit 0
    400