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.
36 # - IMAGE_VER_FILE - Name of file that contains the image version.
38 # - WORKING_TOPOLOGY - Path to topology file.
40 source "${BASH_FUNCTION_DIR}/device.sh" || {
44 device_image="$(< ${CSIT_DIR}/${IMAGE_VER_FILE})"
45 case_text="${NODENESS}_${FLAVOR}"
46 case "${case_text}" in
48 # We execute reservation over csit-shim-dcr (ssh) which runs sourced
49 # script's functions. Env variables are read from ssh output
50 # back to localhost for further processing.
51 hostname=$(grep search /etc/resolv.conf | cut -d' ' -f3)
52 ssh="ssh root@${hostname} -p 6022"
53 run="activate_wrapper ${NODENESS} ${FLAVOR} ${device_image}"
54 # backtics to avoid https://midnight-commander.org/ticket/2142
55 env_vars=`${ssh} "$(declare -f); ${run}"` || {
56 die "Topology reservation via shim-dcr failed!"
59 source <(echo "$env_vars" | grep -v /usr/bin/docker) || {
65 # We execute reservation on localhost. Sourced script automatially
66 # sets environment variables for further processing.
67 activate_wrapper "${NODENESS}" "${FLAVOR}" "${device_image}" || die
70 die "Unknown specification: ${case_text}!"
73 trap 'deactivate_docker_topology' EXIT || {
74 die "Trap attempt failed, please cleanup manually. Aborting!"
77 # Replace all variables in template with those in environment.
78 source <(echo 'cat <<EOF >topo.yml'; cat ${TOPOLOGIES[0]}; echo EOF;) || {
79 die "Topology file create failed!"
82 WORKING_TOPOLOGY="/tmp/topology.yaml"
83 mv topo.yml "${WORKING_TOPOLOGY}" || {
84 die "Topology move failed!"
86 cat ${WORKING_TOPOLOGY} | grep -v password || {
87 die "Topology read failed!"
92 function activate_virtualenv () {
96 # Update virtualenv pip package, delete and create virtualenv directory,
97 # activate the virtualenv, install requirements, set PYTHONPATH.
100 # - ${1} - Path to existing directory for creating virtualenv in.
101 # If missing or empty, ${CSIT_DIR} is used.
102 # - ${2} - Path to requirements file, ${CSIT_DIR}/requirements.txt if empty.
104 # - CSIT_DIR - Path to existing root of local CSIT git repository.
105 # Variables exported:
106 # - PYTHONPATH - CSIT_DIR, as CSIT Python scripts usually need this.
108 # - die - Print to stderr and exit.
110 # TODO: Do we want the callers to be able to set the env dir name?
111 # TODO: + In that case, do we want to support env switching?
112 # TODO: + In that case we want to make env_dir global.
113 # TODO: Do we want the callers to override PYTHONPATH loaction?
115 root_path="${1-$CSIT_DIR}"
116 env_dir="${root_path}/env"
117 req_path=${2-$CSIT_DIR/requirements.txt}
118 rm -rf "${env_dir}" || die "Failed to clean previous virtualenv."
119 pip install --upgrade virtualenv || {
120 die "Virtualenv package install failed."
122 virtualenv "${env_dir}" || {
123 die "Virtualenv creation failed."
126 source "${env_dir}/bin/activate" || die "Virtualenv activation failed."
128 pip install --upgrade -r "${req_path}" || {
129 die "Requirements installation failed."
131 # Most CSIT Python scripts assume PYTHONPATH is set and exported.
132 export PYTHONPATH="${CSIT_DIR}" || die "Export failed."
136 function archive_tests () {
140 # Create .tar.xz of generated/tests for archiving.
141 # To be run after generate_tests, kept separate to offer more flexibility.
144 # - ${GENERATED_DIR}/tests - Tree of executed suites to archive.
146 # - ${ARCHIVE_DIR}/tests.tar.xz - Archive of generated tests.
148 tar c "${GENERATED_DIR}/tests" | xz -9e > "${ARCHIVE_DIR}/tests.tar.xz" || {
149 die "Error creating archive of generated tests."
154 function check_download_dir () {
158 # Fail if there are no files visible in ${DOWNLOAD_DIR}.
159 # TODO: Do we need this as a function, if it is (almost) a one-liner?
162 # - DOWNLOAD_DIR - Path to directory pybot takes the build to test from.
164 # - ${DOWNLOAD_DIR} - Has to be non-empty to proceed.
166 # - die - Print to stderr and exit.
168 if [[ ! "$(ls -A "${DOWNLOAD_DIR}")" ]]; then
169 die "No artifacts downloaded!"
174 function cleanup_topo () {
179 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
180 # - PYTHON_SCRIPTS_DIR - Path to directory holding the reservation script.
182 python "${PYTHON_SCRIPTS_DIR}/topo_cleanup.py" -t "${WORKING_TOPOLOGY}"
183 # Not using "|| die" as some callers might want to ignore errors,
184 # e.g. in teardowns, such as unreserve.
188 function common_dirs () {
192 # Set global variables, create some directories (without touching content).
195 # - BASH_FUNCTION_DIR - Path to existing directory this file is located in.
196 # - CSIT_DIR - Path to existing root of local CSIT git repository.
197 # - TOPOLOGIES_DIR - Path to existing directory with available tpologies.
198 # - RESOURCES_DIR - Path to existing CSIT subdirectory "resources".
199 # - TOOLS_DIR - Path to existing resources subdirectory "tools".
200 # - PYTHON_SCRIPTS_DIR - Path to existing tools subdirectory "scripts".
201 # - ARCHIVE_DIR - Path to created CSIT subdirectory "archive".
202 # - DOWNLOAD_DIR - Path to created CSIT subdirectory "download_dir".
203 # - GENERATED_DIR - Path to created CSIT subdirectory "generated".
204 # Directories created if not present:
205 # ARCHIVE_DIR, DOWNLOAD_DIR, GENERATED_DIR.
207 # - die - Print to stderr and exit.
209 BASH_FUNCTION_DIR="$(dirname "$(readlink -e "${BASH_SOURCE[0]}")")" || {
210 die "Some error during localizing this source directory."
212 # Current working directory could be in a different repo, e.g. VPP.
213 pushd "${BASH_FUNCTION_DIR}" || die "Pushd failed"
214 CSIT_DIR="$(readlink -e "$(git rev-parse --show-toplevel)")" || {
215 die "Readlink or git rev-parse failed."
217 popd || die "Popd failed."
218 TOPOLOGIES_DIR="$(readlink -e "${CSIT_DIR}/topologies/available")" || {
219 die "Readlink failed."
221 RESOURCES_DIR="$(readlink -e "${CSIT_DIR}/resources")" || {
222 die "Readlink failed."
224 TOOLS_DIR="$(readlink -e "${RESOURCES_DIR}/tools")" || {
225 die "Readlink failed."
227 PYTHON_SCRIPTS_DIR="$(readlink -e "${TOOLS_DIR}/scripts")" || {
228 die "Readlink failed."
231 ARCHIVE_DIR="$(readlink -f "${CSIT_DIR}/archive")" || {
232 die "Readlink failed."
234 mkdir -p "${ARCHIVE_DIR}" || die "Mkdir failed."
235 DOWNLOAD_DIR="$(readlink -f "${CSIT_DIR}/download_dir")" || {
236 die "Readlink failed."
238 mkdir -p "${DOWNLOAD_DIR}" || die "Mkdir failed."
239 GENERATED_DIR="$(readlink -f "${CSIT_DIR}/generated")" || {
240 die "Readlink failed."
242 mkdir -p "${GENERATED_DIR}" || die "Mkdir failed."
246 function compose_pybot_arguments () {
251 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
252 # - DUT - CSIT test/ subdirectory, set while processing tags.
253 # - TAGS - Array variable holding selected tag boolean expressions.
254 # - TOPOLOGIES_TAGS - Tag boolean expression filtering tests for topology.
255 # - TEST_CODE - The test selection string from environment or argument.
257 # - PYBOT_ARGS - String holding part of all arguments for pybot.
258 # - EXPANDED_TAGS - Array of strings pybot arguments compiled from tags.
260 # No explicit check needed with "set -u".
261 PYBOT_ARGS=("--loglevel" "TRACE")
262 PYBOT_ARGS+=("--variable" "TOPOLOGY_PATH:${WORKING_TOPOLOGY}")
264 case "${TEST_CODE}" in
266 PYBOT_ARGS+=("--suite" "tests.${DUT}.device")
269 PYBOT_ARGS+=("--suite" "tests.${DUT}.func")
272 PYBOT_ARGS+=("--suite" "tests.${DUT}.perf")
275 die "Unknown specification: ${TEST_CODE}"
279 for tag in "${TAGS[@]}"; do
280 if [[ ${tag} == "!"* ]]; then
281 EXPANDED_TAGS+=("--exclude" "${tag#$"!"}")
283 EXPANDED_TAGS+=("--include" "${TOPOLOGIES_TAGS}AND${tag}")
289 function copy_archives () {
294 # - WORKSPACE - Jenkins workspace, copy only if the value is not empty.
295 # Can be unset, then it speeds up manual testing.
296 # - ARCHIVE_DIR - Path to directory with content to be copied.
297 # Directories updated:
298 # - ${WORKSPACE}/archives/ - Created if does not exist.
299 # Content of ${ARCHIVE_DIR}/ is copied here.
301 # - die - Print to stderr and exit.
303 # We will create additional archive if workspace variable is set.
304 # This way if script is running in jenkins all will be
305 # automatically archived to logs.fd.io.
306 if [[ -n "${WORKSPACE-}" ]]; then
307 mkdir -p "${WORKSPACE}/archives/" || die "Archives dir create failed."
308 cp -rf "${ARCHIVE_DIR}"/* "${WORKSPACE}/archives" || die "Copy failed."
313 function deactivate_docker_topology () {
314 # Deactivate virtual vpp-device topology by removing containers.
317 # - NODENESS - Node multiplicity of desired testbed.
318 # - FLAVOR - Node flavor string, usually describing the processor.
322 case_text="${NODENESS}_${FLAVOR}"
323 case "${case_text}" in
325 hostname=$(grep search /etc/resolv.conf | cut -d' ' -f3)
326 ssh="ssh root@${hostname} -p 6022"
327 env_vars="$(env | grep CSIT_ | tr '\n' ' ' )"
328 ${ssh} "$(declare -f); deactivate_wrapper ${env_vars}" || {
329 die "Topology cleanup via shim-dcr failed!"
334 clean_environment || {
335 die "Topology cleanup locally failed!"
340 die "Unknown specification: ${case_text}!"
346 # Print the message to standard error end exit with error code specified
347 # by the second argument.
350 # - The default error message.
352 # - ${1} - The whole error message, be sure to quote. Optional
353 # - ${2} - the code to exit with, default: 1.
357 warn "${1:-Unspecified run-time error occurred!}"
362 function die_on_pybot_error () {
366 # Source this fragment if you want to abort on any failed test case.
369 # - PYBOT_EXIT_STATUS - Set by a pybot running fragment.
371 # - die - Print to stderr and exit.
373 if [[ "${PYBOT_EXIT_STATUS}" != "0" ]]; then
374 die "Test failures are present!" "${PYBOT_EXIT_STATUS}"
379 function generate_tests () {
383 # Populate ${GENERATED_DIR}/tests based on ${CSIT_DIR}/tests/.
384 # Any previously existing content of ${GENERATED_DIR}/tests is wiped before.
385 # The generation is done by executing any *.py executable
386 # within any subdirectory after copying.
388 # This is a separate function, because this code is called
389 # both by autogen checker and entries calling run_pybot.
392 # - ${CSIT_DIR}/tests - Used as templates for the generated tests.
393 # Directories replaced:
394 # - ${GENERATED_DIR}/tests - Overwritten by the generated tests.
396 rm -rf "${GENERATED_DIR}/tests"
397 cp -r "${CSIT_DIR}/tests" "${GENERATED_DIR}/tests"
398 cmd_line=("find" "${GENERATED_DIR}/tests" "-type" "f")
399 cmd_line+=("-executable" "-name" "*.py")
400 file_list=$("${cmd_line[@]}") || die
402 for gen in ${file_list}; do
403 directory="$(dirname "${gen}")" || die
404 filename="$(basename "${gen}")" || die
405 pushd "${directory}" || die
406 ./"${filename}" || die
412 function get_test_code () {
417 # - ${1} - Optional, argument of entry script (or empty as unset).
418 # Test code value to override job name from environment.
420 # - JOB_NAME - String affecting test selection, default if not argument.
422 # - TEST_CODE - The test selection string from environment or argument.
423 # - NODENESS - Node multiplicity of desired testbed.
424 # - FLAVOR - Node flavor string, usually describing the processor.
426 TEST_CODE="${1-}" || die "Reading optional argument failed, somehow."
427 if [[ -z "${TEST_CODE}" ]]; then
428 TEST_CODE="${JOB_NAME-}" || die "Reading job name failed, somehow."
431 case "${TEST_CODE}" in
453 # Fallback to 3-node Haswell by default (backward compatibility)
461 function get_test_tag_string () {
466 # - GERRIT_EVENT_TYPE - Event type set by gerrit, can be unset.
467 # - GERRIT_EVENT_COMMENT_TEXT - Comment text, read for "comment-added" type.
468 # - TEST_CODE - The test selection string from environment or argument.
470 # - TEST_TAG_STRING - The string following "perftest" in gerrit comment,
473 # TODO: ci-management scripts no longer need to perform this.
476 if [[ "${GERRIT_EVENT_TYPE-}" == "comment-added" ]]; then
477 case "${TEST_CODE}" in
479 # On parsing error, ${trigger} stays empty.
480 trigger="$(echo "${GERRIT_EVENT_COMMENT_TEXT}" \
481 | grep -oE '(devicetest$|devicetest[[:space:]].+$)')" \
483 # Set test tags as string.
484 TEST_TAG_STRING="${trigger#$"devicetest"}"
487 # On parsing error, ${trigger} stays empty.
488 comment="${GERRIT_EVENT_COMMENT_TEXT}"
489 # As "perftest" can be followed by something, we substitute it.
490 comment="${comment/perftest-2n/perftest}"
491 comment="${comment/perftest-3n/perftest}"
492 comment="${comment/perftest-hsw/perftest}"
493 comment="${comment/perftest-skx/perftest}"
494 comment="${comment/perftest-tsh/perftest}"
495 tag_string="$(echo "${comment}" \
496 | grep -oE '(perftest$|perftest[[:space:]].+$)' || true)"
497 # Set test tags as string.
498 TEST_TAG_STRING="${tag_string#$"perftest"}"
501 die "Unknown specification: ${TEST_CODE}"
507 function reserve_testbed () {
511 # Reserve physical testbed, perform cleanup, register trap to unreserve.
514 # - TOPOLOGIES - Array of paths to topology yaml to attempt reservation on.
515 # - PYTHON_SCRIPTS_DIR - Path to directory holding the reservation script.
517 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
519 # - die - Print to stderr and exit.
521 # - EXIT - Calls cancel_all for ${WORKING_TOPOLOGY}.
524 for topo in "${TOPOLOGIES[@]}"; do
526 python "${PYTHON_SCRIPTS_DIR}/topo_reservation.py" -t "${topo}"
529 if [[ "${result}" == "0" ]]; then
530 WORKING_TOPOLOGY="${topo}"
531 echo "Reserved: ${WORKING_TOPOLOGY}"
532 trap "untrap_and_unreserve_testbed" EXIT || {
533 message="TRAP ATTEMPT AND UNRESERVE FAILED, FIX MANUALLY."
534 untrap_and_unreserve_testbed "${message}" || {
535 die "Teardown should have died, not failed."
537 die "Trap attempt failed, unreserve succeeded. Aborting."
540 die "Testbed cleanup failed."
546 if [[ -n "${WORKING_TOPOLOGY-}" ]]; then
547 # Exit the infinite while loop if we made a reservation.
551 # Wait ~3minutes before next try.
552 sleep_time="$[ ( $RANDOM % 20 ) + 180 ]s" || {
553 die "Sleep time calculation failed."
555 echo "Sleeping ${sleep_time}"
556 sleep "${sleep_time}" || die "Sleep failed."
561 function run_pybot () {
566 # - CSIT_DIR - Path to existing root of local CSIT git repository.
567 # - ARCHIVE_DIR - Path to store robot result files in.
568 # - PYBOT_ARGS, EXPANDED_TAGS - See compose_pybot_arguments.sh
569 # - GENERATED_DIR - Tests are assumed to be generated under there.
571 # - PYBOT_EXIT_STATUS - Exit status of most recent pybot invocation.
573 # - die - Print to stderr and exit.
575 all_options=("--outputdir" "${ARCHIVE_DIR}" "${PYBOT_ARGS[@]}")
576 all_options+=("${EXPANDED_TAGS[@]}")
578 pushd "${CSIT_DIR}" || die "Change directory operation failed."
580 # TODO: Make robot tests not require "$(pwd)" == "${CSIT_DIR}".
581 pybot "${all_options[@]}" "${GENERATED_DIR}/tests/"
582 PYBOT_EXIT_STATUS="$?"
585 # Generate INFO level output_info.xml for post-processing.
586 all_options=("--loglevel" "INFO")
587 all_options+=("--log" "none")
588 all_options+=("--report" "none")
589 all_options+=("--output" "${ARCHIVE_DIR}/output_info.xml")
590 all_options+=("${ARCHIVE_DIR}/output.xml")
591 rebot "${all_options[@]}"
592 popd || die "Change directory operation failed."
596 function select_tags () {
601 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
602 # - TEST_CODE - String affecting test selection, usually jenkins job name.
603 # - TEST_TAG_STRING - String selecting tags, from gerrit comment.
605 # - TOPOLOGIES_DIR - Path to existing directory with available tpologies.
607 # - TAGS - Array of processed tag boolean expressions.
610 start_pattern='^ TG:'
611 end_pattern='^ \? \?[A-Za-z0-9]\+:'
612 # Remove the TG section from topology file
613 sed_command="/${start_pattern}/,/${end_pattern}/d"
614 # All topologies DUT NICs
615 available=$(sed "${sed_command}" "${TOPOLOGIES_DIR}"/* \
616 | grep -hoP "model: \K.*" | sort -u)
617 # Selected topology DUT NICs
618 reserved=$(sed "${sed_command}" "${WORKING_TOPOLOGY}" \
619 | grep -hoP "model: \K.*" | sort -u)
620 # All topologies DUT NICs - Selected topology DUT NICs
621 exclude_nics=($(comm -13 <(echo "${reserved}") <(echo "${available}")))
624 case "${TEST_CODE}" in
626 DEFAULT_NIC='nic_intel-x520-da2'
629 DEFAULT_NIC='nic_intel-x710'
633 case "${TEST_CODE}" in
634 # Select specific performance tests based on jenkins job type variable.
636 readarray -t test_tag_array < "${BASH_FUNCTION_DIR}/mlr-weekly.txt"
639 readarray -t test_tag_array < "${BASH_FUNCTION_DIR}/mrr-daily.txt"
642 readarray -t test_tag_array < "${BASH_FUNCTION_DIR}/mrr-weekly.txt"
645 if [[ -z "${TEST_TAG_STRING-}" ]]; then
646 # If nothing is specified, we will run pre-selected tests by
648 test_tag_array=("mrrAND${DEFAULT_NIC}AND1cAND64bANDip4base"
649 "mrrAND${DEFAULT_NIC}AND1cAND78bANDip6base"
650 "mrrAND${DEFAULT_NIC}AND1cAND64bANDl2bdbase"
651 "mrrAND${DEFAULT_NIC}AND1cAND64bANDl2xcbase"
654 # If trigger contains tags, split them into array.
655 test_tag_array=(${TEST_TAG_STRING//:/ })
660 # Blacklisting certain tags per topology.
661 case "${TEST_CODE}" in
663 test_tag_array+=("!ipsechw")
666 test_tag_array+=("!ipsechw")
667 # Not enough nic_intel-xxv710 to support double link tests.
668 test_tag_array+=("!3_node_double_link_topoANDnic_intel-xxv710")
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 # TODO: Introduce NOIOMMU version of AVF tests.
679 # TODO: Make (both) AVF tests work on Haswell,
680 # or document why (some of) it is not possible.
681 # https://github.com/FDio/vpp/blob/master/src/plugins/avf/README.md
682 test_tag_array+=("!drv_avf")
683 # All cards have access to QAT. But only one card (xl710)
684 # resides in same NUMA as QAT. Other cards must go over QPI
685 # which we do not want to even run.
686 test_tag_array+=("!ipsechwNOTnic_intel-xl710")
689 # Default to 3n-hsw due to compatibility.
690 test_tag_array+=("!drv_avf")
691 test_tag_array+=("!ipsechwNOTnic_intel-xl710")
695 # We will add excluded NICs.
696 test_tag_array+=("${exclude_nics[@]/#/!NIC_}")
700 # We will prefix with perftest to prevent running other tests
704 if [[ "${TEST_CODE}" == "vpp-"* ]]; then
705 # Automatic prefixing for VPP jobs to limit the NIC used and
706 # traffic evaluation to MRR.
707 if [[ "${TEST_TAG_STRING-}" == *"nic_"* ]]; then
708 prefix="${prefix}mrrAND"
710 prefix="${prefix}mrrAND${DEFAULT_NIC}AND"
713 for tag in "${test_tag_array[@]}"; do
714 if [[ "${tag}" == "!"* ]]; then
715 # Exclude tags are not prefixed.
717 elif [[ "${tag}" != "" && "${tag}" != "#"* ]]; then
718 # Empty and comment lines are skipped.
719 # Other lines are normal tags, they are to be prefixed.
720 TAGS+=("${prefix}${tag}")
727 function select_vpp_device_tags () {
732 # - TEST_CODE - String affecting test selection, usually jenkins job name.
733 # - TEST_TAG_STRING - String selecting tags, from gerrit comment.
736 # - TAGS - Array of processed tag boolean expressions.
738 case "${TEST_CODE}" in
739 # Select specific performance tests based on jenkins job type variable.
741 if [[ -z "${TEST_TAG_STRING-}" ]]; then
742 # If nothing is specified, we will run pre-selected tests by
743 # following tags. Items of array will be concatenated by OR
744 # in Robot Framework.
747 # If trigger contains tags, split them into array.
748 test_tag_array=(${TEST_TAG_STRING//:/ })
755 # We will prefix with perftest to prevent running other tests
757 prefix="devicetestAND"
758 if [[ "${TEST_CODE}" == "vpp-"* ]]; then
759 # Automatic prefixing for VPP jobs to limit testing.
762 for tag in "${test_tag_array[@]}"; do
763 if [[ ${tag} == "!"* ]]; then
764 # Exclude tags are not prefixed.
767 TAGS+=("${prefix}${tag}")
772 function select_os () {
777 # - VPP_VER_FILE - Name of File in CSIT dir containing vpp stable version.
778 # - IMAGE_VER_FILE - Name of File in CSIT dir containing the image name.
779 # - PKG_SUFFIX - Suffix of OS package file name, "rpm" or "deb."
781 os_id=$(grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g') || {
782 die "Get OS release failed."
787 IMAGE_VER_FILE="VPP_DEVICE_IMAGE_UBUNTU"
788 VPP_VER_FILE="VPP_STABLE_VER_UBUNTU_BIONIC"
792 IMAGE_VER_FILE="VPP_DEVICE_IMAGE_CENTOS"
793 VPP_VER_FILE="VPP_STABLE_VER_CENTOS"
797 die "Unable to identify distro or os from ${OS}"
803 function select_topology () {
808 # - NODENESS - Node multiplicity of testbed, either "2n" or "3n".
809 # - FLAVOR - Node flavor string, currently either "hsw" or "skx".
810 # - CSIT_DIR - Path to existing root of local CSIT git repository.
811 # - TOPOLOGIES_DIR - Path to existing directory with available topologies.
813 # - TOPOLOGIES - Array of paths to suitable topology yaml files.
814 # - TOPOLOGIES_TAGS - Tag expression selecting tests for the topology.
816 # - die - Print to stderr and exit.
818 case_text="${NODENESS}_${FLAVOR}"
819 case "${case_text}" in
820 # TODO: Move tags to "# Blacklisting certain tags per topology" section.
822 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*vpp_device*.template )
823 TOPOLOGIES_TAGS="2_node_single_link_topo"
826 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*vpp_device*.template )
827 TOPOLOGIES_TAGS="2_node_single_link_topo"
830 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_skx*.yaml )
831 TOPOLOGIES_TAGS="2_node_*_link_topo"
834 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_skx*.yaml )
835 TOPOLOGIES_TAGS="3_node_*_link_topo"
838 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_hsw*.yaml )
839 TOPOLOGIES_TAGS="3_node_single_link_topo"
842 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_tsh*.yaml )
843 TOPOLOGIES_TAGS="3_node_*_link_topo"
846 # No falling back to 3n_hsw default, that should have been done
847 # by the function which has set NODENESS and FLAVOR.
848 die "Unknown specification: ${case_text}"
851 if [[ -z "${TOPOLOGIES-}" ]]; then
852 die "No applicable topology found!"
857 function untrap_and_unreserve_testbed () {
858 # Use this as a trap function to ensure testbed does not remain reserved.
859 # Perhaps call directly before script exit, to free testbed for other jobs.
860 # This function is smart enough to avoid multiple unreservations (so safe).
861 # Topo cleanup is executed (call it best practice), ignoring failures.
864 # - default message to die with if testbed might remain reserved.
866 # - ${1} - Message to die with if unreservation fails. Default hardcoded.
867 # Variables read (by inner function):
868 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
869 # - PYTHON_SCRIPTS_DIR - Path to directory holding Python scripts.
871 # - WORKING_TOPOLOGY - Set to empty string on successful unreservation.
873 # - EXIT - Failure to untrap is reported, but ignored otherwise.
875 # - die - Print to stderr and exit.
878 set +eu # We do not want to exit early in a "teardown" function.
879 trap - EXIT || echo "Trap deactivation failed, continuing anyway."
880 wt="${WORKING_TOPOLOGY}" # Just to avoid too long lines.
881 if [[ -z "${wt-}" ]]; then
883 warn "Testbed looks unreserved already. Trap removal failed before?"
886 python "${PYTHON_SCRIPTS_DIR}/topo_reservation.py" -c -t "${wt}" || {
887 die "${1:-FAILED TO UNRESERVE, FIX MANUALLY.}" 2
896 # Print the message to standard error.
899 # - ${@} - The text of the message.