Home | History | Annotate | Line # | Download | only in scripts
test043-delta-syncrepl revision 1.1.1.9
      1 #! /bin/sh
      2 # $OpenLDAP$
      3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4 ##
      5 ## Copyright 1998-2021 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"
     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 < $DSRPROVIDERCONF > $CONF1
     49 $SLAPD -f $CONF1 -h $URI1 -d $LVL > $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 $URI1 \
     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 $URI1 -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 < $DSRCONSUMERCONF > $CONF2
     89 $SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
     90 CONSUMERPID=$!
     91 if test $WAIT != 0 ; then
     92     echo CONSUMERPID $CONSUMERPID
     93     read foo
     94 fi
     95 KILLPIDS="$KILLPIDS $CONSUMERPID"
     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 $URI2 \
    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 $URI1 -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 >> $LOG1 2>&1 &
    135 PID=$!
    136 if test $WAIT != 0 ; then
    137     echo PID $PID
    138     read foo
    139 fi
    140 KILLPIDS="$PID $CONSUMERPID"
    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 $URI1 \
    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 $URI1 -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 add: displayName
    182 displayName: The one
    183 
    184 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
    185 changetype: modify
    186 add: displayName
    187 displayName: James the First
    188 -
    189 delete: displayName
    190 displayName: The one
    191 
    192 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
    193 changetype: modify
    194 replace: drink
    195 drink: Iced Tea
    196 
    197 dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
    198 changetype: modify
    199 delete: uniquemember
    200 uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
    201 uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
    202 -
    203 add: uniquemember
    204 uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
    205 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
    206 
    207 dn: cn=All Staff,ou=Groups,dc=example,dc=com
    208 changetype: modify
    209 delete: description
    210 
    211 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
    212 changetype: add
    213 objectclass: OpenLDAPperson
    214 cn: Gern Jensen
    215 sn: Jensen
    216 uid: gjensen
    217 title: Chief Investigator, ITD
    218 postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
    219 seealso: cn=All Staff, ou=Groups, dc=example,dc=com
    220 drink: Coffee
    221 homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
    222 description: Very odd
    223 facsimiletelephonenumber: +1 313 555 7557
    224 telephonenumber: +1 313 555 8343
    225 mail: gjensen@mailgw.example.com
    226 homephone: +1 313 555 8844
    227 
    228 dn: ou=Retired, ou=People, dc=example,dc=com
    229 changetype: add
    230 objectclass: organizationalUnit
    231 ou: Retired
    232 
    233 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
    234 changetype: add
    235 objectclass: OpenLDAPperson
    236 cn: Rosco P. Coltrane
    237 sn: Coltrane
    238 uid: rosco
    239 description: Fat tycoon
    240 
    241 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
    242 changetype: modrdn
    243 newrdn: cn=Rosco P. Coltrane
    244 deleteoldrdn: 1
    245 newsuperior: ou=Retired, ou=People, dc=example,dc=com
    246 
    247 dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
    248 changetype: delete
    249 
    250 EOMODS
    251 RC=$?
    252 if test $RC != 0 ; then
    253 	echo "ldapmodify failed ($RC)!"
    254 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    255 	exit $RC
    256 fi
    257 
    258 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    259 sleep $SLEEP1
    260 
    261 echo "Using ldapsearch to read all the entries from the provider..."
    262 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
    263 	'objectclass=*' \* + > $PROVIDEROUT 2>&1
    264 RC=$?
    265 
    266 if test $RC != 0 ; then
    267 	echo "ldapsearch failed at provider ($RC)!"
    268 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    269 	exit $RC
    270 fi
    271 
    272 echo "Using ldapsearch to read all the entries from the consumer..."
    273 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI2 \
    274 	'objectclass=*' \* + > $CONSUMEROUT 2>&1
    275 RC=$?
    276 
    277 if test $RC != 0 ; then
    278 	echo "ldapsearch failed at consumer ($RC)!"
    279 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    280 	exit $RC
    281 fi
    282 
    283 echo "Filtering provider results..."
    284 $LDIFFILTER -b $BACKEND -s $SPEC < $PROVIDEROUT | grep -iv "^auditcontext:" > $PROVIDERFLT
    285 echo "Filtering consumer results..."
    286 $LDIFFILTER -b $BACKEND -s $SPEC < $CONSUMEROUT | grep -iv "^auditcontext:" > $CONSUMERFLT
    287 
    288 echo "Comparing retrieved entries from provider and consumer..."
    289 $CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT
    290 
    291 if test $? != 0 ; then
    292 	echo "test failed - provider and consumer databases differ"
    293 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    294 	exit 1
    295 fi
    296 
    297 echo "Stopping consumer to test recovery..."
    298 kill -HUP $CONSUMERPID
    299 sleep 10
    300 
    301 echo "Modifying more entries on the provider..."
    302 $LDAPMODIFY -v -D "$BJORNSDN" -H $URI1 -w bjorn >> \
    303 	$TESTOUT 2>&1 << EOMODS
    304 dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
    305 changetype: delete
    306 
    307 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
    308 changetype: modify
    309 add: drink
    310 drink: Mad Dog 20/20
    311 
    312 dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com
    313 changetype: add
    314 objectclass: OpenLDAPperson
    315 sn: Coltrane
    316 uid: rosco
    317 cn: Rosco P. Coltrane
    318 
    319 dn: cn=Mark Elliot,ou=Alumni Association,ou=People,dc=example,dc=com
    320 changetype: modify
    321 replace: drink
    322 drink: Red Wine
    323 -
    324 replace: drink
    325 
    326 dn: cn=All Staff,ou=Groups,dc=example,dc=com
    327 changetype: modrdn
    328 newrdn: cn=Some Staff
    329 deleteoldrdn: 1
    330 
    331 EOMODS
    332 
    333 echo "Restarting consumer..."
    334 echo "RESTART" >> $LOG2
    335 $SLAPD -f $CONF2 -h $URI2 -d $LVL >> $LOG2 2>&1 &
    336 CONSUMERPID=$!
    337 if test $WAIT != 0 ; then
    338     echo CONSUMERPID $CONSUMERPID
    339     read foo
    340 fi
    341 KILLPIDS="$PID $CONSUMERPID"
    342 
    343 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    344 sleep $SLEEP1
    345 
    346 if test ! $BACKLDAP = "ldapno" ; then
    347 	echo "Try updating the consumer slapd..."
    348 	$LDAPMODIFY -v -D "$MANAGERDN" -H $URI2 -w $PASSWD > \
    349 		$TESTOUT 2>&1 << EOMODS
    350 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
    351 changetype: modify
    352 add: description
    353 description: This write must fail because directed to a shadow context,
    354 description: unless the chain overlay is configured appropriately ;)
    355 
    356 EOMODS
    357 
    358 	RC=$?
    359 	if test $RC != 0 ; then
    360 		echo "ldapmodify failed ($RC)!"
    361 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
    362 		exit $RC
    363 	fi
    364 
    365 	echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    366 	sleep $SLEEP1
    367 fi
    368 
    369 echo "Using ldapsearch to read all the entries from the provider..."
    370 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
    371 	'objectclass=*' \* + > $PROVIDEROUT 2>&1
    372 RC=$?
    373 
    374 if test $RC != 0 ; then
    375 	echo "ldapsearch failed at provider ($RC)!"
    376 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    377 	exit $RC
    378 fi
    379 
    380 echo "Using ldapsearch to read all the entries from the consumer..."
    381 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI2 \
    382 	'objectclass=*' \* + > $CONSUMEROUT 2>&1
    383 RC=$?
    384 
    385 if test $RC != 0 ; then
    386 	echo "ldapsearch failed at consumer ($RC)!"
    387 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    388 	exit $RC
    389 fi
    390 
    391 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    392 
    393 echo "Filtering provider results..."
    394 $LDIFFILTER -b $BACKEND -s $SPEC < $PROVIDEROUT | grep -iv "^auditcontext:" > $PROVIDERFLT
    395 echo "Filtering consumer results..."
    396 $LDIFFILTER -b $BACKEND -s $SPEC < $CONSUMEROUT | grep -iv "^auditcontext:" > $CONSUMERFLT
    397 
    398 echo "Comparing retrieved entries from provider and consumer..."
    399 $CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT
    400 
    401 if test $? != 0 ; then
    402 	echo "test failed - provider and consumer databases differ"
    403 	exit 1
    404 fi
    405 
    406 echo ">>>>> Test succeeded"
    407 
    408 test $KILLSERVERS != no && wait
    409 
    410 exit 0
    411