Continue reservation when cleanup fails 37/18637/8
authorVratko Polak <vrpolak@cisco.com>
Tue, 18 Jun 2019 12:17:07 +0000 (14:17 +0200)
committerVratko Polak <vrpolak@cisco.com>
Tue, 18 Jun 2019 12:46:24 +0000 (12:46 +0000)
+ Only on not-failed-yet testbeds.
+ If any, else give up.

Change-Id: I3209507d3d57a77ef6afad3184ca25e098910311
Signed-off-by: Vratko Polak <vrpolak@cisco.com>
resources/libraries/bash/entry/bootstrap_verify_perf.sh
resources/libraries/bash/entry/per_patch_perf.sh
resources/libraries/bash/function/common.sh

index 0b46ff1..b9299b1 100644 (file)
@@ -42,7 +42,7 @@ check_download_dir || die
 activate_virtualenv || die
 generate_tests || die
 archive_tests || die
-reserve_testbed || die
+reserve_and_cleanup_testbed || die
 ansible_hosts "calibration" || die
 select_tags || die
 compose_pybot_arguments || die
index b5e7bb9..195d1a7 100644 (file)
@@ -56,14 +56,14 @@ select_os || die
 activate_virtualenv "${VPP_DIR}" || die
 generate_tests || die
 archive_tests || die
-reserve_testbed || die
+reserve_and_cleanup_testbed || die
 select_tags || die
 compose_pybot_arguments || die
 # Support for interleaved measurements is kept for future.
 iterations=1 # 8
 for ((iter=0; iter<iterations; iter++)); do
     if ((iter)); then
-        # Reserve testbed has already cleaned it once,
+        # Function reserve_and_cleanup_testbed has already cleaned it once,
         # but we need to clean it explicitly on subsequent iterations.
         cleanup_topo
     fi
index 810500e..6d078e5 100644 (file)
@@ -504,29 +504,35 @@ function get_test_tag_string () {
 }
 
 
-function reserve_testbed () {
+function reserve_and_cleanup_testbed () {
 
     set -exuo pipefail
 
     # Reserve physical testbed, perform cleanup, register trap to unreserve.
+    # When cleanup fails, remove from topologies and keep retrying
+    # until all topologies are removed.
     #
     # Variables read:
     # - TOPOLOGIES - Array of paths to topology yaml to attempt reservation on.
     # - PYTHON_SCRIPTS_DIR - Path to directory holding the reservation script.
     # Variables set:
+    # - TOPOLOGIES - Array of paths to topologies, with failed cleanups removed.
     # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
     # Functions called:
     # - die - Print to stderr and exit.
     # Traps registered:
     # - EXIT - Calls cancel_all for ${WORKING_TOPOLOGY}.
 
-    while true; do
+    while [[ ${TOPOLOGIES[@]} ]]; do
         for topo in "${TOPOLOGIES[@]}"; do
             set +e
             python "${PYTHON_SCRIPTS_DIR}/topo_reservation.py" -t "${topo}"
             result="$?"
             set -e
             if [[ "${result}" == "0" ]]; then
+                # Trap unreservation before cleanup check,
+                # so multiple jobs showing failed cleanup improve chances
+                # of humans to notice and fix.
                 WORKING_TOPOLOGY="${topo}"
                 echo "Reserved: ${WORKING_TOPOLOGY}"
                 trap "untrap_and_unreserve_testbed" EXIT || {
@@ -536,9 +542,28 @@ function reserve_testbed () {
                     }
                     die "Trap attempt failed, unreserve succeeded. Aborting."
                 }
-                cleanup_topo || {
-                    die "Testbed cleanup failed."
-                }
+                # Cleanup check.
+                set +e
+                cleanup_topo
+                result="$?"
+                set -e
+                if [[ "${result}" == "0" ]]; then
+                    break
+                fi
+                warn "Testbed cleanup failed: ${topo}"
+                untrap_and_unreserve_testbed "Fail of unreserve after cleanup."
+                # WORKING_TOPOLOGY is now empty again.
+                # Build new topology array.
+                #   TOPOLOGIES=("${TOPOLOGIES[@]/$topo}")
+                # does not really work, see:
+                # https://stackoverflow.com/questions/16860877/remove-an-element-from-a-bash-array
+                new_topologies=()
+                for item in "${TOPOLOGIES[@]}"; do
+                    if [[ "${item}" != "${topo}" ]]; then
+                        new_topologies+=("${item}")
+                    fi
+                done
+                TOPOLOGIES=("${new_topologies[@]}")
                 break
             fi
         done
@@ -555,6 +580,7 @@ function reserve_testbed () {
         echo "Sleeping ${sleep_time}"
         sleep "${sleep_time}" || die "Sleep failed."
     done
+    die "Run out of operational testbeds!"
 }