1 # Copyright (c) 2019 Cisco and/or its affiliates.
2 # Copyright (c) 2019 PANTHEON.tech and/or its affiliates.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 # This library defines functions used by multiple entry scripts.
18 # Keep functions ordered alphabetically, please.
20 # TODO: Add a link to bash style guide.
21 # TODO: Consider putting every die into a {} block,
22 # the code might become more readable (but longer).
25 function activate_docker_topology () {
28 # Create virtual vpp-device topology. Output of the function is topology
29 # file describing created environment saved to a file.
32 # - BASH_FUNCTION_DIR - Path to existing directory this file is located in.
33 # - TOPOLOGIES - Available topologies.
34 # - NODENESS - Node multiplicity of desired testbed.
35 # - FLAVOR - Node flavor string, usually describing the processor.
37 # - WORKING_TOPOLOGY - Path to topology file.
39 source "${BASH_FUNCTION_DIR}/device.sh" || {
43 device_image="$(< ${CSIT_DIR}/VPP_DEVICE_IMAGE)"
44 case_text="${NODENESS}_${FLAVOR}"
45 case "${case_text}" in
47 # We execute reservation over csit-shim-dcr (ssh) which runs sourced
48 # script's functions. Env variables are read from ssh output
49 # back to localhost for further processing.
50 hostname=$(grep search /etc/resolv.conf | cut -d' ' -f3)
51 ssh="ssh root@${hostname} -p 6022"
52 run="activate_wrapper ${NODENESS} ${FLAVOR} ${device_image}"
53 # backtics to avoid https://midnight-commander.org/ticket/2142
54 env_vars=`${ssh} "$(declare -f); ${run}"` || {
55 die "Topology reservation via shim-dcr failed!"
58 source <(echo "$env_vars" | grep -v /usr/bin/docker) || {
64 # We execute reservation on localhost. Sourced script automatially
65 # sets environment variables for further processing.
66 activate_wrapper "${NODENESS}" "${FLAVOR}" "${device_image}" || die
69 die "Unknown specification: ${case_text}!"
72 trap 'deactivate_docker_topology' EXIT || {
73 die "Trap attempt failed, please cleanup manually. Aborting!"
76 # Replace all variables in template with those in environment.
77 source <(echo 'cat <<EOF >topo.yml'; cat ${TOPOLOGIES[0]}; echo EOF;) || {
78 die "Topology file create failed!"
81 WORKING_TOPOLOGY="/tmp/topology.yaml"
82 mv topo.yml "${WORKING_TOPOLOGY}" || {
83 die "Topology move failed!"
85 cat ${WORKING_TOPOLOGY} | grep -v password || {
86 die "Topology read failed!"
91 function activate_virtualenv () {
95 # Update virtualenv pip package, delete and create virtualenv directory,
96 # activate the virtualenv, install requirements, set PYTHONPATH.
99 # - ${1} - Path to existing directory for creating virtualenv in.
100 # If missing or empty, ${CSIT_DIR} is used.
101 # - ${2} - Path to requirements file, ${CSIT_DIR}/requirements.txt if empty.
103 # - CSIT_DIR - Path to existing root of local CSIT git repository.
104 # Variables exported:
105 # - PYTHONPATH - CSIT_DIR, as CSIT Python scripts usually need this.
107 # - die - Print to stderr and exit.
109 # TODO: Do we want the callers to be able to set the env dir name?
110 # TODO: + In that case, do we want to support env switching?
111 # TODO: + In that case we want to make env_dir global.
112 # TODO: Do we want the callers to override PYTHONPATH loaction?
114 root_path="${1-$CSIT_DIR}"
115 env_dir="${root_path}/env"
116 req_path=${2-$CSIT_DIR/requirements.txt}
117 rm -rf "${env_dir}" || die "Failed to clean previous virtualenv."
118 pip install --upgrade virtualenv || {
119 die "Virtualenv package install failed."
121 virtualenv "${env_dir}" || {
122 die "Virtualenv creation failed."
125 source "${env_dir}/bin/activate" || die "Virtualenv activation failed."
127 pip install --upgrade -r "${req_path}" || {
128 die "Requirements installation failed."
130 # Most CSIT Python scripts assume PYTHONPATH is set and exported.
131 export PYTHONPATH="${CSIT_DIR}" || die "Export failed."
135 function archive_tests () {
139 # Create .tar.xz of generated/tests for archiving.
140 # To be run after generate_tests, kept separate to offer more flexibility.
143 # - ${GENERATED_DIR}/tests - Tree of executed suites to archive.
145 # - ${ARCHIVE_DIR}/tests.tar.xz - Archive of generated tests.
147 tar c "${GENERATED_DIR}/tests" | xz -9e > "${ARCHIVE_DIR}/tests.tar.xz" || {
148 die "Error creating archive of generated tests."
153 function check_download_dir () {
157 # Fail if there are no files visible in ${DOWNLOAD_DIR}.
158 # TODO: Do we need this as a function, if it is (almost) a one-liner?
161 # - DOWNLOAD_DIR - Path to directory pybot takes the build to test from.
163 # - ${DOWNLOAD_DIR} - Has to be non-empty to proceed.
165 # - die - Print to stderr and exit.
167 if [[ ! "$(ls -A "${DOWNLOAD_DIR}")" ]]; then
168 die "No artifacts downloaded!"
173 function cleanup_topo () {
178 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
179 # - PYTHON_SCRIPTS_DIR - Path to directory holding the reservation script.
181 python "${PYTHON_SCRIPTS_DIR}/topo_cleanup.py" -t "${WORKING_TOPOLOGY}"
182 # Not using "|| die" as some callers might want to ignore errors,
183 # e.g. in teardowns, such as unreserve.
187 function common_dirs () {
191 # Set global variables, create some directories (without touching content).
194 # - BASH_FUNCTION_DIR - Path to existing directory this file is located in.
195 # - CSIT_DIR - Path to existing root of local CSIT git repository.
196 # - TOPOLOGIES_DIR - Path to existing directory with available tpologies.
197 # - RESOURCES_DIR - Path to existing CSIT subdirectory "resources".
198 # - TOOLS_DIR - Path to existing resources subdirectory "tools".
199 # - PYTHON_SCRIPTS_DIR - Path to existing tools subdirectory "scripts".
200 # - ARCHIVE_DIR - Path to created CSIT subdirectory "archive".
201 # - DOWNLOAD_DIR - Path to created CSIT subdirectory "download_dir".
202 # - GENERATED_DIR - Path to created CSIT subdirectory "generated".
203 # Directories created if not present:
204 # ARCHIVE_DIR, DOWNLOAD_DIR, GENERATED_DIR.
206 # - die - Print to stderr and exit.
208 BASH_FUNCTION_DIR="$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")" || {
209 die "Some error during localizing this source directory."
211 # Current working directory could be in a different repo, e.g. VPP.
212 pushd "${BASH_FUNCTION_DIR}" || die "Pushd failed"
213 CSIT_DIR="$(readlink -e "$(git rev-parse --show-toplevel)")" || {
214 die "Readlink or git rev-parse failed."
216 popd || die "Popd failed."
217 TOPOLOGIES_DIR="$(readlink -e "${CSIT_DIR}/topologies/available")" || {
218 die "Readlink failed."
220 RESOURCES_DIR="$(readlink -e "${CSIT_DIR}/resources")" || {
221 die "Readlink failed."
223 TOOLS_DIR="$(readlink -e "${RESOURCES_DIR}/tools")" || {
224 die "Readlink failed."
226 PYTHON_SCRIPTS_DIR="$(readlink -e "${TOOLS_DIR}/scripts")" || {
227 die "Readlink failed."
230 ARCHIVE_DIR="$(readlink -f "${CSIT_DIR}/archive")" || {
231 die "Readlink failed."
233 mkdir -p "${ARCHIVE_DIR}" || die "Mkdir failed."
234 DOWNLOAD_DIR="$(readlink -f "${CSIT_DIR}/download_dir")" || {
235 die "Readlink failed."
237 mkdir -p "${DOWNLOAD_DIR}" || die "Mkdir failed."
238 GENERATED_DIR="$(readlink -f "${CSIT_DIR}/generated")" || {
239 die "Readlink failed."
241 mkdir -p "${GENERATED_DIR}" || die "Mkdir failed."
245 function compose_pybot_arguments () {
250 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
251 # - DUT - CSIT test/ subdirectory, set while processing tags.
252 # - TAGS - Array variable holding selected tag boolean expressions.
253 # - TOPOLOGIES_TAGS - Tag boolean expression filtering tests for topology.
254 # - TEST_CODE - The test selection string from environment or argument.
256 # - PYBOT_ARGS - String holding part of all arguments for pybot.
257 # - EXPANDED_TAGS - Array of strings pybot arguments compiled from tags.
259 # No explicit check needed with "set -u".
260 PYBOT_ARGS=("--loglevel" "TRACE")
261 PYBOT_ARGS+=("--variable" "TOPOLOGY_PATH:${WORKING_TOPOLOGY}")
263 case "${TEST_CODE}" in
265 PYBOT_ARGS+=("--suite" "tests.${DUT}.device")
268 PYBOT_ARGS+=("--suite" "tests.${DUT}.func")
271 PYBOT_ARGS+=("--suite" "tests.${DUT}.perf")
274 die "Unknown specification: ${TEST_CODE}"
278 for tag in "${TAGS[@]}"; do
279 if [[ ${tag} == "!"* ]]; then
280 EXPANDED_TAGS+=("--exclude" "${tag#$"!"}")
282 EXPANDED_TAGS+=("--include" "${TOPOLOGIES_TAGS}AND${tag}")
288 function copy_archives () {
293 # - WORKSPACE - Jenkins workspace, copy only if the value is not empty.
294 # Can be unset, then it speeds up manual testing.
295 # - ARCHIVE_DIR - Path to directory with content to be copied.
296 # Directories updated:
297 # - ${WORKSPACE}/archives/ - Created if does not exist.
298 # Content of ${ARCHIVE_DIR}/ is copied here.
300 # - die - Print to stderr and exit.
302 # We will create additional archive if workspace variable is set.
303 # This way if script is running in jenkins all will be
304 # automatically archived to logs.fd.io.
305 if [[ -n "${WORKSPACE-}" ]]; then
306 mkdir -p "${WORKSPACE}/archives/" || die "Archives dir create failed."
307 cp -rf "${ARCHIVE_DIR}"/* "${WORKSPACE}/archives" || die "Copy failed."
312 function deactivate_docker_topology () {
313 # Deactivate virtual vpp-device topology by removing containers.
316 # - NODENESS - Node multiplicity of desired testbed.
317 # - FLAVOR - Node flavor string, usually describing the processor.
321 case_text="${NODENESS}_${FLAVOR}"
322 case "${case_text}" in
324 hostname=$(grep search /etc/resolv.conf | cut -d' ' -f3)
325 ssh="ssh root@${hostname} -p 6022"
326 env_vars="$(env | grep CSIT_ | tr '\n' ' ' )"
327 ${ssh} "$(declare -f); deactivate_wrapper ${env_vars}" || {
328 die "Topology cleanup via shim-dcr failed!"
333 clean_environment || {
334 die "Topology cleanup locally failed!"
339 die "Unknown specification: ${case_text}!"
345 # Print the message to standard error end exit with error code specified
346 # by the second argument.
349 # - The default error message.
351 # - ${1} - The whole error message, be sure to quote. Optional
352 # - ${2} - the code to exit with, default: 1.
356 warn "${1:-Unspecified run-time error occurred!}"
361 function die_on_pybot_error () {
365 # Source this fragment if you want to abort on any failed test case.
368 # - PYBOT_EXIT_STATUS - Set by a pybot running fragment.
370 # - die - Print to stderr and exit.
372 if [[ "${PYBOT_EXIT_STATUS}" != "0" ]]; then
373 die "Test failures are present!" "${PYBOT_EXIT_STATUS}"
378 function generate_tests () {
382 # Populate ${GENERATED_DIR}/tests based on ${CSIT_DIR}/tests/.
383 # Any previously existing content of ${GENERATED_DIR}/tests is wiped before.
384 # The generation is done by executing any *.py executable
385 # within any subdirectory after copying.
387 # This is a separate function, because this code is called
388 # both by autogen checker and entries calling run_pybot.
391 # - ${CSIT_DIR}/tests - Used as templates for the generated tests.
392 # Directories replaced:
393 # - ${GENERATED_DIR}/tests - Overwritten by the generated tests.
395 rm -rf "${GENERATED_DIR}/tests"
396 cp -r "${CSIT_DIR}/tests" "${GENERATED_DIR}/tests"
397 cmd_line=("find" "${GENERATED_DIR}/tests" "-type" "f")
398 cmd_line+=("-executable" "-name" "*.py")
399 file_list=$("${cmd_line[@]}") || die
401 for gen in ${file_list}; do
402 directory="$(dirname "${gen}")" || die
403 filename="$(basename "${gen}")" || die
404 pushd "${directory}" || die
405 ./"${filename}" || die
411 function get_test_code () {
416 # - ${1} - Optional, argument of entry script (or empty as unset).
417 # Test code value to override job name from environment.
419 # - JOB_NAME - String affecting test selection, default if not argument.
421 # - TEST_CODE - The test selection string from environment or argument.
422 # - NODENESS - Node multiplicity of desired testbed.
423 # - FLAVOR - Node flavor string, usually describing the processor.
425 TEST_CODE="${1-}" || die "Reading optional argument failed, somehow."
426 if [[ -z "${TEST_CODE}" ]]; then
427 TEST_CODE="${JOB_NAME-}" || die "Reading job name failed, somehow."
430 case "${TEST_CODE}" in
452 # Fallback to 3-node Haswell by default (backward compatibility)
460 function get_test_tag_string () {
465 # - GERRIT_EVENT_TYPE - Event type set by gerrit, can be unset.
466 # - GERRIT_EVENT_COMMENT_TEXT - Comment text, read for "comment-added" type.
467 # - TEST_CODE - The test selection string from environment or argument.
469 # - TEST_TAG_STRING - The string following "perftest" in gerrit comment,
472 # TODO: ci-management scripts no longer need to perform this.
475 if [[ "${GERRIT_EVENT_TYPE-}" == "comment-added" ]]; then
476 case "${TEST_CODE}" in
478 # On parsing error, ${trigger} stays empty.
479 trigger="$(echo "${GERRIT_EVENT_COMMENT_TEXT}" \
480 | grep -oE '(devicetest$|devicetest[[:space:]].+$)')" \
482 # Set test tags as string.
483 TEST_TAG_STRING="${trigger#$"devicetest"}"
486 # On parsing error, ${trigger} stays empty.
487 comment="${GERRIT_EVENT_COMMENT_TEXT}"
488 # As "perftest" can be followed by something, we substitute it.
489 comment="${comment/perftest-2n/perftest}"
490 comment="${comment/perftest-3n/perftest}"
491 comment="${comment/perftest-hsw/perftest}"
492 comment="${comment/perftest-skx/perftest}"
493 comment="${comment/perftest-tsh/perftest}"
494 tag_string="$(echo "${comment}" \
495 | grep -oE '(perftest$|perftest[[:space:]].+$)' || true)"
496 # Set test tags as string.
497 TEST_TAG_STRING="${tag_string#$"perftest"}"
500 die "Unknown specification: ${TEST_CODE}"
506 function reserve_testbed () {
510 # Reserve physical testbed, perform cleanup, register trap to unreserve.
513 # - TOPOLOGIES - Array of paths to topology yaml to attempt reservation on.
514 # - PYTHON_SCRIPTS_DIR - Path to directory holding the reservation script.
516 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
518 # - die - Print to stderr and exit.
520 # - EXIT - Calls cancel_all for ${WORKING_TOPOLOGY}.
523 for topo in "${TOPOLOGIES[@]}"; do
525 python "${PYTHON_SCRIPTS_DIR}/topo_reservation.py" -t "${topo}"
528 if [[ "${result}" == "0" ]]; then
529 WORKING_TOPOLOGY="${topo}"
530 echo "Reserved: ${WORKING_TOPOLOGY}"
531 trap "untrap_and_unreserve_testbed" EXIT || {
532 message="TRAP ATTEMPT AND UNRESERVE FAILED, FIX MANUALLY."
533 untrap_and_unreserve_testbed "${message}" || {
534 die "Teardown should have died, not failed."
536 die "Trap attempt failed, unreserve succeeded. Aborting."
539 die "Testbed cleanup failed."
545 if [[ -n "${WORKING_TOPOLOGY-}" ]]; then
546 # Exit the infinite while loop if we made a reservation.
550 # Wait ~3minutes before next try.
551 sleep_time="$[ ( $RANDOM % 20 ) + 180 ]s" || {
552 die "Sleep time calculation failed."
554 echo "Sleeping ${sleep_time}"
555 sleep "${sleep_time}" || die "Sleep failed."
560 function run_pybot () {
565 # - CSIT_DIR - Path to existing root of local CSIT git repository.
566 # - ARCHIVE_DIR - Path to store robot result files in.
567 # - PYBOT_ARGS, EXPANDED_TAGS - See compose_pybot_arguments.sh
568 # - GENERATED_DIR - Tests are assumed to be generated under there.
570 # - PYBOT_EXIT_STATUS - Exit status of most recent pybot invocation.
572 # - die - Print to stderr and exit.
574 all_options=("--outputdir" "${ARCHIVE_DIR}" "${PYBOT_ARGS[@]}")
575 all_options+=("${EXPANDED_TAGS[@]}")
577 pushd "${CSIT_DIR}" || die "Change directory operation failed."
579 # TODO: Make robot tests not require "$(pwd)" == "${CSIT_DIR}".
580 pybot "${all_options[@]}" "${GENERATED_DIR}/tests/"
581 PYBOT_EXIT_STATUS="$?"
584 # Generate INFO level output_info.xml for post-processing.
585 all_options=("--loglevel" "INFO")
586 all_options+=("--log" "none")
587 all_options+=("--report" "none")
588 all_options+=("--output" "${ARCHIVE_DIR}/output_info.xml")
589 all_options+=("${ARCHIVE_DIR}/output.xml")
590 rebot "${all_options[@]}"
591 popd || die "Change directory operation failed."
595 function select_tags () {
600 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
601 # - TEST_CODE - String affecting test selection, usually jenkins job name.
602 # - TEST_TAG_STRING - String selecting tags, from gerrit comment.
604 # - TOPOLOGIES_DIR - Path to existing directory with available tpologies.
606 # - TAGS - Array of processed tag boolean expressions.
609 start_pattern='^ TG:'
610 end_pattern='^ \? \?[A-Za-z0-9]\+:'
611 # Remove the TG section from topology file
612 sed_command="/${start_pattern}/,/${end_pattern}/d"
613 # All topologies DUT NICs
614 available=$(sed "${sed_command}" "${TOPOLOGIES_DIR}"/* \
615 | grep -hoP "model: \K.*" | sort -u)
616 # Selected topology DUT NICs
617 reserved=$(sed "${sed_command}" "${WORKING_TOPOLOGY}" \
618 | grep -hoP "model: \K.*" | sort -u)
619 # All topologies DUT NICs - Selected topology DUT NICs
620 exclude_nics=($(comm -13 <(echo "${reserved}") <(echo "${available}")))
623 case "${TEST_CODE}" in
625 DEFAULT_NIC='nic_intel-x520-da2'
628 DEFAULT_NIC='nic_intel-x710'
632 case "${TEST_CODE}" in
633 # Select specific performance tests based on jenkins job type variable.
635 readarray -t test_tag_array < "${BASH_FUNCTION_DIR}/mlr-weekly.txt"
638 readarray -t test_tag_array < "${BASH_FUNCTION_DIR}/mrr-daily.txt"
641 readarray -t test_tag_array < "${BASH_FUNCTION_DIR}/mrr-weekly.txt"
644 if [[ -z "${TEST_TAG_STRING-}" ]]; then
645 # If nothing is specified, we will run pre-selected tests by
647 test_tag_array=("mrrAND${DEFAULT_NIC}AND1cAND64bANDip4base"
648 "mrrAND${DEFAULT_NIC}AND1cAND78bANDip6base"
649 "mrrAND${DEFAULT_NIC}AND1cAND64bANDl2bdbase"
650 "mrrAND${DEFAULT_NIC}AND1cAND64bANDl2xcbase"
653 # If trigger contains tags, split them into array.
654 test_tag_array=(${TEST_TAG_STRING//:/ })
659 # Blacklisting certain tags per topology.
660 case "${TEST_CODE}" in
662 test_tag_array+=("!drv_avf")
665 test_tag_array+=("!ipsechw")
668 test_tag_array+=("!ipsechw")
671 test_tag_array+=("!ipsechw")
672 test_tag_array+=("!memif")
673 test_tag_array+=("!srv6_proxy")
674 test_tag_array+=("!vhost")
675 test_tag_array+=("!vts")
678 # Default to 3n-hsw due to compatibility.
679 test_tag_array+=("!drv_avf")
683 # We will add excluded NICs.
684 test_tag_array+=("${exclude_nics[@]/#/!NIC_}")
688 # We will prefix with perftest to prevent running other tests
691 if [[ "${TEST_CODE}" == "vpp-"* ]]; then
692 # Automatic prefixing for VPP jobs to limit the NIC used and
693 # traffic evaluation to MRR.
694 prefix="${prefix}mrrAND${DEFAULT_NIC}AND"
696 for tag in "${test_tag_array[@]}"; do
697 if [[ "${tag}" == "!"* ]]; then
698 # Exclude tags are not prefixed.
700 elif [[ "${tag}" != "" && "${tag}" != "#"* ]]; then
701 # Empty and comment lines are skipped.
702 # Other lines are normal tags, they are to be prefixed.
703 TAGS+=("${prefix}${tag}")
709 function select_vpp_device_tags () {
714 # - TEST_CODE - String affecting test selection, usually jenkins job name.
715 # - TEST_TAG_STRING - String selecting tags, from gerrit comment.
718 # - TAGS - Array of processed tag boolean expressions.
720 case "${TEST_CODE}" in
721 # Select specific performance tests based on jenkins job type variable.
723 if [[ -z "${TEST_TAG_STRING-}" ]]; then
724 # If nothing is specified, we will run pre-selected tests by
725 # following tags. Items of array will be concatenated by OR
726 # in Robot Framework.
729 # If trigger contains tags, split them into array.
730 test_tag_array=(${TEST_TAG_STRING//:/ })
737 # We will prefix with perftest to prevent running other tests
739 prefix="devicetestAND"
740 if [[ "${TEST_CODE}" == "vpp-"* ]]; then
741 # Automatic prefixing for VPP jobs to limit testing.
744 for tag in "${test_tag_array[@]}"; do
745 if [[ ${tag} == "!"* ]]; then
746 # Exclude tags are not prefixed.
749 TAGS+=("${prefix}${tag}")
755 function select_topology () {
760 # - NODENESS - Node multiplicity of testbed, either "2n" or "3n".
761 # - FLAVOR - Node flavor string, currently either "hsw" or "skx".
762 # - CSIT_DIR - Path to existing root of local CSIT git repository.
763 # - TOPOLOGIES_DIR - Path to existing directory with available topologies.
765 # - TOPOLOGIES - Array of paths to suitable topology yaml files.
766 # - TOPOLOGIES_TAGS - Tag expression selecting tests for the topology.
768 # - die - Print to stderr and exit.
770 case_text="${NODENESS}_${FLAVOR}"
771 case "${case_text}" in
774 "${TOPOLOGIES_DIR}/vpp_device.template"
776 TOPOLOGIES_TAGS="2_node_single_link_topo"
780 "${TOPOLOGIES_DIR}/vpp_device.template"
782 TOPOLOGIES_TAGS="2_node_single_link_topo"
786 "${TOPOLOGIES_DIR}/lf_2n_skx_testbed21.yaml"
787 #"${TOPOLOGIES_DIR}/lf_2n_skx_testbed22.yaml"
788 "${TOPOLOGIES_DIR}/lf_2n_skx_testbed23.yaml"
789 "${TOPOLOGIES_DIR}/lf_2n_skx_testbed24.yaml"
791 TOPOLOGIES_TAGS="2_node_*_link_topo"
795 "${TOPOLOGIES_DIR}/lf_3n_skx_testbed31.yaml"
796 "${TOPOLOGIES_DIR}/lf_3n_skx_testbed32.yaml"
798 TOPOLOGIES_TAGS="3_node_*_link_topo"
802 "${TOPOLOGIES_DIR}/lf_3n_hsw_testbed1.yaml"
803 "${TOPOLOGIES_DIR}/lf_3n_hsw_testbed2.yaml"
804 "${TOPOLOGIES_DIR}/lf_3n_hsw_testbed3.yaml"
806 TOPOLOGIES_TAGS="3_node_single_link_topo"
810 "${TOPOLOGIES_DIR}/lf_3n_tsh_testbed33.yaml"
812 TOPOLOGIES_TAGS="3_node_*_link_topo"
815 # No falling back to 3n_hsw default, that should have been done
816 # by the function which has set NODENESS and FLAVOR.
817 die "Unknown specification: ${case_text}"
820 if [[ -z "${TOPOLOGIES-}" ]]; then
821 die "No applicable topology found!"
826 function untrap_and_unreserve_testbed () {
827 # Use this as a trap function to ensure testbed does not remain reserved.
828 # Perhaps call directly before script exit, to free testbed for other jobs.
829 # This function is smart enough to avoid multiple unreservations (so safe).
830 # Topo cleanup is executed (call it best practice), ignoring failures.
833 # - default message to die with if testbed might remain reserved.
835 # - ${1} - Message to die with if unreservation fails. Default hardcoded.
836 # Variables read (by inner function):
837 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
838 # - PYTHON_SCRIPTS_DIR - Path to directory holding Python scripts.
840 # - WORKING_TOPOLOGY - Set to empty string on successful unreservation.
842 # - EXIT - Failure to untrap is reported, but ignored otherwise.
844 # - die - Print to stderr and exit.
847 set +eu # We do not want to exit early in a "teardown" function.
848 trap - EXIT || echo "Trap deactivation failed, continuing anyway."
849 wt="${WORKING_TOPOLOGY}" # Just to avoid too long lines.
850 if [[ -z "${wt-}" ]]; then
852 warn "Testbed looks unreserved already. Trap removal failed before?"
855 python "${PYTHON_SCRIPTS_DIR}/topo_reservation.py" -c -t "${wt}" || {
856 die "${1:-FAILED TO UNRESERVE, FIX MANUALLY.}" 2
865 # Print the message to standard error.
868 # - ${@} - The text of the message.