run_resperf.sh.j2 2.67 KB
Newer Older
1 2 3 4 5
#!/bin/bash
set -o xtrace

JOBNAME=j$1.$2

6 7 8 9 10 11 12
exit_handler() {
    exitcode=$?
    docker-compose --no-ansi rm -fsv || :
    echo "$exitcode" > ${JOBNAME}_exitcode
}
trap exit_handler EXIT

13 14 15
# HACK (condor): ensure files for transfer exist to avoid held jobs
touch ${JOBNAME}_kresd.docker.txt
touch ${JOBNAME}_resperf.txt
16
echo '1' > ${JOBNAME}_exitcode  # failed unless job exits with 0
17 18 19 20 21
mkdir logs
tar -czf ${JOBNAME}_logs.tar.gz -T /dev/null  # empty tar by default

# HACK (condor): Create proper dir structure
mkdir -p docker-knot-resolver || :
22
mv -t docker-knot-resolver/ Dockerfile kresd.entrypoint.sh || :
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

# HACK (condor): set PATH, otherwise docker-compose exec will fail
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Check no other docker containers are running
if [ -n "$(docker ps -q)" ]; then
    echo "ERROR: running docker containers detected" >&2
    exit 2
fi

# Exit if any cmd fails from now on.
set -o errexit

# Prepare ssh key for knot-resolver-security
set +o xtrace
SSH_PRIVATE_KEY=$(cat </home/respdiff/.ssh/knot_resolver_security.id_rsa || :)
export SSH_PRIVATE_KEY
set -o xtrace

# Attempt to build containers (to have stdout/err logs in case of failure)
export KNOT_BRANCH={{ knot_branch }}
time docker-compose --no-ansi up --no-start

# Run resperf test repeatedly
for i in $(seq 3); do
    set +o xtrace
    echo "Waiting for ports..."
    # Ensure ports are empty, so we're not testing something else!
    MAX_RETRIES=30  # x5s
    {% for resolver in resolvers.values() -%}
    retries=0
    {% if resolver['port'] %}
    while [ ! -z "$(ss --all --no-header '( dport = :{{ resolver["port"] }} or sport = :{{ resolver["port"] }} )')" ]; do
        retries=$((retries+1))
        if (( $retries > $MAX_RETRIES )); then
            echo "ERROR: port {{ resolver['port'] }} not availble" >&2
            exit 2
        fi
        sleep 5
    done
    {% endif %}
    {% if resolver['tls_port'] %}
    retries=0
    while [ ! -z "$(ss --all --no-header '( dport = :{{ resolver["tls_port"] }} or sport = :{{ resolver["tls_port"] }} )')" ]; do
        retries=$((retries+1))
        if (( $retries > $MAX_RETRIES )); then
            echo "ERROR: port {{ resolver['tls_port'] }} not availble" >&2
            exit 2
        fi
        sleep 5
    done
    {% endif %}
    {% endfor %}
    set -o xtrace

    # Execute resperf
    docker-compose --no-ansi up -d
    docker-compose --no-ansi exec -T resperf resperf -q 500000 -m 10000 -C 200 -c 30 -d shortlist -t 15 -r 0 -s 127.0.0.1 -p {{ resperf['port'] }} &>>${JOBNAME}_resperf.txt
    docker-compose --no-ansi logs &>>${JOBNAME}_kresd.docker.txt
    docker-compose --no-ansi ps | (! grep Exit)
    docker-compose --no-ansi kill
done