diff --git a/docker/Dockerfile.debian.testing b/docker/Dockerfile.debian.testing index d9437994ca..462f71474a 100644 --- a/docker/Dockerfile.debian.testing +++ b/docker/Dockerfile.debian.testing @@ -49,6 +49,7 @@ RUN apt-get update && apt-get -y install \ libtool \ lshw \ make \ + net-tools \ opensc \ pkg-config \ psmisc \ diff --git a/docker/Dockerfile.ubuntu.bionic b/docker/Dockerfile.ubuntu.bionic index 8838ff3070..9f62bd5309 100644 --- a/docker/Dockerfile.ubuntu.bionic +++ b/docker/Dockerfile.ubuntu.bionic @@ -48,6 +48,7 @@ RUN apt-get update && apt-get -y install \ lshw \ make \ opensc \ + net-tools \ pkg-config \ psmisc \ python3-dev \ diff --git a/docker/Dockerfile.ubuntu.xenial b/docker/Dockerfile.ubuntu.xenial index 132ef6d6bf..fd046fd31b 100644 --- a/docker/Dockerfile.ubuntu.xenial +++ b/docker/Dockerfile.ubuntu.xenial @@ -45,6 +45,7 @@ RUN apt-get update && apt-get -y install \ libtool \ lshw \ make \ + net-tools \ opensc \ pkg-config \ psmisc \ diff --git a/scripts/make_ostree_sysroot.sh b/scripts/make_ostree_sysroot.sh index ba6c300e3a..94033cfc8b 100755 --- a/scripts/make_ostree_sysroot.sh +++ b/scripts/make_ostree_sysroot.sh @@ -8,8 +8,7 @@ fi SCRIPT="${1}/tests/ostree-scripts/makephysical.sh" REPO="${2}/ostree_repo" -PORT=$("${1}/tests/get_open_port.py") if [ ! -d "${REPO}" ]; then - "${SCRIPT}" "${REPO}" ${PORT} + "${SCRIPT}" "${REPO}" fi diff --git a/src/aktualizr_lite/test_lite.sh b/src/aktualizr_lite/test_lite.sh index c716c35441..cea0f9f64b 100755 --- a/src/aktualizr_lite/test_lite.sh +++ b/src/aktualizr_lite/test_lite.sh @@ -7,7 +7,6 @@ akrepo_bin=$2 tests_dir=$3 #valgrind=$4 valgrind="" -port=$($tests_dir/get_open_port.py) dest_dir=$(mktemp -d) @@ -49,10 +48,10 @@ add_target foo2 akrepo --command signtargets pushd $dest_dir -python3 -m http.server $port & +python3 -m http.server 0& pid=$! - -# curl http://localhost:$port/repo/image/targets.json | json_pp +port=$("$tests_dir/find_listening_port.sh" "$pid") +echo "http server listening on $port" export OSTREE_SYSROOT=$dest_dir/sysroot mkdir $OSTREE_SYSROOT diff --git a/src/libaktualizr/primary/aktualizr_test.cc b/src/libaktualizr/primary/aktualizr_test.cc index cb905e82d3..2828e424a1 100644 --- a/src/libaktualizr/primary/aktualizr_test.cc +++ b/src/libaktualizr/primary/aktualizr_test.cc @@ -635,7 +635,7 @@ TEST(Aktualizr, FinalizationFailure) { EXPECT_EQ(current_version, SIZE_MAX); auto aktualizr_cycle_thread = aktualizr.RunForever(); - auto aktualizr_cycle_thread_status = aktualizr_cycle_thread.wait_for(std::chrono::seconds(10)); + auto aktualizr_cycle_thread_status = aktualizr_cycle_thread.wait_for(std::chrono::seconds(20)); ASSERT_EQ(aktualizr_cycle_thread_status, std::future_status::ready); EXPECT_TRUE(aktualizr.uptane_client_->bootloader->rebootDetected()); @@ -931,7 +931,7 @@ TEST(Aktualizr, AutoRebootAfterUpdate) { aktualizr.Initialize(); auto aktualizr_cycle_thread = aktualizr.RunForever(); - auto aktualizr_cycle_thread_status = aktualizr_cycle_thread.wait_for(std::chrono::seconds(10)); + auto aktualizr_cycle_thread_status = aktualizr_cycle_thread.wait_for(std::chrono::seconds(20)); EXPECT_EQ(aktualizr_cycle_thread_status, std::future_status::ready); EXPECT_TRUE(aktualizr.uptane_client_->bootloader->rebootDetected()); diff --git a/tests/find_listening_port.sh b/tests/find_listening_port.sh new file mode 100755 index 0000000000..c0fbbb995b --- /dev/null +++ b/tests/find_listening_port.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# returns the tcp port a server application listens to +# dependency: netstat (net-tools) + +pid=$1 + +port= +try=0 +while [[ -z $port && $try -le 100 ]]; do + port=$(netstat -lpan 2> /dev/null | awk -F '[ :]+' "/$pid\\/python3/ {print \$5}") + sleep 0.2 + try=$((try+1)) +done +echo "$port" diff --git a/tests/get_open_port.py b/tests/get_open_port.py deleted file mode 100755 index b6e2fc92b8..0000000000 --- a/tests/get_open_port.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -import socket - - -def main(): - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - s.bind(('127.0.0.1', 0)) - port = s.getsockname()[1] - print(port) - s.close() - - -if __name__ == '__main__': - main() diff --git a/tests/ostree-scripts/makephysical.sh b/tests/ostree-scripts/makephysical.sh index 58a5ec0298..493a60bb37 100755 --- a/tests/ostree-scripts/makephysical.sh +++ b/tests/ostree-scripts/makephysical.sh @@ -18,7 +18,7 @@ rm -rf "$OSTREE_SYSROOT" mkdir -p "$OSTREE_SYSROOT" ostree admin init-fs "$OSTREE_SYSROOT" ostree admin os-init $OSNAME -ostree config --repo=${OSTREE_SYSROOT}/ostree/repo set core.mode bare-user-only +ostree config --repo="${OSTREE_SYSROOT}/ostree/repo" set core.mode bare-user-only mkdir -p "$OSTREE_SYSROOT/boot/loader.0" ln -s loader.0 "$OSTREE_SYSROOT/boot/loader" @@ -29,25 +29,19 @@ SCRIPT_DIR="$(dirname "$0")" OSTREE_DIR=$(mktemp -d /tmp/ostreephys-XXXXXX) "$SCRIPT_DIR/makedeployed.sh" "$OSTREE_DIR/repo" $BRANCHNAME $HARDWARE -if [ "$#" -eq 2 ]; then - echo "port: $2" - PORT=$2 -else - PORT=56042 -fi - ( cd "$OSTREE_DIR/repo" - python3 -m http.server $PORT & + python3 -m http.server 0 & + PORT=$("$SCRIPT_DIR/../find_listening_port.sh" $!) trap 'kill %1' EXIT + # Wait for http server to start serving. This can take a while sometimes. - until curl 127.0.0.1:$PORT &> /dev/null - do + until curl 127.0.0.1:"$PORT" &> /dev/null; do sleep 0.2 done - ostree --repo="$OSTREE_SYSROOT/ostree/repo" remote add --no-gpg-verify generate-remote http://127.0.0.1:$PORT $BRANCHNAME + ostree --repo="$OSTREE_SYSROOT/ostree/repo" remote add --no-gpg-verify generate-remote "http://127.0.0.1:$PORT" $BRANCHNAME ostree --repo="$OSTREE_SYSROOT/ostree/repo" pull generate-remote $BRANCHNAME ) diff --git a/tests/run_vector_tests.sh b/tests/run_vector_tests.sh index ac4f2bfc5d..b2fac9214c 100755 --- a/tests/run_vector_tests.sh +++ b/tests/run_vector_tests.sh @@ -23,15 +23,15 @@ TTV_DIR="$TESTS_SRC_DIR/tuf-test-vectors" python -m pip install wheel python -m pip install -r "$TTV_DIR/requirements.txt" -PORT=$("$TESTS_SRC_DIR/get_open_port.py") ECU_SERIAL=test_primary_ecu_serial HARDWARE_ID=test_primary_hardware_id "$TTV_DIR/generator.py" --signature-encoding base64 -o vectors --cjson json-subset \ --ecu-identifier $ECU_SERIAL --hardware-id $HARDWARE_ID # disable werkzeug debug pin which causes issues on Jenkins -WERKZEUG_DEBUG_PIN=off "$TTV_DIR/server.py" --signature-encoding base64 -P "$PORT" \ +WERKZEUG_DEBUG_PIN=off "$TTV_DIR/server.py" --signature-encoding base64 -P 0 \ --ecu-identifier $ECU_SERIAL --hardware-id $HARDWARE_ID & +PORT=$("$TESTS_SRC_DIR/find_listening_port.sh" $!) trap 'kill %1' EXIT # wait for server to go up