]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
testing: Use an on-guest script to cleanup/initialize and run them in parallel
authorTobias Brunner <tobias@strongswan.org>
Fri, 29 Nov 2024 17:15:58 +0000 (18:15 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 3 Dec 2024 07:43:45 +0000 (08:43 +0100)
This is a bit quicker than doing this with separate SSH calls for each
host sequentially (up to half a second per test).

testing/do-tests
testing/hosts/default/usr/local/bin/init-test [new file with mode: 0755]

index 986c1296ba3a6ebed46822e0d6d7edcc2de71e5c..52dacba520c9949a7faef3c383c6c3fccf494936 100755 (executable)
@@ -43,6 +43,8 @@ DEFAULTTESTSDIR=$TESTDIR/testing/tests
 
 SOURCEIP_ROUTING_TABLE=220
 
+export LEAK_DETECTIVE_LOG=/var/log/leak-detective.log
+
 testnumber="0"
 failed_cnt="0"
 passed_cnt="0"
@@ -337,69 +339,41 @@ do
 
 
        ##########################################################################
-       # run tcpdump in the background
+       # clean up and initialize test hosts
        #
 
-       if [ "$TCPDUMPHOSTS" != "" ]
-       then
-           echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
-
-           for host_iface in $TCPDUMPHOSTS
-           do
-               host=`echo $host_iface | awk -F ":" '{print $1}'`
-               iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
-               tcpdump_cmd="tcpdump -l --immediate-mode -i $iface not port ssh and not port domain >/tmp/tcpdump.log 2>/tmp/tcpdump.err.log &"
-               echo "$(print_time)${host}# $tcpdump_cmd" >> $CONSOLE_LOG
-               ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
-               eval TDUP_${host}="true"
-           done
-       fi
-
-       ##########################################################################
-       # create database directory in RAM
-       #
+       declare -A INIT_OPTIONS=()
 
-       for host in $DBHOSTS
+       for host in $TCPDUMPHOSTS
        do
-               eval HOSTLOGIN=root@\$ipv4_${host}
-           ssh $SSHCONF $HOSTLOGIN "mkdir -p $DBDIR; mount -t ramfs -o size=5m ramfs $DBDIR" >/dev/null 2>&1
-           ssh $SSHCONF $HOSTLOGIN "chgrp www-data $DBDIR; chmod g+w $DBDIR" >/dev/null 2>&1
+               # all hosts currently capture on eth0
+               INIT_OPTIONS[${host}]="${INIT_OPTIONS[${host}]} -i eth0"
+               eval TDUP_${host}="true"
        done
 
-       ##########################################################################
-       # flush conntrack table on all hosts
-       #
-
-       for host in $STRONGSWANHOSTS
+       for host in $DBHOSTS
        do
-               ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'conntrack -F' >/dev/null 2>&1
+               INIT_OPTIONS[${host}]="${INIT_OPTIONS[${host}]} -d $DBDIR"
        done
 
-       ##########################################################################
-       # remove leak detective log on all hosts
-       #
+       # initialize hosts in parallel
+       WAIT_FOR=()
 
-       export LEAK_DETECTIVE_LOG=/var/log/leak-detective.log
        for host in $STRONGSWANHOSTS
        do
-               ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'rm -f $LEAK_DETECTIVE_LOG' >/dev/null 2>&1
+               eval HOSTLOGIN=root@\$ipv4_${host}
+               ssh $SSHCONF $HOSTLOGIN /usr/local/bin/init-test ${INIT_OPTIONS[${host}]} &
+               WAIT_FOR+=($!)
        done
 
-       ##########################################################################
-       # flush IPsec state on all hosts
-       #
-
-       for host in $STRONGSWANHOSTS
-       do
-               ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'ip xfrm state flush; ip xfrm policy flush' >/dev/null 2>&1
-       done
+       wait ${WAIT_FOR[@]}
 
        ##########################################################################
        # execute pre-test commands
        #
 
        echo -n "pre.."
-       echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
+       echo -e "PRE-TEST\n" >> $CONSOLE_LOG 2>&1
 
        eval `awk -F "::" '{
                if ($0 ~ /^#.*/)
diff --git a/testing/hosts/default/usr/local/bin/init-test b/testing/hosts/default/usr/local/bin/init-test
new file mode 100755 (executable)
index 0000000..a9886a9
--- /dev/null
@@ -0,0 +1,38 @@
+#! /bin/bash
+
+while getopts "i:d:" opt
+do
+       case "$opt" in
+       i)
+               INTERFACE=${OPTARG}
+               ;;
+       d)
+               DB=${OPTARG}
+       esac
+done
+shift $((OPTIND-1))
+
+# start tcpdump in the background
+if [ -n "$INTERFACE" ]
+then
+       tcpdump -l --immediate-mode -i $INTERFACE not port ssh and not port domain >/tmp/tcpdump.log 2>/tmp/tcpdump.err.log &
+fi
+
+# setup ramdisk for databases
+if [ -n "$DB" ]
+then
+       mkdir -p $DB
+       mount -t ramfs -o size=5m ramfs $DB
+       chgrp www-data $DB
+       chmod g+w $DB
+fi
+
+# flush conntrack table
+conntrack -F >/dev/null 2>&1
+
+# flush IPsec state
+ip xfrm state flush
+ip xfrm policy flush
+
+# remove leak detective log
+rm -f $LEAK_DETECTIVE_LOG