| 1 | #! /bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | # $OpenLDAP$ |
| 3 | ## This work is part of OpenLDAP Software <http://www.openldap.org/>. |
| 4 | ## |
| 5 | ## Copyright 1998-2024 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 | echoscip-shell system . . echo. "running defines.sh" |
| 17 | . $SRCDIR/scripts/defines.sh |
| 18 | |
| 19 | mkdirscip-shell system . . mkdir. -p $TESTDIR $DBDIR1 $DBDIR2 |
| 20 | |
| 21 | $SLAPPASSWD -g -n >$CONFIGPWF |
| 22 | echoscip-shell system . . echo. "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf |
| 23 | |
| 24 | if testscip-shell system . . test. $AC_lloadd = lloaddyes ; then |
| 25 | echoscip-shell system . . echo. "Load balancer module not available, skipping..." |
| 26 | exit 0 |
| 27 | fi |
| 28 | |
| 29 | # Monitor counts are unstable in the face of concurrency, since different |
| 30 | # clients may get different upstreams assigned for their operations. This might |
| 31 | # also change later when tiered load balancing is available. |
| 32 | # Another constraint is that some global counts are updated by the statistics |
| 33 | # collection task scheduled to run every second. |
| 34 | # |
| 35 | # This test assumes current round-robin policy: |
| 36 | # - default backend is rotated every time we successfully pick an upstream |
| 37 | # - upstream connections within the same backend are rotated in the same way |
| 38 | # - the monitor entry order for upstream connections reflects the connection |
| 39 | # order within its CIRCLEQ_ |
| 40 | |
| 41 | echoscip-shell system . . echo. "Starting the first slapd on TCP/IP port $PORT2..." |
| 42 | . $CONFFILTER $BACKEND < $CONF > $CONF2 |
| 43 | $SLAPADD -f $CONF2 -l $LDIFORDERED |
| 44 | RC=$? |
| 45 | if testscip-shell system . . test. $RC != 0 ; then |
| 46 | echoscip-shell system . . echo. "slapadd failed ($RC)!" |
| 47 | exit $RC |
| 48 | fi |
| 49 | |
| 50 | echoscip-shell system . . echo. "Running slapindex to index slapd database..." |
| 51 | $SLAPINDEX -f $CONF2 |
| 52 | RC=$? |
| 53 | if testscip-shell system . . test. $RC != 0 ; then |
| 54 | echoscip-shell system . . echo. "warning: slapindex failed ($RC)" |
| 55 | echoscip-shell system . . echo. " assuming no indexing support" |
| 56 | fi |
| 57 | |
| 58 | $SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 & |
| 59 | PID=$! |
| 60 | if testscip-shell system . . test. $WAIT != 0 ; then |
| 61 | echoscip-shell system . . echo. PID $PID |
| 62 | read foo |
| 63 | fi |
| 64 | PID2="$PID" |
| 65 | KILLPIDS="$PID" |
| 66 | |
| 67 | echoscip-shell system . . echo. "Testing slapd searching..." |
| 68 | for i in 0 1 2 3 4 5; do |
| 69 | $LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \ |
| 70 | '(objectclass=*)' > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 71 | RC=$? |
| 72 | if testscip-shell system . . test. $RC = 0 ; then |
| 73 | break |
| 74 | fi |
| 75 | echoscip-shell system . . echo. "Waiting $SLEEP1 seconds for slapd to start..." |
| 76 | sleepscip-shell system . . sleep. $SLEEP1 |
| 77 | done |
| 78 | if testscip-shell system . . test. $RC != 0 ; then |
| 79 | echoscip-shell system . . echo. "ldapsearch failed ($RC)!" |
| 80 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 81 | exit $RC |
| 82 | fi |
| 83 | |
| 84 | echoscip-shell system . . echo. "Running slapadd to build slapd database..." |
| 85 | . $CONFFILTER $BACKEND < $CONFTWO > $CONF3 |
| 86 | $SLAPADD -f $CONF3 -l $LDIFORDERED |
| 87 | RC=$? |
| 88 | if testscip-shell system . . test. $RC != 0 ; then |
| 89 | echoscip-shell system . . echo. "slapadd failed ($RC)!" |
| 90 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 91 | exit $RC |
| 92 | fi |
| 93 | |
| 94 | echoscip-shell system . . echo. "Running slapindex to index slapd database..." |
| 95 | $SLAPINDEX -f $CONF3 |
| 96 | RC=$? |
| 97 | if testscip-shell system . . test. $RC != 0 ; then |
| 98 | echoscip-shell system . . echo. "warning: slapindex failed ($RC)" |
| 99 | echoscip-shell system . . echo. " assuming no indexing support" |
| 100 | fi |
| 101 | |
| 102 | echoscip-shell system . . echo. "Starting second slapd on TCP/IP port $PORT3..." |
| 103 | $SLAPD -f $CONF3 -h $URI3 -d $LVL > $LOG3 2>&1 & |
| 104 | PID=$! |
| 105 | if testscip-shell system . . test. $WAIT != 0 ; then |
| 106 | echoscip-shell system . . echo. PID $PID |
| 107 | read foo |
| 108 | fi |
| 109 | PID3="$PID" |
| 110 | KILLPIDS="$KILLPIDS $PID" |
| 111 | |
| 112 | sleepscip-shell system . . sleep. $SLEEP0 |
| 113 | |
| 114 | echoscip-shell system . . echo. "Testing slapd searching..." |
| 115 | for i in 0 1 2 3 4 5; do |
| 116 | $LDAPSEARCH -s base -b "$MONITOR" -H $URI3 \ |
| 117 | '(objectclass=*)' > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 118 | RC=$? |
| 119 | if testscip-shell system . . test. $RC = 0 ; then |
| 120 | break |
| 121 | fi |
| 122 | echoscip-shell system . . echo. "Waiting $SLEEP1 seconds for slapd to start..." |
| 123 | sleepscip-shell system . . sleep. $SLEEP1 |
| 124 | done |
| 125 | if testscip-shell system . . test. $RC != 0 ; then |
| 126 | echoscip-shell system . . echo. "ldapsearch failed ($RC)!" |
| 127 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 128 | exit $RC |
| 129 | fi |
| 130 | |
| 131 | echoscip-shell system . . echo. "Starting lloadd on TCP/IP port $PORT1..." |
| 132 | . $CONFFILTER $BACKEND < $LLOADDEMPTYCONF > $CONF1.lloadd |
| 133 | . $CONFFILTER $BACKEND < $SLAPDLLOADCONF > $CONF1.slapd |
| 134 | $SLAPD -f $CONF1.slapd -h $URI6 -d $LVL > $LOG1 2>&1 & |
| 135 | PID=$! |
| 136 | if testscip-shell system . . test. $WAIT != 0 ; then |
| 137 | echoscip-shell system . . echo. PID $PID |
| 138 | read foo |
| 139 | fi |
| 140 | KILLPIDS="$KILLPIDS $PID" |
| 141 | |
| 142 | echoscip-shell system . . echo. "Testing slapd searching..." |
| 143 | for i in 0 1 2 3 4 5; do |
| 144 | $LDAPSEARCH -s base -b "$MONITOR" -H $URI6 \ |
| 145 | '(objectclass=*)' > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 146 | RC=$? |
| 147 | if testscip-shell system . . test. $RC = 0 ; then |
| 148 | break |
| 149 | fi |
| 150 | echoscip-shell system . . echo. "Waiting $SLEEP1 seconds for lloadd to start..." |
| 151 | sleepscip-shell system . . sleep. $SLEEP1 |
| 152 | done |
| 153 | |
| 154 | if testscip-shell system . . test. $RC != 0 ; then |
| 155 | echoscip-shell system . . echo. "ldapsearch failed ($RC)!" |
| 156 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 157 | exit $RC |
| 158 | fi |
| 159 | |
| 160 | echoscip-shell system . . echo. "Sending a search request to prime the counters..." |
| 161 | $LDAPSEARCH -b "$BASEDN" -s base -H $URI1 >> $TESTOUT 2>&1 |
| 162 | RC=$? |
| 163 | if testscip-shell system . . test. $RC != 52 ; then |
| 164 | echoscip-shell system . . echo. "ldapsearch should have failed ($RC != 52)!" |
| 165 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 166 | exit $RC |
| 167 | fi |
| 168 | |
| 169 | echoscip-shell system . . echo. "Retrieving data from cn=monitor..." |
| 170 | echoscip-shell system . . echo. "# Retrieving data from an empty lload's cn=monitor..." >>$SEARCHOUT |
| 171 | echoscip-shell system . . echo. "# Operations received:" >>$SEARCHOUT |
| 172 | echoscip-shell system . . echo. "# Bind: 1 (0 forwarded)" >>$SEARCHOUT |
| 173 | echoscip-shell system . . echo. "# Search: 0" >>$SEARCHOUT |
| 174 | echoscip-shell system . . echo. "# Unbind: 1" >>$SEARCHOUT |
| 175 | $LDAPSEARCH -b "cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \ |
| 176 | olmBalancer olmBalancerServer olmBalancerOperation olmBalancerConnection >> $SEARCHOUT 2>&1 |
| 177 | RC=$? |
| 178 | if testscip-shell system . . test. $RC != 0 ; then |
| 179 | echoscip-shell system . . echo. "ldapsearch failed ($RC)!" |
| 180 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 181 | exit $RC |
| 182 | fi |
| 183 | |
| 184 | echoscip-shell system . . echo. "Adding first tier..." |
| 185 | $LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1 |
| 186 | dn: cn=first,olcBackend={0}lload,cn=config |
| 187 | changetype: add |
| 188 | objectClass: olcBkLloadTierConfig |
| 189 | olcBkLloadTierType: roundrobin |
| 190 | EOF |
| 191 | RC=$? |
| 192 | if testscip-shell system . . test. $RC != 0 ; then |
| 193 | echoscip-shell system . . echo. "ldapadd failed for backend ($RC)!" |
| 194 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 195 | exit $RC |
| 196 | fi |
| 197 | |
| 198 | echoscip-shell system . . echo. "Adding first backend server..." |
| 199 | $LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1 |
| 200 | dn: cn=backend,cn={0}first,olcBackend={0}lload,cn=config |
| 201 | changetype: add |
| 202 | objectClass: olcBkLloadBackendConfig |
| 203 | olcBkLloadBackendUri: $URI2 |
| 204 | olcBkLloadMaxPendingConns: 3 |
| 205 | olcBkLloadMaxPendingOps: 5 |
| 206 | olcBkLloadRetry: 1000 |
| 207 | olcBkLloadNumconns: 2 |
| 208 | olcBkLloadBindconns: 2 |
| 209 | olcBkLloadWeight: 1 |
| 210 | EOF |
| 211 | RC=$? |
| 212 | if testscip-shell system . . test. $RC != 0 ; then |
| 213 | echoscip-shell system . . echo. "ldapadd failed for backend ($RC)!" |
| 214 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 215 | exit $RC |
| 216 | fi |
| 217 | |
| 218 | # At the moment, the global counters are updated by a recurring job, |
| 219 | # wait for it to settle |
| 220 | echoscip-shell system . . echo. "Waiting until connections are established..." |
| 221 | for i in 0 1 2 3 4 5; do |
| 222 | $LDAPCOMPARE "cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \ |
| 223 | 'olmOutgoingConnections:4' > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 224 | RC=$? |
| 225 | if testscip-shell system . . test. $RC = 6 ; then |
| 226 | break |
| 227 | fi |
| 228 | echoscip-shell system . . echo. "Waiting $SLEEP1 seconds until connections are established..." |
| 229 | sleepscip-shell system . . sleep. $SLEEP1 |
| 230 | done |
| 231 | if testscip-shell system . . test. $RC != 6 ; then |
| 232 | echoscip-shell system . . echo. "ldapcompare failed ($RC)!" |
| 233 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 234 | exit $RC |
| 235 | fi |
| 236 | |
| 237 | echoscip-shell system . . echo. "Retrieving data from cn=monitor again..." |
| 238 | echoscip-shell system . . echo. >>$SEARCHOUT |
| 239 | echoscip-shell system . . echo. "# Retrieving data from lload's cn=monitor..." >>$SEARCHOUT |
| 240 | $LDAPSEARCH -b "cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \ |
| 241 | olmBalancer olmBalancerServer olmBalancerOperation olmBalancerConnection >> $SEARCHOUT 2>&1 |
| 242 | RC=$? |
| 243 | if testscip-shell system . . test. $RC != 0 ; then |
| 244 | echoscip-shell system . . echo. "ldapsearch failed ($RC)!" |
| 245 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 246 | exit $RC |
| 247 | fi |
| 248 | |
| 249 | echoscip-shell system . . echo. "Adding another backend server..." |
| 250 | $LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1 |
| 251 | dn: cn=server 2,cn={0}first,olcBackend={0}lload,cn=config |
| 252 | changetype: add |
| 253 | objectClass: olcBkLloadBackendConfig |
| 254 | olcBkLloadBackendUri: $URI3 |
| 255 | olcBkLloadMaxPendingConns: 3 |
| 256 | olcBkLloadMaxPendingOps: 5 |
| 257 | olcBkLloadRetry: 1000 |
| 258 | olcBkLloadNumconns: 4 |
| 259 | olcBkLloadBindconns: 5 |
| 260 | olcBkLloadWeight: 1 |
| 261 | EOF |
| 262 | RC=$? |
| 263 | if testscip-shell system . . test. $RC != 0 ; then |
| 264 | echoscip-shell system . . echo. "ldapadd failed for backend ($RC)!" |
| 265 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 266 | exit $RC |
| 267 | fi |
| 268 | |
| 269 | # At the moment, the global counters are updated by a recurring job, |
| 270 | # wait for it to settle |
| 271 | echoscip-shell system . . echo. "Waiting until connections are established..." |
| 272 | for i in 0 1 2 3 4 5; do |
| 273 | $LDAPCOMPARE "cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \ |
| 274 | 'olmOutgoingConnections:13' > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 275 | RC=$? |
| 276 | if testscip-shell system . . test. $RC = 6 ; then |
| 277 | break |
| 278 | fi |
| 279 | echoscip-shell system . . echo. "Waiting $SLEEP1 seconds until connections are established..." |
| 280 | sleepscip-shell system . . sleep. $SLEEP1 |
| 281 | done |
| 282 | if testscip-shell system . . test. $RC != 6 ; then |
| 283 | echoscip-shell system . . echo. "ldapcompare failed ($RC)!" |
| 284 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 285 | exit $RC |
| 286 | fi |
| 287 | |
| 288 | echoscip-shell system . . echo. "Sending another search request..." |
| 289 | $LDAPSEARCH -b "$BASEDN" -s base -H $URI1 >> $TESTOUT 2>&1 |
| 290 | RC=$? |
| 291 | if testscip-shell system . . test. $RC != 0 ; then |
| 292 | echoscip-shell system . . echo. "ldapsearch failed ($RC)!" |
| 293 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 294 | exit $RC |
| 295 | fi |
| 296 | |
| 297 | echoscip-shell system . . echo. "Sending a WhoAmI? request..." |
| 298 | $LDAPWHOAMI -D "$BABSDN" -w bjensen -H $URI1 >> $TESTOUT 2>&1 |
| 299 | RC=$? |
| 300 | if testscip-shell system . . test. $RC != 0 ; then |
| 301 | echoscip-shell system . . echo. "ldapwhoami failed ($RC)!" |
| 302 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 303 | exit $RC |
| 304 | fi |
| 305 | |
| 306 | # At the moment, the global counters are updated by a recurring job, |
| 307 | # wait for it to settle |
| 308 | echoscip-shell system . . echo. "Waiting until global counters are updated..." |
| 309 | for i in 0 1 2 3 4 5; do |
| 310 | $LDAPCOMPARE "cn=Other,cn=Operations,cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \ |
| 311 | 'olmCompletedOps:2' > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 312 | RC=$? |
| 313 | if testscip-shell system . . test. $RC = 6 ; then |
| 314 | break |
| 315 | fi |
| 316 | echoscip-shell system . . echo. "Waiting $SLEEP1 seconds until counters are updated..." |
| 317 | sleepscip-shell system . . sleep. $SLEEP1 |
| 318 | done |
| 319 | if testscip-shell system . . test. $RC != 6 ; then |
| 320 | echoscip-shell system . . echo. "ldapcompare failed ($RC)!" |
| 321 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 322 | exit $RC |
| 323 | fi |
| 324 | |
| 325 | echoscip-shell system . . echo. "Retrieving data from cn=monitor again..." |
| 326 | echoscip-shell system . . echo. >>$SEARCHOUT |
| 327 | echoscip-shell system . . echo. "# Retrieving data after a search+WhoAmI?..." >>$SEARCHOUT |
| 328 | echoscip-shell system . . echo. "# Operations received:" >>$SEARCHOUT |
| 329 | echoscip-shell system . . echo. "# Bind: 3 (2 forwarded)" >>$SEARCHOUT |
| 330 | echoscip-shell system . . echo. "# Search: 1" >>$SEARCHOUT |
| 331 | echoscip-shell system . . echo. "# Extended: 1 (WhoAmI?)" >>$SEARCHOUT |
| 332 | echoscip-shell system . . echo. "# Unbind: 3" >>$SEARCHOUT |
| 333 | $LDAPSEARCH -b "cn=Load Balancer,cn=Backends,cn=monitor" -H $URI6 \ |
| 334 | olmBalancer olmBalancerServer olmBalancerOperation olmBalancerConnection >> $SEARCHOUT 2>&1 |
| 335 | RC=$? |
| 336 | if testscip-shell system . . test. $RC != 0 ; then |
| 337 | echoscip-shell system . . echo. "ldapsearch failed ($RC)!" |
| 338 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 339 | exit $RC |
| 340 | fi |
| 341 | |
| 342 | testscip-shell system . . test. $KILLSERVERS != no && killscip-shell system . . kill. -HUP $KILLPIDS |
| 343 | |
| 344 | LDIF=$DATADIR/lloadd/monitor.ldif |
| 345 | |
| 346 | echoscip-shell system . . echo. "Filtering ldapsearch results..." |
| 347 | $LDIFFILTER -s e < $SEARCHOUT > $SEARCHFLT |
| 348 | echoscip-shell system . . echo. "Filtering original ldif used to create database..." |
| 349 | $LDIFFILTER -s e < $LDIF | sedscip-shell system . . sed. \ |
| 350 | -e "s|@URI2@|$URI2|g" \ |
| 351 | -e "s|@URI3@|$URI3|g" \ |
| 352 | > $LDIFFLT |
| 353 | echoscip-shell system . . echo. "Comparing filter output..." |
| 354 | $CMP $SEARCHFLT $LDIFFLT > $CMPOUT |
| 355 | |
| 356 | if testscip-shell system . . test. $? != 0 ; then |
| 357 | echoscip-shell system . . echo. "Comparison failed" |
| 358 | exit 1 |
| 359 | fi |
| 360 | |
| 361 | echoscip-shell system . . echo. ">>>>> Test succeeded" |
| 362 | |
| 363 | testscip-shell system . . test. $KILLSERVERS != no && wait |
| 364 | |
| 365 | exit 0 |