1 # Copyright (c) 2023 Cisco and/or its affiliates.
2 # Copyright (c) 2023 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 () {
27 # Create virtual vpp-device topology. Output of the function is topology
28 # file describing created environment saved to a file.
31 # - BASH_FUNCTION_DIR - Path to existing directory this file is located in.
32 # - TOPOLOGIES - Available topologies.
33 # - NODENESS - Node multiplicity of desired testbed.
34 # - FLAVOR - Node flavor string, usually describing the processor.
35 # - IMAGE_VER_FILE - Name of file that contains the image version.
36 # - CSIT_DIR - Directory where ${IMAGE_VER_FILE} is located.
38 # - WORKING_TOPOLOGY - Path to topology file.
42 source "${BASH_FUNCTION_DIR}/device.sh" || {
45 device_image="$(< ${CSIT_DIR}/${IMAGE_VER_FILE})"
46 case_text="${NODENESS}_${FLAVOR}"
47 case "${case_text}" in
48 "1n_skx" | "1n_tx2" | "1n_spr")
49 # We execute reservation over csit-shim-dcr (ssh) which runs sourced
50 # script's functions. Env variables are read from ssh output
51 # back to localhost for further processing.
52 # Shim and Jenkins executor are in the same network on the same host
53 # Connect to docker's default gateway IP and shim's exposed port
54 ssh="ssh root@172.17.0.1 -p 6022"
55 run="activate_wrapper ${NODENESS} ${FLAVOR} ${device_image}"
56 # The "declare -f" output is long and boring.
58 # backtics to avoid https://midnight-commander.org/ticket/2142
59 env_vars=`${ssh} "$(declare -f); ${run}"` || {
60 die "Topology reservation via shim-dcr failed!"
64 source <(echo "$env_vars" | grep -v /usr/bin/docker) || {
70 # We execute reservation on localhost. Sourced script automatially
71 # sets environment variables for further processing.
72 activate_wrapper "${NODENESS}" "${FLAVOR}" "${device_image}" || die
75 die "Unknown specification: ${case_text}!"
78 trap 'deactivate_docker_topology' EXIT || {
79 die "Trap attempt failed, please cleanup manually. Aborting!"
82 parse_env_variables || die "Parse of environment variables failed!"
84 # Replace all variables in template with those in environment.
85 source <(echo 'cat <<EOF >topo.yml'; cat ${TOPOLOGIES[0]}; echo EOF;) || {
86 die "Topology file create failed!"
89 WORKING_TOPOLOGY="${CSIT_DIR}/topologies/available/vpp_device.yaml"
90 mv topo.yml "${WORKING_TOPOLOGY}" || {
91 die "Topology move failed!"
93 cat ${WORKING_TOPOLOGY} | grep -v password || {
94 die "Topology read failed!"
99 function activate_virtualenv () {
101 # Update virtualenv pip package, delete and create virtualenv directory,
102 # activate the virtualenv, install requirements, set PYTHONPATH.
105 # - ${1} - Path to existing directory for creating virtualenv in.
106 # If missing or empty, ${CSIT_DIR} is used.
107 # - ${2} - Path to requirements file, ${CSIT_DIR}/requirements.txt if empty.
109 # - CSIT_DIR - Path to existing root of local CSIT git repository.
110 # Variables exported:
111 # - PYTHONPATH - CSIT_DIR, as CSIT Python scripts usually need this.
113 # - die - Print to stderr and exit.
117 root_path="${1-$CSIT_DIR}"
118 env_dir="${root_path}/env"
119 req_path=${2-$CSIT_DIR/requirements.txt}
120 rm -rf "${env_dir}" || die "Failed to clean previous virtualenv."
121 pip3 install virtualenv==20.15.1 || {
122 die "Virtualenv package install failed."
124 virtualenv --no-download --python=$(which python3) "${env_dir}" || {
125 die "Virtualenv creation for $(which python3) failed."
128 source "${env_dir}/bin/activate" || die "Virtualenv activation failed."
130 pip3 install -r "${req_path}" || {
131 die "Requirements installation failed."
133 # Most CSIT Python scripts assume PYTHONPATH is set and exported.
134 export PYTHONPATH="${CSIT_DIR}" || die "Export failed."
138 function archive_tests () {
140 # Create .tar.gz 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}/generated_tests.tar.gz - Archive of generated tests.
150 pushd "${ARCHIVE_DIR}" || die
151 tar czf "generated_tests.tar.gz" "${GENERATED_DIR}/tests" || true
156 function check_download_dir () {
158 # Fail if there are no files visible in ${DOWNLOAD_DIR}.
161 # - DOWNLOAD_DIR - Path to directory robot takes the build to test from.
163 # - ${DOWNLOAD_DIR} - Has to be non-empty to proceed.
165 # - die - Print to stderr and exit.
169 if [[ ! "$(ls -A "${DOWNLOAD_DIR}")" ]]; then
170 die "No artifacts downloaded!"
175 function check_prerequisites () {
177 # Fail if prerequisites are not met.
180 # - installed - Check if application is installed/present in system.
181 # - die - Print to stderr and exit.
185 if ! installed sshpass; then
186 die "Please install sshpass before continue!"
191 function common_dirs () {
193 # Set global variables, create some directories (without touching content).
196 # - BASH_FUNCTION_DIR - Path to existing directory this file is located in.
197 # - CSIT_DIR - Path to existing root of local CSIT git repository.
198 # - TOPOLOGIES_DIR - Path to existing directory with available topologies.
199 # - JOB_SPECS_DIR - Path to existing directory with job test specifications.
200 # - RESOURCES_DIR - Path to existing CSIT subdirectory "resources".
201 # - TOOLS_DIR - Path to existing resources subdirectory "tools".
202 # - PYTHON_SCRIPTS_DIR - Path to existing tools subdirectory "scripts".
203 # - ARCHIVE_DIR - Path to created CSIT subdirectory "archives".
204 # The name is chosen to match what ci-management expects.
205 # - DOWNLOAD_DIR - Path to created CSIT subdirectory "download_dir".
206 # - GENERATED_DIR - Path to created CSIT subdirectory "generated".
207 # Directories created if not present:
208 # ARCHIVE_DIR, DOWNLOAD_DIR, GENERATED_DIR.
210 # - die - Print to stderr and exit.
214 this_file=$(readlink -e "${BASH_SOURCE[0]}") || {
215 die "Some error during locating of this source file."
217 BASH_FUNCTION_DIR=$(dirname "${this_file}") || {
218 die "Some error during dirname call."
220 # Current working directory could be in a different repo, e.g. VPP.
221 pushd "${BASH_FUNCTION_DIR}" || die "Pushd failed"
222 relative_csit_dir=$(git rev-parse --show-toplevel) || {
223 die "Git rev-parse failed."
225 CSIT_DIR=$(readlink -e "${relative_csit_dir}") || die "Readlink failed."
226 popd || die "Popd failed."
227 TOPOLOGIES_DIR=$(readlink -e "${CSIT_DIR}/topologies/available") || {
228 die "Readlink failed."
230 JOB_SPECS_DIR=$(readlink -e "${CSIT_DIR}/resources/job_specs") || {
231 die "Readlink failed."
233 RESOURCES_DIR=$(readlink -e "${CSIT_DIR}/resources") || {
234 die "Readlink failed."
236 TOOLS_DIR=$(readlink -e "${RESOURCES_DIR}/tools") || {
237 die "Readlink failed."
239 PYTHON_SCRIPTS_DIR=$(readlink -e "${TOOLS_DIR}/scripts") || {
240 die "Readlink failed."
243 ARCHIVE_DIR=$(readlink -f "${CSIT_DIR}/archives") || {
244 die "Readlink failed."
246 mkdir -p "${ARCHIVE_DIR}" || die "Mkdir failed."
247 DOWNLOAD_DIR=$(readlink -f "${CSIT_DIR}/download_dir") || {
248 die "Readlink failed."
250 mkdir -p "${DOWNLOAD_DIR}" || die "Mkdir failed."
251 GENERATED_DIR=$(readlink -f "${CSIT_DIR}/generated") || {
252 die "Readlink failed."
254 mkdir -p "${GENERATED_DIR}" || die "Mkdir failed."
258 function compose_robot_arguments () {
261 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
262 # - DUT - CSIT test/ subdirectory, set while processing tags.
263 # - TAGS - Array variable holding selected tag boolean expressions.
264 # - TOPOLOGIES_TAGS - Tag boolean expression filtering tests for topology.
265 # - TEST_CODE - The test selection string from environment or argument.
266 # - SELECTION_MODE - Selection criteria [test, suite, include, exclude].
268 # - ROBOT_ARGS - String holding part of all arguments for robot.
269 # - EXPANDED_TAGS - Array of strings robot arguments compiled from tags.
273 # No explicit check needed with "set -u".
274 ROBOT_ARGS=("--loglevel" "TRACE")
275 ROBOT_ARGS+=("--variable" "TOPOLOGY_PATH:${WORKING_TOPOLOGY}")
277 case "${TEST_CODE}" in
279 ROBOT_ARGS+=("--suite" "tests.${DUT}.device")
282 ROBOT_ARGS+=("--suite" "tests.${DUT}.perf")
285 die "Unknown specification: ${TEST_CODE}"
289 for tag in "${TAGS[@]}"; do
290 if [[ ${tag} == "!"* ]]; then
291 EXPANDED_TAGS+=("--exclude" "${tag#$"!"}")
293 if [[ ${SELECTION_MODE} == "--test" ]]; then
294 EXPANDED_TAGS+=("--test" "${tag}")
296 EXPANDED_TAGS+=("--include" "${TOPOLOGIES_TAGS}AND${tag}")
301 if [[ ${SELECTION_MODE} == "--test" ]]; then
302 EXPANDED_TAGS+=("--include" "${TOPOLOGIES_TAGS}")
307 function deactivate_docker_topology () {
309 # Deactivate virtual vpp-device topology by removing containers.
312 # - NODENESS - Node multiplicity of desired testbed.
313 # - FLAVOR - Node flavor string, usually describing the processor.
317 case_text="${NODENESS}_${FLAVOR}"
318 case "${case_text}" in
319 "1n_skx" | "1n_tx2" | "1n_spr")
320 ssh="ssh root@172.17.0.1 -p 6022"
321 env_vars=$(env | grep CSIT_ | tr '\n' ' ' ) || die
322 # The "declare -f" output is long and boring.
324 ${ssh} "$(declare -f); deactivate_wrapper ${env_vars}" || {
325 die "Topology cleanup via shim-dcr failed!"
331 clean_environment || {
332 die "Topology cleanup locally failed!"
337 die "Unknown specification: ${case_text}!"
344 # Print the message to standard error end exit with error code specified
345 # by the second argument.
348 # - The default error message.
350 # - ${1} - The whole error message, be sure to quote. Optional
351 # - ${2} - the code to exit with, default: 1.
355 warn "${1:-Unspecified run-time error occurred!}"
360 function die_on_robot_error () {
362 # Source this fragment if you want to abort on any failed test case.
365 # - ROBOT_EXIT_STATUS - Set by a robot running fragment.
367 # - die - Print to stderr and exit.
371 if [[ "${ROBOT_EXIT_STATUS}" != "0" ]]; then
372 die "Test failures are present!" "${ROBOT_EXIT_STATUS}"
377 function generate_tests () {
379 # Populate ${GENERATED_DIR}/tests based on ${CSIT_DIR}/tests/.
380 # Any previously existing content of ${GENERATED_DIR}/tests is wiped before.
381 # The generation is done by executing any *.py executable
382 # within any subdirectory after copying.
384 # This is a separate function, because this code is called
385 # both by autogen checker and entries calling run_robot.
388 # - ${CSIT_DIR}/tests - Used as templates for the generated tests.
389 # Directories replaced:
390 # - ${GENERATED_DIR}/tests - Overwritten by the generated tests.
394 rm -rf "${GENERATED_DIR}/tests" || die
395 cp -r "${CSIT_DIR}/tests" "${GENERATED_DIR}/tests" || die
396 cmd_line=("find" "${GENERATED_DIR}/tests" "-type" "f")
397 cmd_line+=("-executable" "-name" "*.py")
398 # We sort the directories, so log output can be compared between runs.
399 file_list=$("${cmd_line[@]}" | sort) || 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 () {
414 # - ${1} - Optional, argument of entry script (or empty as unset).
415 # Test code value to override job name from environment.
417 # - JOB_NAME - String affecting test selection, default if not argument.
419 # - TEST_CODE - The test selection string from environment or argument.
420 # - NODENESS - Node multiplicity of desired testbed.
421 # - 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
535 function get_test_tag_string () {
538 # - GERRIT_EVENT_TYPE - Event type set by gerrit, can be unset.
539 # - GERRIT_EVENT_COMMENT_TEXT - Comment text, read for "comment-added" type.
540 # - TEST_CODE - The test selection string from environment or argument.
542 # - TEST_TAG_STRING - The string following trigger word in gerrit comment.
543 # May be empty, or even not set on event types not adding comment.
544 # Variables exported optionally:
545 # - GRAPH_NODE_VARIANT - Node variant to test with, set if found in trigger.
547 # TODO: ci-management scripts no longer need to perform this.
551 if [[ "${GERRIT_EVENT_TYPE-}" == "comment-added" ]]; then
552 case "${TEST_CODE}" in
560 die "Unknown specification: ${TEST_CODE}"
562 # Ignore lines not containing the trigger word.
563 comment=$(fgrep "${trigger}" <<< "${GERRIT_EVENT_COMMENT_TEXT}" || true)
564 # The vpp-csit triggers trail stuff we are not interested in.
565 # Removing them and trigger word: https://unix.stackexchange.com/a/13472
566 # (except relying on \s whitespace, \S non-whitespace and . both).
567 # The last string is concatenated, only the middle part is expanded.
568 cmd=("grep" "-oP" '\S*'"${trigger}"'\S*\s\K.+$') || die "Unset trigger?"
569 # On parsing error, TEST_TAG_STRING probably stays empty.
570 TEST_TAG_STRING=$("${cmd[@]}" <<< "${comment}" || true)
571 if [[ -z "${TEST_TAG_STRING-}" ]]; then
572 # Probably we got a base64 encoded comment.
573 comment="${GERRIT_EVENT_COMMENT_TEXT}"
574 comment=$(base64 --decode <<< "${comment}" || true)
575 comment=$(fgrep "${trigger}" <<< "${comment}" || true)
576 TEST_TAG_STRING=$("${cmd[@]}" <<< "${comment}" || true)
578 if [[ -n "${TEST_TAG_STRING-}" ]]; then
579 test_tag_array=(${TEST_TAG_STRING})
580 if [[ "${test_tag_array[0]}" == "icl" ]]; then
581 export GRAPH_NODE_VARIANT="icl"
582 TEST_TAG_STRING="${test_tag_array[@]:1}" || true
583 elif [[ "${test_tag_array[0]}" == "skx" ]]; then
584 export GRAPH_NODE_VARIANT="skx"
585 TEST_TAG_STRING="${test_tag_array[@]:1}" || true
592 function installed () {
594 # Check if the given utility is installed. Fail if not installed.
596 # Duplicate of common.sh function, as this file is also used standalone.
599 # - ${1} - Utility to check.
601 # - 0 - If command is installed.
602 # - 1 - If command is not installed.
610 function move_archives () {
612 # Move archive directory to top of workspace, if not already there.
614 # ARCHIVE_DIR is positioned relative to CSIT_DIR,
615 # but in some jobs CSIT_DIR is not same as WORKSPACE
616 # (e.g. under VPP_DIR). To simplify ci-management settings,
617 # we want to move the data to the top. We do not want simple copy,
618 # as ci-management is eager with recursive search.
620 # As some scripts may call this function multiple times,
621 # the actual implementation use copying and deletion,
622 # so the workspace gets "union" of contents (except overwrites on conflict).
623 # The consequence is empty ARCHIVE_DIR remaining after this call.
625 # As the source directory is emptied,
626 # the check for dirs being different is essential.
629 # - WORKSPACE - Jenkins workspace, move only if the value is not empty.
630 # Can be unset, then it speeds up manual testing.
631 # - ARCHIVE_DIR - Path to directory with content to be moved.
632 # Directories updated:
633 # - ${WORKSPACE}/archives/ - Created if does not exist.
634 # Content of ${ARCHIVE_DIR}/ is moved.
636 # - die - Print to stderr and exit.
640 if [[ -n "${WORKSPACE-}" ]]; then
641 target=$(readlink -f "${WORKSPACE}/archives")
642 if [[ "${target}" != "${ARCHIVE_DIR}" ]]; then
643 mkdir -p "${target}" || die "Archives dir create failed."
644 cp -rf "${ARCHIVE_DIR}"/* "${target}" || die "Copy failed."
645 rm -rf "${ARCHIVE_DIR}"/* || die "Delete failed."
651 function prepare_topology () {
653 # Prepare virtual testbed topology if needed based on flavor.
656 # - TEST_CODE - String affecting test selection, usually jenkins job name.
657 # - NODENESS - Node multiplicity of testbed, either "2n" or "3n".
658 # - FLAVOR - Node flavor string, e.g. "clx" or "skx".
660 # - TERRAFORM_MODULE_DIR - Terraform module directory.
662 # - die - Print to stderr and exit.
663 # - terraform_init - Terraform init topology.
664 # - terraform_apply - Terraform apply topology.
668 case_text="${NODENESS}_${FLAVOR}"
669 case "${case_text}" in
670 "1n_aws" | "2n_aws" | "3n_aws")
671 export TF_VAR_testbed_name="${TEST_CODE}"
672 TERRAFORM_MODULE_DIR="terraform-aws-${NODENESS}-${FLAVOR}-c5n"
673 terraform_init || die "Failed to call terraform init."
674 trap "terraform_destroy" ERR EXIT || {
675 die "Trap attempt failed, please cleanup manually. Aborting!"
677 terraform_apply || die "Failed to call terraform apply."
679 "1n_c6gn" | "2n_c6gn" | "3n_c6gn")
680 export TF_VAR_testbed_name="${TEST_CODE}"
681 TERRAFORM_MODULE_DIR="terraform-aws-${NODENESS}-c6gn"
682 terraform_init || die "Failed to call terraform init."
683 trap "terraform_destroy" ERR EXIT || {
684 die "Trap attempt failed, please cleanup manually. Aborting!"
686 terraform_apply || die "Failed to call terraform apply."
688 "1n_c6in" | "2n_c6in" | "3n_c6in")
689 export TF_VAR_testbed_name="${TEST_CODE}"
690 TERRAFORM_MODULE_DIR="terraform-aws-${NODENESS}-c6in"
691 terraform_init || die "Failed to call terraform init."
692 trap "terraform_destroy" ERR EXIT || {
693 die "Trap attempt failed, please cleanup manually. Aborting!"
695 terraform_apply || die "Failed to call terraform apply."
701 function reserve_and_cleanup_testbed () {
703 # Reserve physical testbed, perform cleanup, register trap to unreserve.
704 # When cleanup fails, remove from topologies and keep retrying
705 # until all topologies are removed.
708 # - TOPOLOGIES - Array of paths to topology yaml to attempt reservation on.
709 # - PYTHON_SCRIPTS_DIR - Path to directory holding the reservation script.
710 # - BUILD_TAG - Any string suitable as filename, identifying
711 # test run executing this function. May be unset.
713 # - TOPOLOGIES - Array of paths to topologies, with failed cleanups removed.
714 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
716 # - die - Print to stderr and exit.
717 # - ansible_playbook - Perform an action using ansible, see ansible.sh
719 # - EXIT - Calls cancel_all for ${WORKING_TOPOLOGY}.
724 for topo in "${TOPOLOGIES[@]}"; do
726 scrpt="${PYTHON_SCRIPTS_DIR}/topo_reservation.py"
727 opts=("-t" "${topo}" "-r" "${BUILD_TAG:-Unknown}")
728 python3 "${scrpt}" "${opts[@]}"
731 if [[ "${result}" == "0" ]]; then
732 # Trap unreservation before cleanup check,
733 # so multiple jobs showing failed cleanup improve chances
734 # of humans to notice and fix.
735 WORKING_TOPOLOGY="${topo}"
736 echo "Reserved: ${WORKING_TOPOLOGY}"
737 trap "untrap_and_unreserve_testbed" EXIT || {
738 message="TRAP ATTEMPT AND UNRESERVE FAILED, FIX MANUALLY."
739 untrap_and_unreserve_testbed "${message}" || {
740 die "Teardown should have died, not failed."
742 die "Trap attempt failed, unreserve succeeded. Aborting."
744 # Cleanup + calibration checks
746 ansible_playbook "cleanup, calibration"
749 if [[ "${result}" == "0" ]]; then
752 warn "Testbed cleanup failed: ${topo}"
753 untrap_and_unreserve_testbed "Fail of unreserve after cleanup."
755 # Else testbed is accessible but currently reserved, moving on.
758 if [[ -n "${WORKING_TOPOLOGY-}" ]]; then
759 # Exit the infinite while loop if we made a reservation.
760 warn "Reservation and cleanup successful."
764 if [[ "${#TOPOLOGIES[@]}" == "0" ]]; then
765 die "Run out of operational testbeds!"
768 # Wait ~3minutes before next try.
769 sleep_time="$[ ( ${RANDOM} % 20 ) + 180 ]s" || {
770 die "Sleep time calculation failed."
772 echo "Sleeping ${sleep_time}"
773 sleep "${sleep_time}" || die "Sleep failed."
778 function run_robot () {
780 # Run robot with options based on input variables.
783 # - CSIT_DIR - Path to existing root of local CSIT git repository.
784 # - ARCHIVE_DIR - Path to store robot result files in.
785 # - ROBOT_ARGS, EXPANDED_TAGS - See compose_robot_arguments.sh
786 # - GENERATED_DIR - Tests are assumed to be generated under there.
788 # - ROBOT_EXIT_STATUS - Exit status of most recent robot invocation.
790 # - die - Print to stderr and exit.
794 all_options=("--outputdir" "${ARCHIVE_DIR}" "${ROBOT_ARGS[@]}")
795 all_options+=("${EXPANDED_TAGS[@]}")
797 pushd "${CSIT_DIR}" || die "Change directory operation failed."
799 robot "${all_options[@]}" "${GENERATED_DIR}/tests/"
800 ROBOT_EXIT_STATUS="$?"
803 popd || die "Change directory operation failed."
807 function select_arch_os () {
809 # Set variables affected by local CPU architecture and operating system.
812 # - VPP_VER_FILE - Name of file in CSIT dir containing vpp stable version.
813 # - IMAGE_VER_FILE - Name of file in CSIT dir containing the image name.
814 # - PKG_SUFFIX - Suffix of OS package file name, "rpm" or "deb."
818 source /etc/os-release || die "Get OS release failed."
823 *"LTS (Jammy Jellyfish)"*)
824 IMAGE_VER_FILE="VPP_DEVICE_IMAGE_UBUNTU_JAMMY"
825 VPP_VER_FILE="VPP_STABLE_VER_UBUNTU_JAMMY"
829 die "Unsupported Ubuntu version!"
834 die "Unsupported distro or OS!"
838 arch=$(uname -m) || {
839 die "Get CPU architecture failed."
844 IMAGE_VER_FILE="${IMAGE_VER_FILE}_ARM"
852 function select_tags () {
855 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
856 # - TEST_CODE - String affecting test selection, usually jenkins job name.
857 # - DUT - CSIT test/ subdirectory, set while processing tags.
858 # - TEST_TAG_STRING - String selecting tags, from gerrit comment.
860 # - TOPOLOGIES_DIR - Path to existing directory with available tpologies.
861 # - BASH_FUNCTION_DIR - Directory with input files to process.
863 # - TAGS - Array of processed tag boolean expressions.
864 # - SELECTION_MODE - Selection criteria [test, suite, include, exclude].
869 case "${TEST_CODE}" in
870 *"1n-aws"* | *"1n-c6gn"* | *"1n-c6in"*)
871 start_pattern='^ SUT:'
874 start_pattern='^ TG:'
877 end_pattern='^ \? \?[A-Za-z0-9]\+:'
878 # Remove the sections from topology file
879 sed_command="/${start_pattern}/,/${end_pattern}/d"
880 # All topologies NICs
881 available=$(sed "${sed_command}" "${TOPOLOGIES_DIR}"/* \
882 | grep -hoP "model: \K.*" | sort -u)
883 # Selected topology NICs
884 reserved=$(sed "${sed_command}" "${WORKING_TOPOLOGY}" \
885 | grep -hoP "model: \K.*" | sort -u)
886 # All topologies NICs - Selected topology NICs
887 exclude_nics=($(comm -13 <(echo "${reserved}") <(echo "${available}"))) || {
888 die "Computation of excluded NICs failed."
891 # Select default NIC tag.
892 case "${TEST_CODE}" in
894 default_nic="nic_intel-e822cq"
897 default_nic="nic_intel-e823c"
900 default_nic="nic_intel-x520-da2"
902 *"3n-icx"* | *"2n-icx"*)
903 default_nic="nic_intel-e810cq"
906 default_nic="nic_mellanox-cx7veat"
909 default_nic="nic_intel-e810cq"
912 default_nic="nic_intel-e810cq"
914 *"2n-clx"* | *"2n-zn2"*)
915 default_nic="nic_intel-xxv710"
917 *"2n-tx2"* | *"3n-alt"*)
918 default_nic="nic_intel-xl710"
920 *"1n-aws"* | *"2n-aws"* | *"3n-aws"*)
921 default_nic="nic_amazon-nitro-50g"
923 *"1n-c6gn"* | *"2n-c6gn"* | *"3n-c6gn"*)
924 default_nic="nic_amazon-nitro-100g"
926 *"1n-c6in"* | *"2n-c6in"* | *"3n-c6in"*)
927 default_nic="nic_amazon-nitro-200g"
930 default_nic="nic_intel-x710"
934 sed_nic_sub_cmd="sed s/\${default_nic}/${default_nic}/"
936 awk_nics_sub_cmd+='gsub("xxv710","25ge2p1xxv710");'
937 awk_nics_sub_cmd+='gsub("x710","10ge2p1x710");'
938 awk_nics_sub_cmd+='gsub("xl710","40ge2p1xl710");'
939 awk_nics_sub_cmd+='gsub("x520-da2","10ge2p1x520");'
940 awk_nics_sub_cmd+='gsub("cx556a","100ge2p1cx556a");'
941 awk_nics_sub_cmd+='gsub("cx7veat","200ge2p1cx7veat");'
942 awk_nics_sub_cmd+='gsub("cx6dx","100ge2p1cx6dx");'
943 awk_nics_sub_cmd+='gsub("e810cq","100ge2p1e810cq");'
944 awk_nics_sub_cmd+='gsub("e822cq","25ge2p1e822cq)'
945 awk_nics_sub_cmd+='gsub("e823c","25ge2p1e823c)'
946 awk_nics_sub_cmd+='gsub("vic1227","10ge2p1vic1227");'
947 awk_nics_sub_cmd+='gsub("vic1385","40ge2p1vic1385");'
948 awk_nics_sub_cmd+='gsub("nitro-50g","50ge1p1ENA");'
949 awk_nics_sub_cmd+='gsub("nitro-100g","100ge1p1ENA");'
950 awk_nics_sub_cmd+='gsub("nitro-200g","200ge1p1ENA");'
951 awk_nics_sub_cmd+='gsub("virtual","1ge1p82540em");'
952 awk_nics_sub_cmd+='if ($9 =="drv_avf") drv="avf-";'
953 awk_nics_sub_cmd+='else if ($9 =="drv_rdma_core") drv ="rdma-";'
954 awk_nics_sub_cmd+='else if ($9 =="drv_mlx5_core") drv ="mlx5-";'
955 awk_nics_sub_cmd+='else if ($9 =="drv_af_xdp") drv ="af-xdp-";'
956 awk_nics_sub_cmd+='else drv="";'
957 awk_nics_sub_cmd+='if ($1 =="-") cores="";'
958 awk_nics_sub_cmd+='else cores=$1;'
959 awk_nics_sub_cmd+='print "*"$7"-" drv $11"-"$5"."$3"-" cores "-" drv $11"-"$5'
961 # Tag file directory shorthand.
962 tfd="${JOB_SPECS_DIR}"
963 case "${TEST_CODE}" in
964 # Select specific performance tests based on jenkins job type variable.
966 readarray -t test_tag_array <<< $(grep -v "#" \
967 ${tfd}/vpp_device/${DUT}-${NODENESS}-${FLAVOR}.md |
968 awk {"$awk_nics_sub_cmd"} || echo "devicetest") || die
969 SELECTION_MODE="--test"
971 *"hoststack-daily"* )
972 readarray -t test_tag_array <<< $(grep -v "#" \
973 ${tfd}/hoststack_daily/${DUT}-${NODENESS}-${FLAVOR}.md |
974 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
975 SELECTION_MODE="--test"
978 readarray -t test_tag_array <<< $(grep -v "#" \
979 ${tfd}/ndrpdr_weekly/${DUT}-${NODENESS}-${FLAVOR}.md |
980 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
981 SELECTION_MODE="--test"
984 readarray -t test_tag_array <<< $(grep -v "#" \
985 ${tfd}/mrr_daily/${DUT}-${NODENESS}-${FLAVOR}.md |
986 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
987 SELECTION_MODE="--test"
990 readarray -t test_tag_array <<< $(grep -v "#" \
991 ${tfd}/mrr_weekly/${DUT}-${NODENESS}-${FLAVOR}.md |
992 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
993 SELECTION_MODE="--test"
995 *"report-iterative"* )
996 test_sets=(${TEST_TAG_STRING//:/ })
997 # Run only one test set per run
998 report_file=${test_sets[0]}.md
999 readarray -t test_tag_array <<< $(grep -v "#" \
1000 ${tfd}/report_iterative/${NODENESS}-${FLAVOR}/${report_file} |
1001 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
1002 SELECTION_MODE="--test"
1004 *"report-coverage"* )
1005 test_sets=(${TEST_TAG_STRING//:/ })
1006 # Run only one test set per run
1007 report_file=${test_sets[0]}.md
1008 readarray -t test_tag_array <<< $(grep -v "#" \
1009 ${tfd}/report_coverage/${NODENESS}-${FLAVOR}/${report_file} |
1010 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
1011 SELECTION_MODE="--test"
1014 if [[ -z "${TEST_TAG_STRING-}" ]]; then
1015 # If nothing is specified, we will run pre-selected tests by
1017 test_tag_array=("mrrAND${default_nic}AND1cAND64bANDethip4-ip4base"
1018 "mrrAND${default_nic}AND1cAND78bANDethip6-ip6base"
1019 "mrrAND${default_nic}AND1cAND64bANDeth-l2bdbasemaclrn"
1020 "mrrAND${default_nic}AND1cAND64bANDeth-l2xcbase"
1021 "!drv_af_xdp" "!drv_avf")
1023 # If trigger contains tags, split them into array.
1024 test_tag_array=(${TEST_TAG_STRING//:/ })
1026 SELECTION_MODE="--include"
1030 # Blacklisting certain tags per topology.
1032 # Reasons for blacklisting:
1033 # - ipsechw - Blacklisted on testbeds without crypto hardware accelerator.
1034 case "${TEST_CODE}" in
1036 test_tag_array+=("!avf")
1037 test_tag_array+=("!vhost")
1038 test_tag_array+=("!flow")
1041 test_tag_array+=("!flow")
1044 test_tag_array+=("!ipsechw")
1047 test_tag_array+=("!ipsechw")
1052 test_tag_array+=("!ipsechw")
1055 test_tag_array+=("!ipsechw")
1058 test_tag_array+=("!ipsechw")
1061 test_tag_array+=("!ipsechw")
1062 test_tag_array+=("!3_node_double_link_topoANDnic_intel-xxv710")
1073 test_tag_array+=("!drv_avf")
1074 test_tag_array+=("!ipsechw")
1076 *"1n-aws"* | *"2n-aws"* | *"3n-aws"*)
1077 test_tag_array+=("!ipsechw")
1079 *"1n-c6gn"* | *"2n-c6gn"* | *"3n-c6gn"*)
1080 test_tag_array+=("!ipsechw")
1082 *"1n-c6in"* | *"2n-c6in"* | *"3n-c6in"*)
1083 test_tag_array+=("!ipsechw")
1087 # We will add excluded NICs.
1088 test_tag_array+=("${exclude_nics[@]/#/!NIC_}")
1092 if [[ "${TEST_CODE}" == "vpp-"* ]]; then
1093 if [[ "${TEST_CODE}" != *"device"* ]]; then
1094 # Automatic prefixing for VPP perf jobs to limit the NIC used.
1095 if [[ "${TEST_TAG_STRING-}" != *"nic_"* ]]; then
1096 prefix="${default_nic}AND"
1101 for tag in "${test_tag_array[@]}"; do
1102 if [[ "${tag}" == "!"* ]]; then
1103 # Exclude tags are not prefixed.
1105 elif [[ "${tag}" == " "* || "${tag}" == *"perftest"* ]]; then
1106 # Badly formed tag expressions can trigger way too much tests.
1108 warn "The following tag expression hints at bad trigger: ${tag}"
1109 warn "Possible cause: Multiple triggers in a single comment."
1110 die "Aborting to avoid triggering too many tests."
1111 elif [[ "${tag}" == *"OR"* ]]; then
1112 # If OR had higher precedence than AND, it would be useful here.
1113 # Some people think it does, thus triggering way too much tests.
1115 warn "The following tag expression hints at bad trigger: ${tag}"
1116 warn "Operator OR has lower precedence than AND. Use space instead."
1117 die "Aborting to avoid triggering too many tests."
1118 elif [[ "${tag}" != "" && "${tag}" != "#"* ]]; then
1119 # Empty and comment lines are skipped.
1120 # Other lines are normal tags, they are to be prefixed.
1121 TAGS+=("${prefix}${tag}")
1128 function select_topology () {
1131 # - NODENESS - Node multiplicity of testbed, either "2n" or "3n".
1132 # - FLAVOR - Node flavor string, e.g. "clx" or "skx".
1133 # - CSIT_DIR - Path to existing root of local CSIT git repository.
1134 # - TOPOLOGIES_DIR - Path to existing directory with available topologies.
1136 # - TOPOLOGIES - Array of paths to suitable topology yaml files.
1137 # - TOPOLOGIES_TAGS - Tag expression selecting tests for the topology.
1139 # - die - Print to stderr and exit.
1143 case_text="${NODENESS}_${FLAVOR}"
1144 case "${case_text}" in
1146 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*vpp_device*.template )
1147 TOPOLOGIES_TAGS="2_node_single_link_topo"
1149 "1n_skx" | "1n_tx2" | "1n_spr")
1150 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*vpp_device*.template )
1151 TOPOLOGIES_TAGS="2_node_single_link_topo"
1154 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_skx*.yaml )
1155 TOPOLOGIES_TAGS="2_node_*_link_topo"
1158 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_zn2*.yaml )
1159 TOPOLOGIES_TAGS="2_node_*_link_topo"
1162 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_skx*.yaml )
1163 TOPOLOGIES_TAGS="3_node_*_link_topo"
1166 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_icx*.yaml )
1167 TOPOLOGIES_TAGS="3_node_*_link_topo"
1170 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3na_spr*.yaml )
1171 TOPOLOGIES_TAGS="3_node_*_link_topo"
1174 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3nb_spr*.yaml )
1175 TOPOLOGIES_TAGS="3_node_*_link_topo"
1178 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_clx*.yaml )
1179 TOPOLOGIES_TAGS="2_node_*_link_topo"
1182 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_icx*.yaml )
1183 TOPOLOGIES_TAGS="2_node_*_link_topo"
1186 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_spr*.yaml )
1187 TOPOLOGIES_TAGS="2_node_*_link_topo"
1190 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_snr*.yaml )
1191 TOPOLOGIES_TAGS="3_node_single_link_topo"
1194 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_icxd*.yaml )
1195 TOPOLOGIES_TAGS="3_node_single_link_topo"
1198 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_tsh*.yaml )
1199 TOPOLOGIES_TAGS="3_node_single_link_topo"
1202 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_tx2*.yaml )
1203 TOPOLOGIES_TAGS="2_node_single_link_topo"
1206 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_alt*.yaml )
1207 TOPOLOGIES_TAGS="3_node_single_link_topo"
1210 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*1n-aws*.yaml )
1211 TOPOLOGIES_TAGS="1_node_single_link_topo"
1214 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n-aws*.yaml )
1215 TOPOLOGIES_TAGS="2_node_single_link_topo"
1218 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n-aws*.yaml )
1219 TOPOLOGIES_TAGS="3_node_single_link_topo"
1222 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*1n-c6gn*.yaml )
1223 TOPOLOGIES_TAGS="1_node_single_link_topo"
1226 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n-c6gn*.yaml )
1227 TOPOLOGIES_TAGS="2_node_single_link_topo"
1230 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n-c6gn*.yaml )
1231 TOPOLOGIES_TAGS="3_node_single_link_topo"
1234 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*1n-c6in*.yaml )
1235 TOPOLOGIES_TAGS="1_node_single_link_topo"
1238 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n-c6in*.yaml )
1239 TOPOLOGIES_TAGS="2_node_single_link_topo"
1242 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n-c6in*.yaml )
1243 TOPOLOGIES_TAGS="3_node_single_link_topo"
1246 # No falling back to default, that should have been done
1247 # by the function which has set NODENESS and FLAVOR.
1248 die "Unknown specification: ${case_text}"
1251 if [[ -z "${TOPOLOGIES-}" ]]; then
1252 die "No applicable topology found!"
1257 function set_environment_variables () {
1259 # Depending on testbed topology, overwrite defaults set in the
1260 # resources/libraries/python/Constants.py file
1263 # - TEST_CODE - String affecting test selection, usually jenkins job name.
1265 # See specific cases
1269 case "${TEST_CODE}" in
1270 *"1n-aws"* | *"2n-aws"* | *"3n-aws"*)
1271 export TREX_RX_DESCRIPTORS_COUNT=1024
1272 export TREX_EXTRA_CMDLINE="--mbuf-factor 19"
1273 export TREX_CORE_COUNT=6
1274 # Settings to prevent duration stretching.
1275 export PERF_TRIAL_STL_DELAY=0.1
1277 *"1n-c6gn"* | *"2n-c6gn"* | *"3n-c6gn"*)
1278 export TREX_RX_DESCRIPTORS_COUNT=1024
1279 export TREX_EXTRA_CMDLINE="--mbuf-factor 19"
1280 export TREX_CORE_COUNT=6
1281 # Settings to prevent duration stretching.
1282 export PERF_TRIAL_STL_DELAY=0.1
1284 *"1n-c6in"* | *"2n-c6in"* | *"3n-c6in"*)
1285 export TREX_RX_DESCRIPTORS_COUNT=1024
1286 export TREX_EXTRA_CMDLINE="--mbuf-factor 19"
1287 export TREX_CORE_COUNT=6
1288 # Settings to prevent duration stretching.
1289 export PERF_TRIAL_STL_DELAY=0.1
1292 # Maciek's workaround for Zen2 with lower amount of cores.
1293 export TREX_CORE_COUNT=14
1298 function untrap_and_unreserve_testbed () {
1300 # Use this as a trap function to ensure testbed does not remain reserved.
1301 # Perhaps call directly before script exit, to free testbed for other jobs.
1302 # This function is smart enough to avoid multiple unreservations (so safe).
1303 # Topo cleanup is executed (call it best practice), ignoring failures.
1306 # - default message to die with if testbed might remain reserved.
1308 # - ${1} - Message to die with if unreservation fails. Default hardcoded.
1309 # Variables read (by inner function):
1310 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
1311 # - PYTHON_SCRIPTS_DIR - Path to directory holding Python scripts.
1313 # - TERRAFORM_MODULE_DIR - Terraform module directory.
1314 # - WORKING_TOPOLOGY - Set to empty string on successful unreservation.
1315 # Trap unregistered:
1316 # - EXIT - Failure to untrap is reported, but ignored otherwise.
1318 # - die - Print to stderr and exit.
1319 # - ansible_playbook - Perform an action using ansible, see ansible.sh
1322 set +eu # We do not want to exit early in a "teardown" function.
1323 trap - EXIT || echo "Trap deactivation failed, continuing anyway."
1324 wt="${WORKING_TOPOLOGY}" # Just to avoid too long lines.
1325 if [[ -z "${wt-}" ]]; then
1327 warn "Testbed looks unreserved already. Trap removal failed before?"
1329 ansible_playbook "cleanup" || true
1330 python3 "${PYTHON_SCRIPTS_DIR}/topo_reservation.py" -c -t "${wt}" || {
1331 die "${1:-FAILED TO UNRESERVE, FIX MANUALLY.}" 2
1333 case "${TEST_CODE}" in
1334 *"1n-aws"* | *"2n-aws"* | *"3n-aws"*)
1335 TERRAFORM_MODULE_DIR="terraform-aws-${NODENESS}-${FLAVOR}-c5n"
1336 terraform_destroy || die "Failed to call terraform destroy."
1338 *"1n-c6gn"* | *"2n-c6gn"* | *"3n-c6gn"*)
1339 TERRAFORM_MODULE_DIR="terraform-aws-${NODENESS}-${FLAVOR}"
1340 terraform_destroy || die "Failed to call terraform destroy."
1342 *"1n-c6in"* | *"2n-c6in"* | *"3n-c6in"*)
1343 TERRAFORM_MODULE_DIR="terraform-aws-${NODENESS}-${FLAVOR}"
1344 terraform_destroy || die "Failed to call terraform destroy."
1357 # Print the message to standard error.
1360 # - ${@} - The text of the message.