From 24fcc0c0ff8180e78deba7bc41604df588949875 Mon Sep 17 00:00:00 2001 From: Nadav Har'El Date: Sun, 12 Apr 2020 16:06:39 +0300 Subject: [PATCH] alternator-test: change "run" script to pick random IP address Before this patch, the Alternator tests "run" script ran Scylla on a fixed listening address, 127.0.0.1. There is a problem that there might be other concurrent runs of Scylla using the same IP address - e.g., CCM (used by dtest) uses exactly this IP address for its first node. Luckily, Linux's loopback device actually allows us to pick any of over a million addresses in 127.0.0.0/8 to listen on - we don't need to use 127.0.0.1 specifically. So the code in this patch picks an address in 127.1.*.*, so it cannot collide with CCM (which uses 127.0.0.* for up to 255 nodes). Moreover, the last two bytes of the listen address are picked based on the process ID of the run script; This allows multiple copies of this script to run concurrently - in case anybody wishes to do that. Signed-off-by: Nadav Har'El --- alternator-test/run | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/alternator-test/run b/alternator-test/run index 6b3aacbc2a..a047d16eab 100755 --- a/alternator-test/run +++ b/alternator-test/run @@ -8,7 +8,6 @@ script_path=$(dirname $(readlink -e $0)) # By default, we take the latest build/*/scylla as the executable: SCYLLA=${SCYLLA-$(ls -t "$script_path/../build/"*"/scylla" | head -1)} SCYLLA=$(readlink -f "$SCYLLA") -SCYLLA_IP=${IP-127.0.0.1} CPUSET=${CPUSET-0} # Below, we need to use python3 and the Cassandra drive to set up the @@ -21,6 +20,14 @@ then exit 1 fi +# Pick a loopback IP address for Scylla to run, in an attempt not to collide +# other concurrent runs of Scylla. CCM uses 127.0.0., so if we use +# 127.1.*.* which cannot collide with it. Moreover, we'll take the last two +# bytes of the address from the current process - so as to allow multiple +# concurrent runs of this code to use a different address. +SCYLLA_IP=127.1.$(($$ >> 8 & 255)).$(($$ & 255)) +echo "Running Scylla on $SCYLLA_IP" + tmp_dir=/tmp/alternator-test-$$ mkdir $tmp_dir @@ -51,6 +58,7 @@ trap 'cleanup' EXIT # to work. We only need to do this if the "--https" option was explicitly # passed - otherwise the test would not use HTTPS anyway. alternator_port_option="--alternator-port=8000" +alternator_url="http://$SCYLLA_IP:8000" for i do if [ "$i" = --https ] @@ -58,17 +66,20 @@ do openssl genrsa 2048 > "$tmp_dir/scylla.key" openssl req -new -x509 -nodes -sha256 -days 365 -subj "/C=IL/ST=None/L=None/O=None/OU=None/CN=example.com" -key "$tmp_dir/scylla.key" -out "$tmp_dir/scylla.crt" alternator_port_option="--alternator-https-port=8043" + alternator_url="https://$SCYLLA_IP:8043" fi done -"$SCYLLA" --options-file "$script_path/../conf/scylla.yaml" \ - --alternator-address $SCYLLA_IP \ +"$SCYLLA" --options-file "$source_path/conf/scylla.yaml" \ + --alternator-address $SCYLLA_IP \ $alternator_port_option \ --alternator-enforce-authorization=1 \ --developer-mode=1 \ --ring-delay-ms 0 --collectd 0 \ --cpuset "$CPUSET" -m 1G \ - --api-address $SCYLLA_IP --rpc-address $SCYLLA_IP \ + --api-address $SCYLLA_IP \ + --rpc-address $SCYLLA_IP \ --listen-address $SCYLLA_IP \ + --prometheus-address $SCYLLA_IP \ --seed-provider-parameters seeds=$SCYLLA_IP \ --workdir "$tmp_dir" \ --server-encryption-options keyfile="$tmp_dir/scylla.key" \ @@ -81,7 +92,7 @@ SCYLLA_PROCESS=$! # test. This requires connecting to Scylla with CQL - we'll wait up for # one minute for this to work: setup_authentication() { - python3 -c 'from cassandra.cluster import Cluster; Cluster().connect().execute("INSERT INTO system_auth.roles (role, salted_hash) VALUES ('\''alternator'\'', '\''secret_pass'\'')")' + python3 -c 'from cassandra.cluster import Cluster; Cluster(["'$SCYLLA_IP'"]).connect().execute("INSERT INTO system_auth.roles (role, salted_hash) VALUES ('\''alternator'\'', '\''secret_pass'\'')")' } echo "Scylla is: $SCYLLA." echo -n "Booting Scylla..." @@ -127,7 +138,8 @@ else fi cd "$script_path" -pytest "$@" +set +e +pytest --url $alternator_url "$@" code=$? case $code in 0) summary="Alternator tests pass";;