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!"
97 # Subfunctions to update data that may depend on topology reserved.
98 set_environment_variables || die
100 compose_robot_arguments || die
105 function activate_virtualenv () {
107 # Update virtualenv pip package, delete and create virtualenv directory,
108 # activate the virtualenv, install requirements, set PYTHONPATH.
111 # - ${1} - Path to existing directory for creating virtualenv in.
112 # If missing or empty, ${CSIT_DIR} is used.
113 # - ${2} - Path to requirements file, ${CSIT_DIR}/requirements.txt if empty.
115 # - CSIT_DIR - Path to existing root of local CSIT git repository.
116 # Variables exported:
117 # - PYTHONPATH - CSIT_DIR, as CSIT Python scripts usually need this.
119 # - die - Print to stderr and exit.
123 root_path="${1-$CSIT_DIR}"
124 env_dir="${root_path}/env"
125 req_path=${2-$CSIT_DIR/requirements.txt}
126 rm -rf "${env_dir}" || die "Failed to clean previous virtualenv."
127 pip3 install virtualenv==20.15.1 || {
128 die "Virtualenv package install failed."
130 virtualenv --no-download --python=$(which python3) "${env_dir}" || {
131 die "Virtualenv creation for $(which python3) failed."
134 source "${env_dir}/bin/activate" || die "Virtualenv activation failed."
136 pip3 install -r "${req_path}" || {
137 die "Requirements installation failed."
139 # Most CSIT Python scripts assume PYTHONPATH is set and exported.
140 export PYTHONPATH="${CSIT_DIR}" || die "Export failed."
144 function archive_tests () {
146 # Create .tar.gz of generated/tests for archiving.
147 # To be run after generate_tests, kept separate to offer more flexibility.
150 # - ${GENERATED_DIR}/tests - Tree of executed suites to archive.
152 # - ${ARCHIVE_DIR}/generated_tests.tar.gz - Archive of generated tests.
156 pushd "${ARCHIVE_DIR}" || die
157 tar czf "generated_tests.tar.gz" "${GENERATED_DIR}/tests" || true
162 function check_download_dir () {
164 # Fail if there are no files visible in ${DOWNLOAD_DIR}.
167 # - DOWNLOAD_DIR - Path to directory robot takes the build to test from.
169 # - ${DOWNLOAD_DIR} - Has to be non-empty to proceed.
171 # - die - Print to stderr and exit.
175 if [[ ! "$(ls -A "${DOWNLOAD_DIR}")" ]]; then
176 die "No artifacts downloaded!"
181 function check_prerequisites () {
183 # Fail if prerequisites are not met.
186 # - installed - Check if application is installed/present in system.
187 # - die - Print to stderr and exit.
191 if ! installed sshpass; then
192 die "Please install sshpass before continue!"
197 function common_dirs () {
199 # Set global variables, create some directories (without touching content).
202 # - BASH_FUNCTION_DIR - Path to existing directory this file is located in.
203 # - CSIT_DIR - Path to existing root of local CSIT git repository.
204 # - TOPOLOGIES_DIR - Path to existing directory with available topologies.
205 # - JOB_SPECS_DIR - Path to existing directory with job test specifications.
206 # - RESOURCES_DIR - Path to existing CSIT subdirectory "resources".
207 # - TOOLS_DIR - Path to existing resources subdirectory "tools".
208 # - PYTHON_SCRIPTS_DIR - Path to existing tools subdirectory "scripts".
209 # - ARCHIVE_DIR - Path to created CSIT subdirectory "archives".
210 # The name is chosen to match what ci-management expects.
211 # - DOWNLOAD_DIR - Path to created CSIT subdirectory "download_dir".
212 # - GENERATED_DIR - Path to created CSIT subdirectory "generated".
213 # Directories created if not present:
214 # ARCHIVE_DIR, DOWNLOAD_DIR, GENERATED_DIR.
216 # - die - Print to stderr and exit.
220 this_file=$(readlink -e "${BASH_SOURCE[0]}") || {
221 die "Some error during locating of this source file."
223 BASH_FUNCTION_DIR=$(dirname "${this_file}") || {
224 die "Some error during dirname call."
226 # Current working directory could be in a different repo, e.g. VPP.
227 pushd "${BASH_FUNCTION_DIR}" || die "Pushd failed"
228 relative_csit_dir=$(git rev-parse --show-toplevel) || {
229 die "Git rev-parse failed."
231 CSIT_DIR=$(readlink -e "${relative_csit_dir}") || die "Readlink failed."
232 popd || die "Popd failed."
233 TOPOLOGIES_DIR=$(readlink -e "${CSIT_DIR}/topologies/available") || {
234 die "Readlink failed."
236 JOB_SPECS_DIR=$(readlink -e "${CSIT_DIR}/resources/job_specs") || {
237 die "Readlink failed."
239 RESOURCES_DIR=$(readlink -e "${CSIT_DIR}/resources") || {
240 die "Readlink failed."
242 TOOLS_DIR=$(readlink -e "${RESOURCES_DIR}/tools") || {
243 die "Readlink failed."
245 PYTHON_SCRIPTS_DIR=$(readlink -e "${TOOLS_DIR}/scripts") || {
246 die "Readlink failed."
249 ARCHIVE_DIR=$(readlink -f "${CSIT_DIR}/archives") || {
250 die "Readlink failed."
252 mkdir -p "${ARCHIVE_DIR}" || die "Mkdir failed."
253 DOWNLOAD_DIR=$(readlink -f "${CSIT_DIR}/download_dir") || {
254 die "Readlink failed."
256 mkdir -p "${DOWNLOAD_DIR}" || die "Mkdir failed."
257 GENERATED_DIR=$(readlink -f "${CSIT_DIR}/generated") || {
258 die "Readlink failed."
260 mkdir -p "${GENERATED_DIR}" || die "Mkdir failed."
264 function compose_robot_arguments () {
266 # This function is called by run_tests function.
267 # The reason is that some jobs (bisect) perform reservation multiple times,
268 # so WORKING_TOPOLOGY can be different each time.
271 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
272 # - DUT - CSIT test/ subdirectory, set while processing tags.
273 # - TAGS - Array variable holding selected tag boolean expressions.
274 # - TOPOLOGIES_TAGS - Tag boolean expression filtering tests for topology.
275 # - TEST_CODE - The test selection string from environment or argument.
276 # - SELECTION_MODE - Selection criteria [test, suite, include, exclude].
278 # - ROBOT_ARGS - String holding part of all arguments for robot.
279 # - EXPANDED_TAGS - Array of strings robot arguments compiled from tags.
283 # No explicit check needed with "set -u".
284 ROBOT_ARGS=("--loglevel" "TRACE")
285 ROBOT_ARGS+=("--variable" "TOPOLOGY_PATH:${WORKING_TOPOLOGY}")
287 # TODO: The rest does not need to be recomputed on each reservation.
288 # Refactor TEST_CODE so this part can be called only once.
289 case "${TEST_CODE}" in
291 ROBOT_ARGS+=("--suite" "tests.${DUT}.device")
294 ROBOT_ARGS+=("--suite" "tests.${DUT}.perf")
297 die "Unknown specification: ${TEST_CODE}"
301 for tag in "${TAGS[@]}"; do
302 if [[ ${tag} == "!"* ]]; then
303 EXPANDED_TAGS+=("--exclude" "${tag#$"!"}")
305 if [[ ${SELECTION_MODE} == "--test" ]]; then
306 EXPANDED_TAGS+=("--test" "${tag}")
308 EXPANDED_TAGS+=("--include" "${TOPOLOGIES_TAGS}AND${tag}")
313 if [[ ${SELECTION_MODE} == "--test" ]]; then
314 EXPANDED_TAGS+=("--include" "${TOPOLOGIES_TAGS}")
319 function deactivate_docker_topology () {
321 # Deactivate virtual vpp-device topology by removing containers.
324 # - NODENESS - Node multiplicity of desired testbed.
325 # - FLAVOR - Node flavor string, usually describing the processor.
329 case_text="${NODENESS}_${FLAVOR}"
330 case "${case_text}" in
331 "1n_skx" | "1n_tx2" | "1n_spr")
332 ssh="ssh root@172.17.0.1 -p 6022"
333 env_vars=$(env | grep CSIT_ | tr '\n' ' ' ) || die
334 # The "declare -f" output is long and boring.
336 ${ssh} "$(declare -f); deactivate_wrapper ${env_vars}" || {
337 die "Topology cleanup via shim-dcr failed!"
343 clean_environment || {
344 die "Topology cleanup locally failed!"
349 die "Unknown specification: ${case_text}!"
356 # Print the message to standard error end exit with error code specified
357 # by the second argument.
360 # - The default error message.
362 # - ${1} - The whole error message, be sure to quote. Optional
363 # - ${2} - the code to exit with, default: 1.
367 warn "${1:-Unspecified run-time error occurred!}"
372 function die_on_robot_error () {
374 # Source this fragment if you want to abort on any failed test case.
377 # - ROBOT_EXIT_STATUS - Set by a robot running fragment.
379 # - die - Print to stderr and exit.
383 if [[ "${ROBOT_EXIT_STATUS}" != "0" ]]; then
384 die "Test failures are present!" "${ROBOT_EXIT_STATUS}"
389 function generate_tests () {
391 # Populate ${GENERATED_DIR}/tests based on ${CSIT_DIR}/tests/.
392 # Any previously existing content of ${GENERATED_DIR}/tests is wiped before.
393 # The generation is done by executing any *.py executable
394 # within any subdirectory after copying.
396 # This is a separate function, because this code is called
397 # both by autogen checker and entries calling run_robot.
400 # - ${CSIT_DIR}/tests - Used as templates for the generated tests.
401 # Directories replaced:
402 # - ${GENERATED_DIR}/tests - Overwritten by the generated tests.
406 rm -rf "${GENERATED_DIR}/tests" || die
407 cp -r "${CSIT_DIR}/tests" "${GENERATED_DIR}/tests" || die
408 cmd_line=("find" "${GENERATED_DIR}/tests" "-type" "f")
409 cmd_line+=("-executable" "-name" "*.py")
410 # We sort the directories, so log output can be compared between runs.
411 file_list=$("${cmd_line[@]}" | sort) || die
413 for gen in ${file_list}; do
414 directory="$(dirname "${gen}")" || die
415 filename="$(basename "${gen}")" || die
416 pushd "${directory}" || die
417 ./"${filename}" || die
423 function get_test_code () {
426 # - ${1} - Optional, argument of entry script (or empty as unset).
427 # Test code value to override job name from environment.
429 # - JOB_NAME - String affecting test selection, default if not argument.
431 # - TEST_CODE - The test selection string from environment or argument.
432 # - NODENESS - Node multiplicity of desired testbed.
433 # - FLAVOR - Node flavor string, usually describing the processor.
437 TEST_CODE="${1-}" || die "Reading optional argument failed, somehow."
438 if [[ -z "${TEST_CODE}" ]]; then
439 TEST_CODE="${JOB_NAME-}" || die "Reading job name failed, somehow."
442 case "${TEST_CODE}" in
551 function get_test_tag_string () {
554 # - GERRIT_EVENT_TYPE - Event type set by gerrit, can be unset.
555 # - GERRIT_EVENT_COMMENT_TEXT - Comment text, read for "comment-added" type.
556 # - TEST_CODE - The test selection string from environment or argument.
558 # - TEST_TAG_STRING - The string following trigger word in gerrit comment.
559 # May be empty, or even not set on event types not adding comment.
560 # Variables exported optionally:
561 # - GRAPH_NODE_VARIANT - Node variant to test with, set if found in trigger.
563 # TODO: ci-management scripts no longer need to perform this.
567 if [[ "${GERRIT_EVENT_TYPE-}" == "comment-added" ]]; then
568 case "${TEST_CODE}" in
576 die "Unknown specification: ${TEST_CODE}"
578 # Ignore lines not containing the trigger word.
579 comment=$(fgrep "${trigger}" <<< "${GERRIT_EVENT_COMMENT_TEXT}" || true)
580 # The vpp-csit triggers trail stuff we are not interested in.
581 # Removing them and trigger word: https://unix.stackexchange.com/a/13472
582 # (except relying on \s whitespace, \S non-whitespace and . both).
583 # The last string is concatenated, only the middle part is expanded.
584 cmd=("grep" "-oP" '\S*'"${trigger}"'\S*\s\K.+$') || die "Unset trigger?"
585 # On parsing error, TEST_TAG_STRING probably stays empty.
586 TEST_TAG_STRING=$("${cmd[@]}" <<< "${comment}" || true)
587 if [[ -z "${TEST_TAG_STRING-}" ]]; then
588 # Probably we got a base64 encoded comment.
589 comment="${GERRIT_EVENT_COMMENT_TEXT}"
590 comment=$(base64 --decode <<< "${comment}" || true)
591 comment=$(fgrep "${trigger}" <<< "${comment}" || true)
592 TEST_TAG_STRING=$("${cmd[@]}" <<< "${comment}" || true)
594 if [[ -n "${TEST_TAG_STRING-}" ]]; then
595 test_tag_array=(${TEST_TAG_STRING})
596 if [[ "${test_tag_array[0]}" == "icl" ]]; then
597 export GRAPH_NODE_VARIANT="icl"
598 TEST_TAG_STRING="${test_tag_array[@]:1}" || true
599 elif [[ "${test_tag_array[0]}" == "skx" ]]; then
600 export GRAPH_NODE_VARIANT="skx"
601 TEST_TAG_STRING="${test_tag_array[@]:1}" || true
608 function installed () {
610 # Check if the given utility is installed. Fail if not installed.
612 # Duplicate of common.sh function, as this file is also used standalone.
615 # - ${1} - Utility to check.
617 # - 0 - If command is installed.
618 # - 1 - If command is not installed.
626 function move_archives () {
628 # Move archive directory to top of workspace, if not already there.
630 # ARCHIVE_DIR is positioned relative to CSIT_DIR,
631 # but in some jobs CSIT_DIR is not same as WORKSPACE
632 # (e.g. under VPP_DIR). To simplify ci-management settings,
633 # we want to move the data to the top. We do not want simple copy,
634 # as ci-management is eager with recursive search.
636 # As some scripts may call this function multiple times,
637 # the actual implementation use copying and deletion,
638 # so the workspace gets "union" of contents (except overwrites on conflict).
639 # The consequence is empty ARCHIVE_DIR remaining after this call.
641 # As the source directory is emptied,
642 # the check for dirs being different is essential.
645 # - WORKSPACE - Jenkins workspace, move only if the value is not empty.
646 # Can be unset, then it speeds up manual testing.
647 # - ARCHIVE_DIR - Path to directory with content to be moved.
648 # Directories updated:
649 # - ${WORKSPACE}/archives/ - Created if does not exist.
650 # Content of ${ARCHIVE_DIR}/ is moved.
652 # - die - Print to stderr and exit.
656 if [[ -n "${WORKSPACE-}" ]]; then
657 target=$(readlink -f "${WORKSPACE}/archives")
658 if [[ "${target}" != "${ARCHIVE_DIR}" ]]; then
659 mkdir -p "${target}" || die "Archives dir create failed."
660 cp -rf "${ARCHIVE_DIR}"/* "${target}" || die "Copy failed."
661 rm -rf "${ARCHIVE_DIR}"/* || die "Delete failed."
667 function prepare_topology () {
669 # Prepare virtual testbed topology if needed based on flavor.
672 # - TEST_CODE - String affecting test selection, usually jenkins job name.
673 # - NODENESS - Node multiplicity of testbed, either "2n" or "3n".
674 # - FLAVOR - Node flavor string, e.g. "clx" or "skx".
676 # - TERRAFORM_MODULE_DIR - Terraform module directory.
678 # - die - Print to stderr and exit.
679 # - terraform_init - Terraform init topology.
680 # - terraform_apply - Terraform apply topology.
684 case_text="${NODENESS}_${FLAVOR}"
685 case "${case_text}" in
686 "1n_aws" | "2n_aws" | "3n_aws")
687 export TF_VAR_testbed_name="${TEST_CODE}"
688 TERRAFORM_MODULE_DIR="terraform-aws-${NODENESS}-${FLAVOR}-c5n"
689 terraform_init || die "Failed to call terraform init."
690 trap "terraform_destroy" ERR EXIT || {
691 die "Trap attempt failed, please cleanup manually. Aborting!"
693 terraform_apply || die "Failed to call terraform apply."
695 "2n_c6gn" | "3n_c6gn")
696 export TF_VAR_testbed_name="${TEST_CODE}"
697 TERRAFORM_MODULE_DIR="terraform-aws-${NODENESS}-c6gn"
698 terraform_init || die "Failed to call terraform init."
699 trap "terraform_destroy" ERR EXIT || {
700 die "Trap attempt failed, please cleanup manually. Aborting!"
702 terraform_apply || die "Failed to call terraform apply."
704 "2n_c7gn" | "3n_c7gn")
705 export TF_VAR_testbed_name="${TEST_CODE}"
706 TERRAFORM_MODULE_DIR="terraform-aws-${NODENESS}-c7gn"
707 terraform_init || die "Failed to call terraform init."
708 trap "terraform_destroy" ERR EXIT || {
709 die "Trap attempt failed, please cleanup manually. Aborting!"
711 terraform_apply || die "Failed to call terraform apply."
713 "1n_c6in" | "2n_c6in" | "3n_c6in")
714 export TF_VAR_testbed_name="${TEST_CODE}"
715 TERRAFORM_MODULE_DIR="terraform-aws-${NODENESS}-c6in"
716 terraform_init || die "Failed to call terraform init."
717 trap "terraform_destroy" ERR EXIT || {
718 die "Trap attempt failed, please cleanup manually. Aborting!"
720 terraform_apply || die "Failed to call terraform apply."
726 function reserve_and_cleanup_testbed () {
728 # Reserve physical testbed, perform cleanup, register trap to unreserve.
729 # When cleanup fails, remove from topologies and keep retrying
730 # until all topologies are removed.
732 # Multiple other functions are called from here,
733 # as they set variables that depend on reserved topology data.
736 # - TOPOLOGIES - Array of paths to topology yaml to attempt reservation on.
737 # - PYTHON_SCRIPTS_DIR - Path to directory holding the reservation script.
738 # - BUILD_TAG - Any string suitable as filename, identifying
739 # test run executing this function. May be unset.
741 # - TOPOLOGIES - Array of paths to topologies, with failed cleanups removed.
742 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
744 # - die - Print to stderr and exit.
745 # - ansible_playbook - Perform an action using ansible, see ansible.sh
747 # - EXIT - Calls cancel_all for ${WORKING_TOPOLOGY}.
752 for topo in "${TOPOLOGIES[@]}"; do
754 scrpt="${PYTHON_SCRIPTS_DIR}/topo_reservation.py"
755 opts=("-t" "${topo}" "-r" "${BUILD_TAG:-Unknown}")
756 python3 "${scrpt}" "${opts[@]}"
759 if [[ "${result}" == "0" ]]; then
760 # Trap unreservation before cleanup check,
761 # so multiple jobs showing failed cleanup improve chances
762 # of humans to notice and fix.
763 WORKING_TOPOLOGY="${topo}"
764 echo "Reserved: ${WORKING_TOPOLOGY}"
765 trap "untrap_and_unreserve_testbed" EXIT || {
766 message="TRAP ATTEMPT AND UNRESERVE FAILED, FIX MANUALLY."
767 untrap_and_unreserve_testbed "${message}" || {
768 die "Teardown should have died, not failed."
770 die "Trap attempt failed, unreserve succeeded. Aborting."
772 # Cleanup + calibration checks
774 ansible_playbook "cleanup, calibration"
777 if [[ "${result}" == "0" ]]; then
780 warn "Testbed cleanup failed: ${topo}"
781 untrap_and_unreserve_testbed "Fail of unreserve after cleanup."
783 # Else testbed is accessible but currently reserved, moving on.
786 if [[ -n "${WORKING_TOPOLOGY-}" ]]; then
787 # Exit the infinite while loop if we made a reservation.
788 warn "Reservation and cleanup successful."
792 if [[ "${#TOPOLOGIES[@]}" == "0" ]]; then
793 die "Run out of operational testbeds!"
796 # Wait ~3minutes before next try.
797 sleep_time="$[ ( ${RANDOM} % 20 ) + 180 ]s" || {
798 die "Sleep time calculation failed."
800 echo "Sleeping ${sleep_time}"
801 sleep "${sleep_time}" || die "Sleep failed."
804 # Subfunctions to update data that may depend on topology reserved.
805 set_environment_variables || die
807 compose_robot_arguments || die
811 function run_robot () {
813 # Run robot with options based on input variables.
815 # Testbed has to be reserved already,
816 # as some data may have changed between reservations,
817 # for example excluded NICs.
820 # - CSIT_DIR - Path to existing root of local CSIT git repository.
821 # - ARCHIVE_DIR - Path to store robot result files in.
822 # - ROBOT_ARGS, EXPANDED_TAGS - See compose_robot_arguments.sh
823 # - GENERATED_DIR - Tests are assumed to be generated under there.
824 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
825 # - DUT - CSIT test/ subdirectory, set while processing tags.
826 # - TAGS - Array variable holding selected tag boolean expressions.
827 # - TOPOLOGIES_TAGS - Tag boolean expression filtering tests for topology.
828 # - TEST_CODE - The test selection string from environment or argument.
830 # - ROBOT_ARGS - String holding part of all arguments for robot.
831 # - EXPANDED_TAGS - Array of string robot arguments compiled from tags.
832 # - ROBOT_EXIT_STATUS - Exit status of most recent robot invocation.
834 # - die - Print to stderr and exit.
838 all_options=("--outputdir" "${ARCHIVE_DIR}" "${ROBOT_ARGS[@]}")
839 all_options+=("${EXPANDED_TAGS[@]}")
841 pushd "${CSIT_DIR}" || die "Change directory operation failed."
843 robot "${all_options[@]}" "${GENERATED_DIR}/tests/"
844 ROBOT_EXIT_STATUS="$?"
847 popd || die "Change directory operation failed."
851 function select_arch_os () {
853 # Set variables affected by local CPU architecture and operating system.
856 # - VPP_VER_FILE - Name of file in CSIT dir containing vpp stable version.
857 # - IMAGE_VER_FILE - Name of file in CSIT dir containing the image name.
858 # - PKG_SUFFIX - Suffix of OS package file name, "rpm" or "deb."
862 source /etc/os-release || die "Get OS release failed."
867 *"LTS (Jammy Jellyfish)"*)
868 IMAGE_VER_FILE="VPP_DEVICE_IMAGE_UBUNTU_JAMMY"
869 VPP_VER_FILE="VPP_STABLE_VER_UBUNTU_JAMMY"
873 die "Unsupported Ubuntu version!"
878 die "Unsupported distro or OS!"
882 arch=$(uname -m) || {
883 die "Get CPU architecture failed."
888 IMAGE_VER_FILE="${IMAGE_VER_FILE}_ARM"
896 function select_tags () {
898 # Only to be called from the reservation function,
899 # as resulting tags may change based on topology data.
902 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
903 # - TEST_CODE - String affecting test selection, usually jenkins job name.
904 # - DUT - CSIT test/ subdirectory, set while processing tags.
905 # - TEST_TAG_STRING - String selecting tags, from gerrit comment.
907 # - TOPOLOGIES_DIR - Path to existing directory with available tpologies.
908 # - BASH_FUNCTION_DIR - Directory with input files to process.
910 # - TAGS - Array of processed tag boolean expressions.
911 # - SELECTION_MODE - Selection criteria [test, suite, include, exclude].
916 case "${TEST_CODE}" in
917 *"1n-aws"* | *"1n-c6in"*)
918 start_pattern='^ SUT:'
921 start_pattern='^ TG:'
924 end_pattern='^ \? \?[A-Za-z0-9]\+:'
925 # Remove the sections from topology file
926 sed_command="/${start_pattern}/,/${end_pattern}/d"
927 # All topologies NICs
928 available=$(sed "${sed_command}" "${TOPOLOGIES_DIR}"/* \
929 | grep -hoP "model: \K.*" | sort -u)
930 # Selected topology NICs
931 reserved=$(sed "${sed_command}" "${WORKING_TOPOLOGY}" \
932 | grep -hoP "model: \K.*" | sort -u)
933 # All topologies NICs - Selected topology NICs
934 exclude_nics=($(comm -13 <(echo "${reserved}") <(echo "${available}"))) || {
935 die "Computation of excluded NICs failed."
938 # Select default NIC tag.
939 case "${TEST_CODE}" in
941 default_nic="nic_intel-e822cq"
944 default_nic="nic_intel-e823c"
947 default_nic="nic_intel-x520-da2"
949 *"3n-icx" | *"2n-icx")
950 default_nic="nic_intel-e810cq"
953 default_nic="nic_mellanox-cx7veat"
956 default_nic="nic_intel-e810cq"
959 default_nic="nic_intel-e810cq"
961 *"2n-clx" | *"2n-zn2")
962 default_nic="nic_intel-xxv710"
964 *"2n-tx2" | *"3n-alt")
965 default_nic="nic_intel-xl710"
967 *"1n-aws" | *"2n-aws" | *"3n-aws")
968 default_nic="nic_amazon-nitro-50g"
970 *"2n-c6gn" | *"3n-c6gn")
971 default_nic="nic_amazon-nitro-100g"
973 *"2n-c7gn" | *"3n-c7gn")
974 default_nic="nic_amazon-nitro-100g"
976 *"1n-c6in" | *"2n-c6in" | *"3n-c6in")
977 default_nic="nic_amazon-nitro-200g"
980 default_nic="nic_intel-x710"
984 sed_nic_sub_cmd="sed s/\${default_nic}/${default_nic}/"
986 awk_nics_sub_cmd+='gsub("xxv710","25ge2p1xxv710");'
987 awk_nics_sub_cmd+='gsub("x710","10ge2p1x710");'
988 awk_nics_sub_cmd+='gsub("xl710","40ge2p1xl710");'
989 awk_nics_sub_cmd+='gsub("x520-da2","10ge2p1x520");'
990 awk_nics_sub_cmd+='gsub("cx556a","100ge2p1cx556a");'
991 awk_nics_sub_cmd+='gsub("2p1cx7veat","200ge2p1cx7veat");'
992 awk_nics_sub_cmd+='gsub("6p3cx7veat","200ge6p3cx7veat");'
993 awk_nics_sub_cmd+='gsub("cx6dx","100ge2p1cx6dx");'
994 awk_nics_sub_cmd+='gsub("e810cq","100ge2p1e810cq");'
995 awk_nics_sub_cmd+='gsub("e822cq","25ge2p1e822cq");'
996 awk_nics_sub_cmd+='gsub("e823c","25ge2p1e823c");'
997 awk_nics_sub_cmd+='gsub("vic1227","10ge2p1vic1227");'
998 awk_nics_sub_cmd+='gsub("vic1385","40ge2p1vic1385");'
999 awk_nics_sub_cmd+='gsub("nitro-50g","50ge1p1ENA");'
1000 awk_nics_sub_cmd+='gsub("nitro-100g","100ge1p1ENA");'
1001 awk_nics_sub_cmd+='gsub("nitro-200g","200ge1p1ENA");'
1002 awk_nics_sub_cmd+='gsub("virtual","1ge1p82540em");'
1003 awk_nics_sub_cmd+='if ($9 =="drv_avf") drv="avf-";'
1004 awk_nics_sub_cmd+='else if ($9 =="drv_rdma_core") drv ="rdma-";'
1005 awk_nics_sub_cmd+='else if ($9 =="drv_mlx5_core") drv ="mlx5-";'
1006 awk_nics_sub_cmd+='else if ($9 =="drv_af_xdp") drv ="af-xdp-";'
1007 awk_nics_sub_cmd+='else drv="";'
1008 awk_nics_sub_cmd+='if ($1 =="-") cores="";'
1009 awk_nics_sub_cmd+='else cores=$1;'
1010 awk_nics_sub_cmd+='print "*"$7"-" drv $11"-"$5"."$3"-" cores "-" drv $11"-"$5'
1012 # Tag file directory shorthand.
1013 tfd="${JOB_SPECS_DIR}"
1014 case "${TEST_CODE}" in
1015 # Select specific performance tests based on jenkins job type variable.
1017 readarray -t test_tag_array <<< $(grep -v "#" \
1018 ${tfd}/vpp_device/${DUT}-${NODENESS}-${FLAVOR}.md |
1019 awk {"$awk_nics_sub_cmd"} || echo "devicetest") || die
1020 SELECTION_MODE="--test"
1022 *"hoststack-daily"* )
1023 readarray -t test_tag_array <<< $(grep -v "#" \
1024 ${tfd}/hoststack_daily/${DUT}-${NODENESS}-${FLAVOR}.md |
1025 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
1026 SELECTION_MODE="--test"
1029 readarray -t test_tag_array <<< $(grep -v "#" \
1030 ${tfd}/ndrpdr_weekly/${DUT}-${NODENESS}-${FLAVOR}.md |
1031 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
1032 SELECTION_MODE="--test"
1035 readarray -t test_tag_array <<< $(grep -v "#" \
1036 ${tfd}/mrr_daily/${DUT}-${NODENESS}-${FLAVOR}.md |
1037 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
1038 SELECTION_MODE="--test"
1041 readarray -t test_tag_array <<< $(grep -v "#" \
1042 ${tfd}/mrr_weekly/${DUT}-${NODENESS}-${FLAVOR}.md |
1043 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
1044 SELECTION_MODE="--test"
1046 *"report-iterative"* )
1047 test_sets=(${TEST_TAG_STRING//:/ })
1048 # Run only one test set per run
1049 report_file=${test_sets[0]}.md
1050 readarray -t test_tag_array <<< $(grep -v "#" \
1051 ${tfd}/report_iterative/${NODENESS}-${FLAVOR}/${report_file} |
1052 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
1053 SELECTION_MODE="--test"
1055 *"report-coverage"* )
1056 test_sets=(${TEST_TAG_STRING//:/ })
1057 # Run only one test set per run
1058 report_file=${test_sets[0]}.md
1059 readarray -t test_tag_array <<< $(grep -v "#" \
1060 ${tfd}/report_coverage/${NODENESS}-${FLAVOR}/${report_file} |
1061 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
1062 SELECTION_MODE="--test"
1065 if [[ -z "${TEST_TAG_STRING-}" ]]; then
1066 # If nothing is specified, we will run pre-selected tests by
1068 test_tag_array=("mrrAND${default_nic}AND1cAND64bANDethip4-ip4base"
1069 "mrrAND${default_nic}AND1cAND78bANDethip6-ip6base"
1070 "mrrAND${default_nic}AND1cAND64bANDeth-l2bdbasemaclrn"
1071 "mrrAND${default_nic}AND1cAND64bANDeth-l2xcbase"
1072 "!drv_af_xdp" "!drv_avf")
1074 # If trigger contains tags, split them into array.
1075 test_tag_array=(${TEST_TAG_STRING//:/ })
1077 SELECTION_MODE="--include"
1081 # Blacklisting certain tags per topology.
1083 # Reasons for blacklisting:
1084 # - ipsechw - Blacklisted on testbeds without crypto hardware accelerator.
1085 case "${TEST_CODE}" in
1087 test_tag_array+=("!avf")
1088 test_tag_array+=("!vhost")
1089 test_tag_array+=("!flow")
1092 test_tag_array+=("!flow")
1095 test_tag_array+=("!ipsechw")
1098 test_tag_array+=("!ipsechw")
1103 test_tag_array+=("!ipsechw")
1106 test_tag_array+=("!ipsechw")
1109 test_tag_array+=("!ipsechw")
1112 test_tag_array+=("!ipsechw")
1113 test_tag_array+=("!3_node_double_link_topoANDnic_intel-xxv710")
1124 test_tag_array+=("!drv_avf")
1125 test_tag_array+=("!ipsechw")
1127 *"1n-aws" | *"2n-aws" | *"3n-aws")
1128 test_tag_array+=("!ipsechw")
1130 *"2n-c6gn" | *"3n-c6gn")
1131 test_tag_array+=("!ipsechw")
1133 *"2n-c7gn" | *"3n-c7gn")
1134 test_tag_array+=("!ipsechw")
1136 *"1n-c6in" | *"2n-c6in" | *"3n-c6in")
1137 test_tag_array+=("!ipsechw")
1141 # We will add excluded NICs.
1142 test_tag_array+=("${exclude_nics[@]/#/!NIC_}")
1146 if [[ "${TEST_CODE}" == "vpp-"* ]]; then
1147 if [[ "${TEST_CODE}" != *"device"* ]]; then
1148 # Automatic prefixing for VPP perf jobs to limit the NIC used.
1149 if [[ "${TEST_TAG_STRING-}" != *"nic_"* ]]; then
1150 prefix="${default_nic}AND"
1155 for tag in "${test_tag_array[@]}"; do
1156 if [[ "${tag}" == "!"* ]]; then
1157 # Exclude tags are not prefixed.
1159 elif [[ "${tag}" == " "* || "${tag}" == *"perftest"* ]]; then
1160 # Badly formed tag expressions can trigger way too much tests.
1162 warn "The following tag expression hints at bad trigger: ${tag}"
1163 warn "Possible cause: Multiple triggers in a single comment."
1164 die "Aborting to avoid triggering too many tests."
1165 elif [[ "${tag}" == *"OR"* ]]; then
1166 # If OR had higher precedence than AND, it would be useful here.
1167 # Some people think it does, thus triggering way too much tests.
1169 warn "The following tag expression hints at bad trigger: ${tag}"
1170 warn "Operator OR has lower precedence than AND. Use space instead."
1171 die "Aborting to avoid triggering too many tests."
1172 elif [[ "${tag}" != "" && "${tag}" != "#"* ]]; then
1173 # Empty and comment lines are skipped.
1174 # Other lines are normal tags, they are to be prefixed.
1175 TAGS+=("${prefix}${tag}")
1182 function select_topology () {
1185 # - NODENESS - Node multiplicity of testbed, either "2n" or "3n".
1186 # - FLAVOR - Node flavor string, e.g. "clx" or "skx".
1187 # - CSIT_DIR - Path to existing root of local CSIT git repository.
1188 # - TOPOLOGIES_DIR - Path to existing directory with available topologies.
1190 # - TOPOLOGIES - Array of paths to suitable topology yaml files.
1191 # - TOPOLOGIES_TAGS - Tag expression selecting tests for the topology.
1193 # - die - Print to stderr and exit.
1197 case_text="${NODENESS}_${FLAVOR}"
1198 case "${case_text}" in
1200 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*1n-aws*.yaml )
1201 TOPOLOGIES_TAGS="1_node_single_link_topo"
1204 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*1n-c6in*.yaml )
1205 TOPOLOGIES_TAGS="1_node_single_link_topo"
1207 "1n_tx2" | "1n_spr")
1208 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*vpp_device*.template )
1209 TOPOLOGIES_TAGS="2_node_single_link_topo"
1212 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*vpp_device*.template )
1213 TOPOLOGIES_TAGS="2_node_single_link_topo"
1216 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n-aws*.yaml )
1217 TOPOLOGIES_TAGS="2_node_single_link_topo"
1220 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n-c6gn*.yaml )
1221 TOPOLOGIES_TAGS="2_node_single_link_topo"
1224 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n-c7gn*.yaml )
1225 TOPOLOGIES_TAGS="2_node_single_link_topo"
1228 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n-c6in*.yaml )
1229 TOPOLOGIES_TAGS="2_node_single_link_topo"
1232 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_clx_*.yaml )
1233 TOPOLOGIES_TAGS="2_node_*_link_topo"
1236 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_icx_*.yaml )
1237 TOPOLOGIES_TAGS="2_node_*_link_topo"
1240 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_spr_*.yaml )
1241 TOPOLOGIES_TAGS="2_node_*_link_topo"
1244 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_tx2_*.yaml )
1245 TOPOLOGIES_TAGS="2_node_single_link_topo"
1248 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_zn2_*.yaml )
1249 TOPOLOGIES_TAGS="2_node_*_link_topo"
1252 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_alt_*.yaml )
1253 TOPOLOGIES_TAGS="3_node_single_link_topo"
1256 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n-aws*.yaml )
1257 TOPOLOGIES_TAGS="3_node_single_link_topo"
1260 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n-c6gn*.yaml )
1261 TOPOLOGIES_TAGS="3_node_single_link_topo"
1264 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n-c7gn*.yaml )
1265 TOPOLOGIES_TAGS="3_node_single_link_topo"
1268 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n-c6in*.yaml )
1269 TOPOLOGIES_TAGS="3_node_single_link_topo"
1272 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_icx_*.yaml )
1273 # Trailing underscore is needed to distinguish from 3n_icxd.
1274 TOPOLOGIES_TAGS="3_node_*_link_topo"
1277 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_icxd_*.yaml )
1278 TOPOLOGIES_TAGS="3_node_single_link_topo"
1281 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_snr_*.yaml )
1282 TOPOLOGIES_TAGS="3_node_single_link_topo"
1285 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_tsh_*.yaml )
1286 TOPOLOGIES_TAGS="3_node_single_link_topo"
1289 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3na_spr_*.yaml )
1290 TOPOLOGIES_TAGS="3_node_*_link_topo"
1293 TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3nb_spr_*.yaml )
1294 TOPOLOGIES_TAGS="3_node_*_link_topo"
1297 # No falling back to default, that should have been done
1298 # by the function which has set NODENESS and FLAVOR.
1299 die "Unknown specification: ${case_text}"
1302 if [[ -z "${TOPOLOGIES-}" ]]; then
1303 die "No applicable topology found!"
1308 function set_environment_variables () {
1310 # Depending on testbed topology, overwrite defaults set in the
1311 # resources/libraries/python/Constants.py file
1313 # Only to be called from the reservation function,
1314 # as resulting values may change based on topology data.
1317 # - TEST_CODE - String affecting test selection, usually jenkins job name.
1319 # See specific cases
1323 case "${TEST_CODE}" in
1324 *"1n-aws" | *"2n-aws" | *"3n-aws")
1325 export TREX_RX_DESCRIPTORS_COUNT=1024
1326 export TREX_EXTRA_CMDLINE="--mbuf-factor 19"
1327 export TREX_CORE_COUNT=6
1328 # Settings to prevent duration stretching.
1329 export PERF_TRIAL_STL_DELAY=0.1
1331 *"2n-c6gn" | *"3n-c6gn")
1332 export TREX_RX_DESCRIPTORS_COUNT=1024
1333 export TREX_EXTRA_CMDLINE="--mbuf-factor 19"
1334 export TREX_CORE_COUNT=6
1335 # Settings to prevent duration stretching.
1336 export PERF_TRIAL_STL_DELAY=0.1
1338 *"2n-c7gn" | *"3n-c7gn")
1339 export TREX_RX_DESCRIPTORS_COUNT=1024
1340 export TREX_EXTRA_CMDLINE="--mbuf-factor 19"
1341 export TREX_CORE_COUNT=6
1342 # Settings to prevent duration stretching.
1343 export PERF_TRIAL_STL_DELAY=0.1
1345 *"1n-c6in" | *"2n-c6in" | *"3n-c6in")
1346 export TREX_RX_DESCRIPTORS_COUNT=1024
1347 export TREX_EXTRA_CMDLINE="--mbuf-factor 19"
1348 export TREX_CORE_COUNT=6
1349 # Settings to prevent duration stretching.
1350 export PERF_TRIAL_STL_DELAY=0.1
1353 # Maciek's workaround for Zen2 with lower amount of cores.
1354 export TREX_CORE_COUNT=14
1359 function untrap_and_unreserve_testbed () {
1361 # Use this as a trap function to ensure testbed does not remain reserved.
1362 # Perhaps call directly before script exit, to free testbed for other jobs.
1363 # This function is smart enough to avoid multiple unreservations (so safe).
1364 # Topo cleanup is executed (call it best practice), ignoring failures.
1367 # - default message to die with if testbed might remain reserved.
1369 # - ${1} - Message to die with if unreservation fails. Default hardcoded.
1370 # Variables read (by inner function):
1371 # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
1372 # - PYTHON_SCRIPTS_DIR - Path to directory holding Python scripts.
1374 # - TERRAFORM_MODULE_DIR - Terraform module directory.
1375 # - WORKING_TOPOLOGY - Set to empty string on successful unreservation.
1376 # Trap unregistered:
1377 # - EXIT - Failure to untrap is reported, but ignored otherwise.
1379 # - die - Print to stderr and exit.
1380 # - ansible_playbook - Perform an action using ansible, see ansible.sh
1383 set +eu # We do not want to exit early in a "teardown" function.
1384 trap - EXIT || echo "Trap deactivation failed, continuing anyway."
1385 wt="${WORKING_TOPOLOGY}" # Just to avoid too long lines.
1386 if [[ -z "${wt-}" ]]; then
1388 warn "Testbed looks unreserved already. Trap removal failed before?"
1390 ansible_playbook "cleanup" || true
1391 python3 "${PYTHON_SCRIPTS_DIR}/topo_reservation.py" -c -t "${wt}" || {
1392 die "${1:-FAILED TO UNRESERVE, FIX MANUALLY.}" 2
1394 case "${TEST_CODE}" in
1395 *"1n-aws" | *"2n-aws" | *"3n-aws")
1396 TERRAFORM_MODULE_DIR="terraform-aws-${NODENESS}-${FLAVOR}-c5n"
1397 terraform_destroy || die "Failed to call terraform destroy."
1399 *"2n-c6gn" | *"3n-c6gn")
1400 TERRAFORM_MODULE_DIR="terraform-aws-${NODENESS}-${FLAVOR}"
1401 terraform_destroy || die "Failed to call terraform destroy."
1403 *"2n-c7gn" | *"3n-c7gn")
1404 TERRAFORM_MODULE_DIR="terraform-aws-${NODENESS}-${FLAVOR}"
1405 terraform_destroy || die "Failed to call terraform destroy."
1407 *"1n-c6in" | *"2n-c6in" | *"3n-c6in")
1408 TERRAFORM_MODULE_DIR="terraform-aws-${NODENESS}-${FLAVOR}"
1409 terraform_destroy || die "Failed to call terraform destroy."
1422 # Print the message to standard error.
1425 # - ${@} - The text of the message.