Prevent many TC triggered by bad tag expressions
[csit.git] / resources / libraries / bash / function / common.sh
index b38cd52..93adda7 100644 (file)
@@ -515,8 +515,8 @@ function get_test_tag_string () {
             *"device"*)
                 # On parsing error, ${trigger} stays empty.
                 trigger="$(echo "${GERRIT_EVENT_COMMENT_TEXT}" \
-                    | grep -oE '(devicetest$|devicetest[[:space:]].+$)')" \
-                    || true
+                    | grep -oE '(devicetest$|devicetest[[:space:]].+$)' \
+                    || true)"
                 # Set test tags as string.
                 TEST_TAG_STRING="${trigger#$"devicetest"}"
                 ;;
@@ -576,6 +576,7 @@ function reserve_and_cleanup_testbed () {
     # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
     # Functions called:
     # - die - Print to stderr and exit.
+    # - ansible_hosts - Perform an action using ansible, see ansible.sh
     # Traps registered:
     # - EXIT - Calls cancel_all for ${WORKING_TOPOLOGY}.
 
@@ -604,7 +605,7 @@ function reserve_and_cleanup_testbed () {
                 }
                 # Cleanup check.
                 set +e
-                cleanup_topo
+                ansible_hosts "cleanup"
                 result="$?"
                 set -e
                 if [[ "${result}" == "0" ]]; then
@@ -756,6 +757,12 @@ function select_tags () {
         *"3n-tsh"*)
             default_nic="nic_intel-x520-da2"
             ;;
+        *"3n-skx"* | *"2n-skx"* | *"2n-clx"*)
+            default_nic="nic_intel-xxv710"
+            ;;
+        *"3n-hsw"* | *"mrr-daily-master")
+            default_nic="nic_intel-xl710"
+            ;;
         *)
             default_nic="nic_intel-x710"
             ;;
@@ -869,6 +876,12 @@ function select_tags () {
         if [[ "${tag}" == "!"* ]]; then
             # Exclude tags are not prefixed.
             TAGS+=("${tag}")
+        elif [[ "${tag}" == " "* || "${tag}" == *"perftest"* ]]; then
+            # Badly formed tag expressions can trigger way too much tests.
+            set -x
+            warn "The following tag expression hints at bad trigger: ${tag}"
+            warn "Possible cause: Multiple triggers in a single comment."
+            die "Aborting to avoid triggering too many tests."
         elif [[ "${tag}" != "" && "${tag}" != "#"* ]]; then
             # Empty and comment lines are skipped.
             # Other lines are normal tags, they are to be prefixed.
@@ -1025,6 +1038,7 @@ function untrap_and_unreserve_testbed () {
     # - EXIT - Failure to untrap is reported, but ignored otherwise.
     # Functions called:
     # - die - Print to stderr and exit.
+    # - ansible_hosts - Perform an action using ansible, see ansible.sh
 
     set -xo pipefail
     set +eu  # We do not want to exit early in a "teardown" function.
@@ -1034,7 +1048,7 @@ function untrap_and_unreserve_testbed () {
         set -eu
         warn "Testbed looks unreserved already. Trap removal failed before?"
     else
-        cleanup_topo || true
+        ansible_hosts "cleanup" || true
         python "${PYTHON_SCRIPTS_DIR}/topo_reservation.py" -c -t "${wt}" || {
             die "${1:-FAILED TO UNRESERVE, FIX MANUALLY.}" 2
         }