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

JOBNAME=j$1.$2

# HACK (condor): ensure files for transfer exist to avoid held jobs
7 8
touch ${JOBNAME}_report{,.diffrepro}.json
touch ${JOBNAME}_report{,.diffrepro}.txt
9
touch ${JOBNAME}_histogram.png
10 11
mkdir logs
tar -czf ${JOBNAME}_logs.tar.gz -T /dev/null  # empty tar by default
12 13 14 15 16 17 18

# HACK (condor): Create proper dir structure
mkdir -p docker-knot-resolver || :
mv Dockerfile docker-knot-resolver/ || :

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

# Ensure ports are empty, so we're not testing something else!
24 25
set +o xtrace
echo "Waiting for ports..."
26 27 28 29
MAX_RETRIES=60
{% for resolver in resolvers.values() -%}
retries=0
{% if resolver['port'] %}
30
while [ ! -z "$(ss --all --no-header '( dport = :{{ resolver["port"] }} or sport = :{{ resolver["port"] }} )')" ]; do
31 32 33 34 35 36
    retries=$((retries+1))
    if (( $retries > $MAX_RETRIES )); then
        echo "ERROR: port {{ resolver['port'] }} not availble" >&2
        exit 2
    fi
    sleep 1
37 38 39 40
done
{% endif %}
{% if resolver['tls_port'] %}
retries=0
41
while [ ! -z "$(ss --all --no-header '( dport = :{{ resolver["tls_port"] }} or sport = :{{ resolver["tls_port"] }} )')" ]; do
42 43 44 45 46 47
    retries=$((retries+1))
    if (( $retries > $MAX_RETRIES )); then
        echo "ERROR: port {{ resolver['tls_port'] }} not availble" >&2
        exit 2
    fi
    sleep 1
48 49 50
done
{% endif %}
{% endfor %}
51
set -o xtrace
52 53 54 55 56

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

cleanup() {
57
    docker-compose --no-ansi rm -fsv || :
58
    tar --use-compress-program=pigz -cf ${JOBNAME}_logs.tar.gz logs &>/dev/null || :
59
{%if database['remove_after'] %}
60
    rm -rf ./*.mdb || :
61
{% endif %}
62
    exit 0
63 64 65 66 67 68
}
trap cleanup ERR EXIT

# Get database
wget --quiet -O {{ database['dest'] }} {{ database['url'] }}

69 70 71 72 73 74
# 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

75
# Attempt to build containers (to have stdout/err logs in case of failure)
76
export KNOT_BRANCH={{ knot_branch }}
77
time docker-compose --no-ansi up --no-start >&2
78 79 80 81 82
# Start and wait for resolvers to be available
./restart-all.sh

# Run respdiff toolchain
time "{{ respdiff['srcdir'] }}/orchestrator.py" .
83
docker-compose --no-ansi stop  # give lingering connections time to close
84
time "{{ respdiff['srcdir'] }}/msgdiff.py" -d ${JOBNAME}_report.json .
85
cp ${JOBNAME}_report{,.diffrepro}.json
86 87
time "{{ respdiff['srcdir'] }}/diffrepro.py" -d ${JOBNAME}_report.diffrepro.json .
time "{{ respdiff['srcdir'] }}/diffsum.py" --without-diffrepro -d ${JOBNAME}_report.json . > ${JOBNAME}_report.txt
88
time "{{ respdiff['srcdir'] }}/diffsum.py" -d ${JOBNAME}_report.diffrepro.json . > ${JOBNAME}_report.diffrepro.txt
89
time "{{ respdiff['srcdir'] }}/histogram.py" -o ${JOBNAME}_histogram.png .