fix(job_spec): Naming conventions
[csit.git] / resources / libraries / bash / function / common.sh
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:
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 set -exuo pipefail
16
17 # This library defines functions used by multiple entry scripts.
18 # Keep functions ordered alphabetically, please.
19
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).
23
24
25 function activate_docker_topology () {
26
27     # Create virtual vpp-device topology. Output of the function is topology
28     # file describing created environment saved to a file.
29     #
30     # Variables read:
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.
37     # Variables set:
38     # - WORKING_TOPOLOGY - Path to topology file.
39
40     set -exuo pipefail
41
42     source "${BASH_FUNCTION_DIR}/device.sh" || {
43         die "Source failed!"
44     }
45     device_image="$(< ${CSIT_DIR}/${IMAGE_VER_FILE})"
46     case_text="${NODENESS}_${FLAVOR}"
47     case "${case_text}" in
48         "1n_skx" | "1n_tx2")
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.
57             set +x
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!"
61             }
62             set -x
63             set -a
64             source <(echo "$env_vars" | grep -v /usr/bin/docker) || {
65                 die "Source failed!"
66             }
67             set +a
68             ;;
69         "1n_vbox")
70             # We execute reservation on localhost. Sourced script automatially
71             # sets environment variables for further processing.
72             activate_wrapper "${NODENESS}" "${FLAVOR}" "${device_image}" || die
73             ;;
74         *)
75             die "Unknown specification: ${case_text}!"
76     esac
77
78     trap 'deactivate_docker_topology' EXIT || {
79          die "Trap attempt failed, please cleanup manually. Aborting!"
80     }
81
82     parse_env_variables || die "Parse of environment variables failed!"
83
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!"
87     }
88
89     WORKING_TOPOLOGY="${CSIT_DIR}/topologies/available/vpp_device.yaml"
90     mv topo.yml "${WORKING_TOPOLOGY}" || {
91         die "Topology move failed!"
92     }
93     cat ${WORKING_TOPOLOGY} | grep -v password || {
94         die "Topology read failed!"
95     }
96 }
97
98
99 function activate_virtualenv () {
100
101     # Update virtualenv pip package, delete and create virtualenv directory,
102     # activate the virtualenv, install requirements, set PYTHONPATH.
103
104     # Arguments:
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.
108     # Variables read:
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.
112     # Functions called:
113     # - die - Print to stderr and exit.
114
115     set -exuo pipefail
116
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."
123     }
124     virtualenv --no-download --python=$(which python3) "${env_dir}" || {
125         die "Virtualenv creation for $(which python3) failed."
126     }
127     set +u
128     source "${env_dir}/bin/activate" || die "Virtualenv activation failed."
129     set -u
130     pip3 install -r "${req_path}" || {
131         die "Requirements installation failed."
132     }
133     # Most CSIT Python scripts assume PYTHONPATH is set and exported.
134     export PYTHONPATH="${CSIT_DIR}" || die "Export failed."
135 }
136
137
138 function archive_tests () {
139
140     # Create .tar.gz of generated/tests for archiving.
141     # To be run after generate_tests, kept separate to offer more flexibility.
142
143     # Directory read:
144     # - ${GENERATED_DIR}/tests - Tree of executed suites to archive.
145     # File rewriten:
146     # - ${ARCHIVE_DIR}/generated_tests.tar.gz - Archive of generated tests.
147
148     set -exuo pipefail
149
150     pushd "${ARCHIVE_DIR}" || die
151     tar czf "generated_tests.tar.gz" "${GENERATED_DIR}/tests" || true
152     popd || die
153 }
154
155
156 function check_download_dir () {
157
158     # Fail if there are no files visible in ${DOWNLOAD_DIR}.
159     #
160     # Variables read:
161     # - DOWNLOAD_DIR - Path to directory pybot takes the build to test from.
162     # Directories read:
163     # - ${DOWNLOAD_DIR} - Has to be non-empty to proceed.
164     # Functions called:
165     # - die - Print to stderr and exit.
166
167     set -exuo pipefail
168
169     if [[ ! "$(ls -A "${DOWNLOAD_DIR}")" ]]; then
170         die "No artifacts downloaded!"
171     fi
172 }
173
174
175 function check_prerequisites () {
176
177     # Fail if prerequisites are not met.
178     #
179     # Functions called:
180     # - installed - Check if application is installed/present in system.
181     # - die - Print to stderr and exit.
182
183     set -exuo pipefail
184
185     if ! installed sshpass; then
186         die "Please install sshpass before continue!"
187     fi
188 }
189
190
191 function common_dirs () {
192
193     # Set global variables, create some directories (without touching content).
194
195     # Variables set:
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.
209     # Functions called:
210     # - die - Print to stderr and exit.
211
212     set -exuo pipefail
213
214     this_file=$(readlink -e "${BASH_SOURCE[0]}") || {
215         die "Some error during locating of this source file."
216     }
217     BASH_FUNCTION_DIR=$(dirname "${this_file}") || {
218         die "Some error during dirname call."
219     }
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."
224     }
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."
229     }
230     JOB_SPECS_DIR=$(readlink -e "${CSIT_DIR}/docs/job_specs") || {
231         die "Readlink failed."
232     }
233     RESOURCES_DIR=$(readlink -e "${CSIT_DIR}/resources") || {
234         die "Readlink failed."
235     }
236     TOOLS_DIR=$(readlink -e "${RESOURCES_DIR}/tools") || {
237         die "Readlink failed."
238     }
239     DOC_GEN_DIR=$(readlink -e "${TOOLS_DIR}/doc_gen") || {
240         die "Readlink failed."
241     }
242     PYTHON_SCRIPTS_DIR=$(readlink -e "${TOOLS_DIR}/scripts") || {
243         die "Readlink failed."
244     }
245
246     ARCHIVE_DIR=$(readlink -f "${CSIT_DIR}/archives") || {
247         die "Readlink failed."
248     }
249     mkdir -p "${ARCHIVE_DIR}" || die "Mkdir failed."
250     DOWNLOAD_DIR=$(readlink -f "${CSIT_DIR}/download_dir") || {
251         die "Readlink failed."
252     }
253     mkdir -p "${DOWNLOAD_DIR}" || die "Mkdir failed."
254     GENERATED_DIR=$(readlink -f "${CSIT_DIR}/generated") || {
255         die "Readlink failed."
256     }
257     mkdir -p "${GENERATED_DIR}" || die "Mkdir failed."
258 }
259
260
261 function compose_pybot_arguments () {
262
263     # Variables read:
264     # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
265     # - DUT - CSIT test/ subdirectory, set while processing tags.
266     # - TAGS - Array variable holding selected tag boolean expressions.
267     # - TOPOLOGIES_TAGS - Tag boolean expression filtering tests for topology.
268     # - TEST_CODE - The test selection string from environment or argument.
269     # - SELECTION_MODE - Selection criteria [test, suite, include, exclude].
270     # Variables set:
271     # - PYBOT_ARGS - String holding part of all arguments for pybot.
272     # - EXPANDED_TAGS - Array of strings pybot arguments compiled from tags.
273
274     set -exuo pipefail
275
276     # No explicit check needed with "set -u".
277     PYBOT_ARGS=("--loglevel" "TRACE")
278     PYBOT_ARGS+=("--variable" "TOPOLOGY_PATH:${WORKING_TOPOLOGY}")
279
280     case "${TEST_CODE}" in
281         *"device"*)
282             PYBOT_ARGS+=("--suite" "tests.${DUT}.device")
283             ;;
284         *"perf"*)
285             PYBOT_ARGS+=("--suite" "tests.${DUT}.perf")
286             ;;
287         *)
288             die "Unknown specification: ${TEST_CODE}"
289     esac
290
291     EXPANDED_TAGS=()
292     for tag in "${TAGS[@]}"; do
293         if [[ ${tag} == "!"* ]]; then
294             EXPANDED_TAGS+=("--exclude" "${tag#$"!"}")
295         else
296             if [[ ${SELECTION_MODE} == "--test" ]]; then
297                 EXPANDED_TAGS+=("--test" "${tag}")
298             else
299                 EXPANDED_TAGS+=("--include" "${TOPOLOGIES_TAGS}AND${tag}")
300             fi
301         fi
302     done
303
304     if [[ ${SELECTION_MODE} == "--test" ]]; then
305         EXPANDED_TAGS+=("--include" "${TOPOLOGIES_TAGS}")
306     fi
307 }
308
309
310 function deactivate_docker_topology () {
311
312     # Deactivate virtual vpp-device topology by removing containers.
313     #
314     # Variables read:
315     # - NODENESS - Node multiplicity of desired testbed.
316     # - FLAVOR - Node flavor string, usually describing the processor.
317
318     set -exuo pipefail
319
320     case_text="${NODENESS}_${FLAVOR}"
321     case "${case_text}" in
322         "1n_skx" | "1n_tx2")
323             ssh="ssh root@172.17.0.1 -p 6022"
324             env_vars=$(env | grep CSIT_ | tr '\n' ' ' ) || die
325             # The "declare -f" output is long and boring.
326             set +x
327             ${ssh} "$(declare -f); deactivate_wrapper ${env_vars}" || {
328                 die "Topology cleanup via shim-dcr failed!"
329             }
330             set -x
331             ;;
332         "1n_vbox")
333             enter_mutex || die
334             clean_environment || {
335                 die "Topology cleanup locally failed!"
336             }
337             exit_mutex || die
338             ;;
339         *)
340             die "Unknown specification: ${case_text}!"
341     esac
342 }
343
344
345 function die () {
346
347     # Print the message to standard error end exit with error code specified
348     # by the second argument.
349     #
350     # Hardcoded values:
351     # - The default error message.
352     # Arguments:
353     # - ${1} - The whole error message, be sure to quote. Optional
354     # - ${2} - the code to exit with, default: 1.
355
356     set -x
357     set +eu
358     warn "${1:-Unspecified run-time error occurred!}"
359     exit "${2:-1}"
360 }
361
362
363 function die_on_pybot_error () {
364
365     # Source this fragment if you want to abort on any failed test case.
366     #
367     # Variables read:
368     # - PYBOT_EXIT_STATUS - Set by a pybot running fragment.
369     # Functions called:
370     # - die - Print to stderr and exit.
371
372     set -exuo pipefail
373
374     if [[ "${PYBOT_EXIT_STATUS}" != "0" ]]; then
375         die "Test failures are present!" "${PYBOT_EXIT_STATUS}"
376     fi
377 }
378
379
380 function generate_tests () {
381
382     # Populate ${GENERATED_DIR}/tests based on ${CSIT_DIR}/tests/.
383     # Any previously existing content of ${GENERATED_DIR}/tests is wiped before.
384     # The generation is done by executing any *.py executable
385     # within any subdirectory after copying.
386
387     # This is a separate function, because this code is called
388     # both by autogen checker and entries calling run_pybot.
389
390     # Directories read:
391     # - ${CSIT_DIR}/tests - Used as templates for the generated tests.
392     # Directories replaced:
393     # - ${GENERATED_DIR}/tests - Overwritten by the generated tests.
394
395     set -exuo pipefail
396
397     rm -rf "${GENERATED_DIR}/tests" || die
398     cp -r "${CSIT_DIR}/tests" "${GENERATED_DIR}/tests" || die
399     cmd_line=("find" "${GENERATED_DIR}/tests" "-type" "f")
400     cmd_line+=("-executable" "-name" "*.py")
401     # We sort the directories, so log output can be compared between runs.
402     file_list=$("${cmd_line[@]}" | sort) || die
403
404     for gen in ${file_list}; do
405         directory="$(dirname "${gen}")" || die
406         filename="$(basename "${gen}")" || die
407         pushd "${directory}" || die
408         ./"${filename}" || die
409         popd || die
410     done
411 }
412
413
414 function get_test_code () {
415
416     # Arguments:
417     # - ${1} - Optional, argument of entry script (or empty as unset).
418     #   Test code value to override job name from environment.
419     # Variables read:
420     # - JOB_NAME - String affecting test selection, default if not argument.
421     # Variables set:
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.
425
426     set -exuo pipefail
427
428     TEST_CODE="${1-}" || die "Reading optional argument failed, somehow."
429     if [[ -z "${TEST_CODE}" ]]; then
430         TEST_CODE="${JOB_NAME-}" || die "Reading job name failed, somehow."
431     fi
432
433     case "${TEST_CODE}" in
434         *"1n-vbox"*)
435             NODENESS="1n"
436             FLAVOR="vbox"
437             ;;
438         *"1n-skx"*)
439             NODENESS="1n"
440             FLAVOR="skx"
441             ;;
442         *"1n-tx2"*)
443             NODENESS="1n"
444             FLAVOR="tx2"
445             ;;
446         *"1n-aws"*)
447             NODENESS="1n"
448             FLAVOR="aws"
449             ;;
450         *"2n-aws"*)
451             NODENESS="2n"
452             FLAVOR="aws"
453             ;;
454         *"3n-aws"*)
455             NODENESS="3n"
456             FLAVOR="aws"
457             ;;
458         *"2n-zn2"*)
459             NODENESS="2n"
460             FLAVOR="zn2"
461             ;;
462         *"2n-clx"*)
463             NODENESS="2n"
464             FLAVOR="clx"
465             ;;
466         *"2n-icx"*)
467             NODENESS="2n"
468             FLAVOR="icx"
469             ;;
470         *"3n-icx"*)
471             NODENESS="3n"
472             FLAVOR="icx"
473             ;;
474         *"3n-snr"*)
475             NODENESS="3n"
476             FLAVOR="snr"
477             ;;
478         *"2n-tx2"*)
479             NODENESS="2n"
480             FLAVOR="tx2"
481             ;;
482         *"3n-tsh"*)
483             NODENESS="3n"
484             FLAVOR="tsh"
485             ;;
486         *"3n-alt"*)
487             NODENESS="3n"
488             FLAVOR="alt"
489             ;;
490     esac
491 }
492
493
494 function get_test_tag_string () {
495
496     # Variables read:
497     # - GERRIT_EVENT_TYPE - Event type set by gerrit, can be unset.
498     # - GERRIT_EVENT_COMMENT_TEXT - Comment text, read for "comment-added" type.
499     # - TEST_CODE - The test selection string from environment or argument.
500     # Variables set:
501     # - TEST_TAG_STRING - The string following trigger word in gerrit comment.
502     #   May be empty, or even not set on event types not adding comment.
503
504     # TODO: ci-management scripts no longer need to perform this.
505
506     set -exuo pipefail
507
508     if [[ "${GERRIT_EVENT_TYPE-}" == "comment-added" ]]; then
509         case "${TEST_CODE}" in
510             *"device"*)
511                 trigger="devicetest"
512                 ;;
513             *"perf"*)
514                 trigger="perftest"
515                 ;;
516             *)
517                 die "Unknown specification: ${TEST_CODE}"
518         esac
519         # Ignore lines not containing the trigger word.
520         comment=$(fgrep "${trigger}" <<< "${GERRIT_EVENT_COMMENT_TEXT}" || true)
521         # The vpp-csit triggers trail stuff we are not interested in.
522         # Removing them and trigger word: https://unix.stackexchange.com/a/13472
523         # (except relying on \s whitespace, \S non-whitespace and . both).
524         # The last string is concatenated, only the middle part is expanded.
525         cmd=("grep" "-oP" '\S*'"${trigger}"'\S*\s\K.+$') || die "Unset trigger?"
526         # On parsing error, TEST_TAG_STRING probably stays empty.
527         TEST_TAG_STRING=$("${cmd[@]}" <<< "${comment}" || true)
528         if [[ -z "${TEST_TAG_STRING-}" ]]; then
529             # Probably we got a base64 encoded comment.
530             comment="${GERRIT_EVENT_COMMENT_TEXT}"
531             comment=$(base64 --decode <<< "${comment}" || true)
532             comment=$(fgrep "${trigger}" <<< "${comment}" || true)
533             TEST_TAG_STRING=$("${cmd[@]}" <<< "${comment}" || true)
534         fi
535         if [[ -n "${TEST_TAG_STRING-}" ]]; then
536             test_tag_array=(${TEST_TAG_STRING})
537             if [[ "${test_tag_array[0]}" == "icl" ]]; then
538                 export GRAPH_NODE_VARIANT="icl"
539                 TEST_TAG_STRING="${test_tag_array[@]:1}" || true
540             elif [[ "${test_tag_array[0]}" == "skx" ]]; then
541                 export GRAPH_NODE_VARIANT="skx"
542                 TEST_TAG_STRING="${test_tag_array[@]:1}" || true
543             fi
544         fi
545     fi
546 }
547
548
549 function installed () {
550
551     # Check if the given utility is installed. Fail if not installed.
552     #
553     # Duplicate of common.sh function, as this file is also used standalone.
554     #
555     # Arguments:
556     # - ${1} - Utility to check.
557     # Returns:
558     # - 0 - If command is installed.
559     # - 1 - If command is not installed.
560
561     set -exuo pipefail
562
563     command -v "${1}"
564 }
565
566
567 function move_archives () {
568
569     # Move archive directory to top of workspace, if not already there.
570     #
571     # ARCHIVE_DIR is positioned relative to CSIT_DIR,
572     # but in some jobs CSIT_DIR is not same as WORKSPACE
573     # (e.g. under VPP_DIR). To simplify ci-management settings,
574     # we want to move the data to the top. We do not want simple copy,
575     # as ci-management is eager with recursive search.
576     #
577     # As some scripts may call this function multiple times,
578     # the actual implementation use copying and deletion,
579     # so the workspace gets "union" of contents (except overwrites on conflict).
580     # The consequence is empty ARCHIVE_DIR remaining after this call.
581     #
582     # As the source directory is emptied,
583     # the check for dirs being different is essential.
584     #
585     # Variables read:
586     # - WORKSPACE - Jenkins workspace, move only if the value is not empty.
587     #   Can be unset, then it speeds up manual testing.
588     # - ARCHIVE_DIR - Path to directory with content to be moved.
589     # Directories updated:
590     # - ${WORKSPACE}/archives/ - Created if does not exist.
591     #   Content of ${ARCHIVE_DIR}/ is moved.
592     # Functions called:
593     # - die - Print to stderr and exit.
594
595     set -exuo pipefail
596
597     if [[ -n "${WORKSPACE-}" ]]; then
598         target=$(readlink -f "${WORKSPACE}/archives")
599         if [[ "${target}" != "${ARCHIVE_DIR}" ]]; then
600             mkdir -p "${target}" || die "Archives dir create failed."
601             cp -rf "${ARCHIVE_DIR}"/* "${target}" || die "Copy failed."
602             rm -rf "${ARCHIVE_DIR}"/* || die "Delete failed."
603         fi
604     fi
605 }
606
607
608 function post_process_robot_outputs () {
609
610     # Generate INFO level output_info.xml by rebot.
611     #
612     # Variables read:
613     # - ARCHIVE_DIR - Path to post-processed files.
614
615     set -exuo pipefail
616
617     # Generate INFO level output_info.xml for post-processing.
618     all_options=("--loglevel" "INFO")
619     all_options+=("--log" "none")
620     all_options+=("--report" "none")
621     all_options+=("--output" "${ARCHIVE_DIR}/output_info.xml")
622     all_options+=("${ARCHIVE_DIR}/output.xml")
623     rebot "${all_options[@]}" || true
624 }
625
626
627 function prepare_topology () {
628
629     # Prepare virtual testbed topology if needed based on flavor.
630
631     # Variables read:
632     # - TEST_CODE - String affecting test selection, usually jenkins job name.
633     # - NODENESS - Node multiplicity of testbed, either "2n" or "3n".
634     # - FLAVOR - Node flavor string, e.g. "clx" or "skx".
635     # Functions called:
636     # - die - Print to stderr and exit.
637     # - terraform_init - Terraform init topology.
638     # - terraform_apply - Terraform apply topology.
639
640     set -exuo pipefail
641
642     case_text="${NODENESS}_${FLAVOR}"
643     case "${case_text}" in
644         "1n_aws" | "2n_aws" | "3n_aws")
645             export TF_VAR_testbed_name="${TEST_CODE}"
646             terraform_init || die "Failed to call terraform init."
647             terraform_apply || die "Failed to call terraform apply."
648             ;;
649     esac
650 }
651
652
653 function reserve_and_cleanup_testbed () {
654
655     # Reserve physical testbed, perform cleanup, register trap to unreserve.
656     # When cleanup fails, remove from topologies and keep retrying
657     # until all topologies are removed.
658     #
659     # Variables read:
660     # - TOPOLOGIES - Array of paths to topology yaml to attempt reservation on.
661     # - PYTHON_SCRIPTS_DIR - Path to directory holding the reservation script.
662     # - BUILD_TAG - Any string suitable as filename, identifying
663     #   test run executing this function. May be unset.
664     # Variables set:
665     # - TOPOLOGIES - Array of paths to topologies, with failed cleanups removed.
666     # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
667     # Functions called:
668     # - die - Print to stderr and exit.
669     # - ansible_playbook - Perform an action using ansible, see ansible.sh
670     # Traps registered:
671     # - EXIT - Calls cancel_all for ${WORKING_TOPOLOGY}.
672
673     set -exuo pipefail
674
675     while true; do
676         for topo in "${TOPOLOGIES[@]}"; do
677             set +e
678             scrpt="${PYTHON_SCRIPTS_DIR}/topo_reservation.py"
679             opts=("-t" "${topo}" "-r" "${BUILD_TAG:-Unknown}")
680             python3 "${scrpt}" "${opts[@]}"
681             result="$?"
682             set -e
683             if [[ "${result}" == "0" ]]; then
684                 # Trap unreservation before cleanup check,
685                 # so multiple jobs showing failed cleanup improve chances
686                 # of humans to notice and fix.
687                 WORKING_TOPOLOGY="${topo}"
688                 echo "Reserved: ${WORKING_TOPOLOGY}"
689                 trap "untrap_and_unreserve_testbed" EXIT || {
690                     message="TRAP ATTEMPT AND UNRESERVE FAILED, FIX MANUALLY."
691                     untrap_and_unreserve_testbed "${message}" || {
692                         die "Teardown should have died, not failed."
693                     }
694                     die "Trap attempt failed, unreserve succeeded. Aborting."
695                 }
696                 # Cleanup + calibration checks
697                 set +e
698                 ansible_playbook "cleanup, calibration"
699                 result="$?"
700                 set -e
701                 if [[ "${result}" == "0" ]]; then
702                     break
703                 fi
704                 warn "Testbed cleanup failed: ${topo}"
705                 untrap_and_unreserve_testbed "Fail of unreserve after cleanup."
706             fi
707             # Else testbed is accessible but currently reserved, moving on.
708         done
709
710         if [[ -n "${WORKING_TOPOLOGY-}" ]]; then
711             # Exit the infinite while loop if we made a reservation.
712             warn "Reservation and cleanup successful."
713             break
714         fi
715
716         if [[ "${#TOPOLOGIES[@]}" == "0" ]]; then
717             die "Run out of operational testbeds!"
718         fi
719
720         # Wait ~3minutes before next try.
721         sleep_time="$[ ( ${RANDOM} % 20 ) + 180 ]s" || {
722             die "Sleep time calculation failed."
723         }
724         echo "Sleeping ${sleep_time}"
725         sleep "${sleep_time}" || die "Sleep failed."
726     done
727 }
728
729
730 function run_pybot () {
731
732     # Run pybot with options based on input variables.
733     # Generate INFO level output_info.xml by rebot.
734     #
735     # Variables read:
736     # - CSIT_DIR - Path to existing root of local CSIT git repository.
737     # - ARCHIVE_DIR - Path to store robot result files in.
738     # - PYBOT_ARGS, EXPANDED_TAGS - See compose_pybot_arguments.sh
739     # - GENERATED_DIR - Tests are assumed to be generated under there.
740     # Variables set:
741     # - PYBOT_EXIT_STATUS - Exit status of most recent pybot invocation.
742     # Functions called:
743     # - die - Print to stderr and exit.
744
745     set -exuo pipefail
746
747     all_options=("--outputdir" "${ARCHIVE_DIR}" "${PYBOT_ARGS[@]}")
748     all_options+=("${EXPANDED_TAGS[@]}")
749
750     pushd "${CSIT_DIR}" || die "Change directory operation failed."
751     set +e
752     robot "${all_options[@]}" "${GENERATED_DIR}/tests/"
753     PYBOT_EXIT_STATUS="$?"
754     set -e
755
756     post_process_robot_outputs || die
757
758     popd || die "Change directory operation failed."
759 }
760
761
762 function select_arch_os () {
763
764     # Set variables affected by local CPU architecture and operating system.
765     #
766     # Variables set:
767     # - VPP_VER_FILE - Name of file in CSIT dir containing vpp stable version.
768     # - IMAGE_VER_FILE - Name of file in CSIT dir containing the image name.
769     # - PKG_SUFFIX - Suffix of OS package file name, "rpm" or "deb."
770
771     set -exuo pipefail
772
773     source /etc/os-release || die "Get OS release failed."
774
775     case "${ID}" in
776         "ubuntu"*)
777             case "${VERSION}" in
778                 *"LTS (Jammy Jellyfish)"*)
779                     IMAGE_VER_FILE="VPP_DEVICE_IMAGE_UBUNTU_JAMMY"
780                     VPP_VER_FILE="VPP_STABLE_VER_UBUNTU_JAMMY"
781                     PKG_SUFFIX="deb"
782                     ;;
783                 *)
784                     die "Unsupported Ubuntu version!"
785                     ;;
786             esac
787             ;;
788         *)
789             die "Unsupported distro or OS!"
790             ;;
791     esac
792
793     arch=$(uname -m) || {
794         die "Get CPU architecture failed."
795     }
796
797     case "${arch}" in
798         "aarch64")
799             IMAGE_VER_FILE="${IMAGE_VER_FILE}_ARM"
800             ;;
801         *)
802             ;;
803     esac
804 }
805
806
807 function select_tags () {
808
809     # Variables read:
810     # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
811     # - TEST_CODE - String affecting test selection, usually jenkins job name.
812     # - DUT - CSIT test/ subdirectory, set while processing tags.
813     # - TEST_TAG_STRING - String selecting tags, from gerrit comment.
814     #   Can be unset.
815     # - TOPOLOGIES_DIR - Path to existing directory with available tpologies.
816     # - BASH_FUNCTION_DIR - Directory with input files to process.
817     # Variables set:
818     # - TAGS - Array of processed tag boolean expressions.
819     # - SELECTION_MODE - Selection criteria [test, suite, include, exclude].
820
821     set -exuo pipefail
822
823     # NIC SELECTION
824     case "${TEST_CODE}" in
825         *"1n-aws"*)
826             start_pattern='^  SUT:'
827             ;;
828         *)
829             start_pattern='^  TG:'
830             ;;
831     esac
832     end_pattern='^ \? \?[A-Za-z0-9]\+:'
833     # Remove the sections from topology file
834     sed_command="/${start_pattern}/,/${end_pattern}/d"
835     # All topologies NICs
836     available=$(sed "${sed_command}" "${TOPOLOGIES_DIR}"/* \
837                 | grep -hoP "model: \K.*" | sort -u)
838     # Selected topology NICs
839     reserved=$(sed "${sed_command}" "${WORKING_TOPOLOGY}" \
840                | grep -hoP "model: \K.*" | sort -u)
841     # All topologies NICs - Selected topology NICs
842     exclude_nics=($(comm -13 <(echo "${reserved}") <(echo "${available}"))) || {
843         die "Computation of excluded NICs failed."
844     }
845
846     # Select default NIC tag.
847     case "${TEST_CODE}" in
848         *"3n-snr"*)
849             default_nic="nic_intel-e822cq"
850             ;;
851         *"3n-tsh"*)
852             default_nic="nic_intel-x520-da2"
853             ;;
854         *"3n-icx"* | *"2n-icx"*)
855             default_nic="nic_intel-xxv710"
856             ;;
857         *"2n-clx"* | *"2n-zn2"*)
858             default_nic="nic_intel-xxv710"
859             ;;
860         *"2n-tx2"* | *"3n-alt"* | *"mrr-daily-master")
861             default_nic="nic_intel-xl710"
862             ;;
863         *"1n-aws"* | *"2n-aws"* | *"3n-aws"*)
864             default_nic="nic_amazon-nitro-50g"
865             ;;
866         *)
867             default_nic="nic_intel-x710"
868             ;;
869     esac
870
871     sed_nic_sub_cmd="sed s/\${default_nic}/${default_nic}/"
872     awk_nics_sub_cmd=""
873     awk_nics_sub_cmd+='gsub("xxv710","25ge2p1xxv710");'
874     awk_nics_sub_cmd+='gsub("x710","10ge2p1x710");'
875     awk_nics_sub_cmd+='gsub("xl710","40ge2p1xl710");'
876     awk_nics_sub_cmd+='gsub("x520-da2","10ge2p1x520");'
877     awk_nics_sub_cmd+='gsub("cx556a","100ge2p1cx556a");'
878     awk_nics_sub_cmd+='gsub("e810cq","100ge2p1e810cq");'
879     awk_nics_sub_cmd+='gsub("vic1227","10ge2p1vic1227");'
880     awk_nics_sub_cmd+='gsub("vic1385","40ge2p1vic1385");'
881     awk_nics_sub_cmd+='gsub("nitro-50g","50ge1p1ENA");'
882     awk_nics_sub_cmd+='if ($9 =="drv_avf") drv="avf-";'
883     awk_nics_sub_cmd+='else if ($9 =="drv_rdma_core") drv ="rdma-";'
884     awk_nics_sub_cmd+='else if ($9 =="drv_mlx5_core") drv ="mlx5-";'
885     awk_nics_sub_cmd+='else if ($9 =="drv_af_xdp") drv ="af-xdp-";'
886     awk_nics_sub_cmd+='else drv="";'
887     awk_nics_sub_cmd+='if ($1 =="-") cores="";'
888     awk_nics_sub_cmd+='else cores=$1;'
889     awk_nics_sub_cmd+='print "*"$7"-" drv $11"-"$5"."$3"-" cores "-" drv $11"-"$5'
890
891     # Tag file directory shorthand.
892     tfd="${JOB_SPECS_DIR}"
893     case "${TEST_CODE}" in
894         # Select specific performance tests based on jenkins job type variable.
895         *"device"* )
896             readarray -t test_tag_array <<< $(grep -v "#" \
897                 ${tfd}/vpp_device/${DUT}-${NODENESS}-${FLAVOR}.md |
898                 awk {"$awk_nics_sub_cmd"} || echo "devicetest") || die
899             SELECTION_MODE="--test"
900             ;;
901         *"hoststack-daily"* )
902             readarray -t test_tag_array <<< $(grep -v "#" \
903                 ${tfd}/hoststack_daily/${DUT}-${NODENESS}-${FLAVOR}.md |
904                 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
905             SELECTION_MODE="--test"
906             ;;
907         *"ndrpdr-weekly"* )
908             readarray -t test_tag_array <<< $(grep -v "#" \
909                 ${tfd}/ndrpdr_weekly/${DUT}-${NODENESS}-${FLAVOR}.md |
910                 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
911             SELECTION_MODE="--test"
912             ;;
913         *"mrr-daily"* )
914             readarray -t test_tag_array <<< $(grep -v "#" \
915                 ${tfd}/mrr_daily/${DUT}-${NODENESS}-${FLAVOR}.md |
916                 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
917             SELECTION_MODE="--test"
918             ;;
919         *"mrr-weekly"* )
920             readarray -t test_tag_array <<< $(grep -v "#" \
921                 ${tfd}/mrr_weekly/${DUT}-${NODENESS}-${FLAVOR}.md |
922                 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
923             SELECTION_MODE="--test"
924             ;;
925         *"report-iterative"* )
926             test_sets=(${TEST_TAG_STRING//:/ })
927             # Run only one test set per run
928             report_file=${test_sets[0]}.md
929             readarray -t test_tag_array <<< $(grep -v "#" \
930                 ${tfd}/report_iterative/${NODENESS}-${FLAVOR}/${report_file} |
931                 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
932             SELECTION_MODE="--test"
933             ;;
934         *"report-coverage"* )
935             test_sets=(${TEST_TAG_STRING//:/ })
936             # Run only one test set per run
937             report_file=${test_sets[0]}.md
938             readarray -t test_tag_array <<< $(grep -v "#" \
939                 ${tfd}/report_coverage/${NODENESS}-${FLAVOR}/${report_file} |
940                 awk {"$awk_nics_sub_cmd"} || echo "perftest") || die
941             SELECTION_MODE="--test"
942             ;;
943         * )
944             if [[ -z "${TEST_TAG_STRING-}" ]]; then
945                 # If nothing is specified, we will run pre-selected tests by
946                 # following tags.
947                 test_tag_array=("mrrAND${default_nic}AND1cAND64bANDethip4-ip4base"
948                                 "mrrAND${default_nic}AND1cAND78bANDethip6-ip6base"
949                                 "mrrAND${default_nic}AND1cAND64bANDeth-l2bdbasemaclrn"
950                                 "mrrAND${default_nic}AND1cAND64bANDeth-l2xcbase"
951                                 "!drv_af_xdp" "!drv_avf")
952             else
953                 # If trigger contains tags, split them into array.
954                 test_tag_array=(${TEST_TAG_STRING//:/ })
955             fi
956             SELECTION_MODE="--include"
957             ;;
958     esac
959
960     # Blacklisting certain tags per topology.
961     #
962     # Reasons for blacklisting:
963     # - ipsechw - Blacklisted on testbeds without crypto hardware accelerator.
964     case "${TEST_CODE}" in
965         *"1n-vbox"*)
966             test_tag_array+=("!avf")
967             test_tag_array+=("!vhost")
968             test_tag_array+=("!flow")
969             ;;
970         *"1n_tx2"*)
971             test_tag_array+=("!flow")
972             ;;
973         *"2n-clx"*)
974             test_tag_array+=("!ipsechw")
975             ;;
976         *"2n-icx"*)
977             test_tag_array+=("!ipsechw")
978             ;;
979         *"3n-icx"*)
980             test_tag_array+=("!ipsechw")
981             # Not enough nic_intel-xxv710 to support double link tests.
982             test_tag_array+=("!3_node_double_link_topoANDnic_intel-xxv710")
983             ;;
984         *"2n-zn2"*)
985             test_tag_array+=("!ipsechw")
986             ;;
987         *"2n-tx2"* | *"3n-alt"*)
988             test_tag_array+=("!ipsechw")
989             ;;
990         *"3n-snr"*)
991             ;;
992         *"3n-tsh"*)
993             # 3n-tsh only has x520 NICs which don't work with AVF
994             test_tag_array+=("!drv_avf")
995             test_tag_array+=("!ipsechw")
996             ;;
997         *"1n-aws"* | *"2n-aws"* | *"3n-aws"*)
998             test_tag_array+=("!ipsechw")
999             ;;
1000     esac
1001
1002     # We will add excluded NICs.
1003     test_tag_array+=("${exclude_nics[@]/#/!NIC_}")
1004
1005     TAGS=()
1006     prefix=""
1007
1008     set +x
1009     if [[ "${TEST_CODE}" == "vpp-"* ]]; then
1010         if [[ "${TEST_CODE}" != *"device"* ]]; then
1011             # Automatic prefixing for VPP perf jobs to limit the NIC used and
1012             # traffic evaluation to MRR.
1013             if [[ "${TEST_TAG_STRING-}" == *"nic_"* ]]; then
1014                 prefix="${prefix}mrrAND"
1015             else
1016                 prefix="${prefix}mrrAND${default_nic}AND"
1017             fi
1018         fi
1019     fi
1020     for tag in "${test_tag_array[@]}"; do
1021         if [[ "${tag}" == "!"* ]]; then
1022             # Exclude tags are not prefixed.
1023             TAGS+=("${tag}")
1024         elif [[ "${tag}" == " "* || "${tag}" == *"perftest"* ]]; then
1025             # Badly formed tag expressions can trigger way too much tests.
1026             set -x
1027             warn "The following tag expression hints at bad trigger: ${tag}"
1028             warn "Possible cause: Multiple triggers in a single comment."
1029             die "Aborting to avoid triggering too many tests."
1030         elif [[ "${tag}" == *"OR"* ]]; then
1031             # If OR had higher precedence than AND, it would be useful here.
1032             # Some people think it does, thus triggering way too much tests.
1033             set -x
1034             warn "The following tag expression hints at bad trigger: ${tag}"
1035             warn "Operator OR has lower precedence than AND. Use space instead."
1036             die "Aborting to avoid triggering too many tests."
1037         elif [[ "${tag}" != "" && "${tag}" != "#"* ]]; then
1038             # Empty and comment lines are skipped.
1039             # Other lines are normal tags, they are to be prefixed.
1040             TAGS+=("${prefix}${tag}")
1041         fi
1042     done
1043     set -x
1044 }
1045
1046
1047 function select_topology () {
1048
1049     # Variables read:
1050     # - NODENESS - Node multiplicity of testbed, either "2n" or "3n".
1051     # - FLAVOR - Node flavor string, e.g. "clx" or "skx".
1052     # - CSIT_DIR - Path to existing root of local CSIT git repository.
1053     # - TOPOLOGIES_DIR - Path to existing directory with available topologies.
1054     # Variables set:
1055     # - TOPOLOGIES - Array of paths to suitable topology yaml files.
1056     # - TOPOLOGIES_TAGS - Tag expression selecting tests for the topology.
1057     # Functions called:
1058     # - die - Print to stderr and exit.
1059
1060     set -exuo pipefail
1061
1062     case_text="${NODENESS}_${FLAVOR}"
1063     case "${case_text}" in
1064         "1n_vbox")
1065             TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*vpp_device*.template )
1066             TOPOLOGIES_TAGS="2_node_single_link_topo"
1067             ;;
1068         "1n_skx" | "1n_tx2")
1069             TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*vpp_device*.template )
1070             TOPOLOGIES_TAGS="2_node_single_link_topo"
1071             ;;
1072         "2n_skx")
1073             TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_skx*.yaml )
1074             TOPOLOGIES_TAGS="2_node_*_link_topo"
1075             ;;
1076         "2n_zn2")
1077             TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_zn2*.yaml )
1078             TOPOLOGIES_TAGS="2_node_*_link_topo"
1079             ;;
1080         "3n_skx")
1081             TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_skx*.yaml )
1082             TOPOLOGIES_TAGS="3_node_*_link_topo"
1083             ;;
1084         "3n_icx")
1085             TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_icx*.yaml )
1086             TOPOLOGIES_TAGS="3_node_*_link_topo"
1087             ;;
1088         "2n_clx")
1089             TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_clx*.yaml )
1090             TOPOLOGIES_TAGS="2_node_*_link_topo"
1091             ;;
1092         "2n_icx")
1093             TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_icx*.yaml )
1094             TOPOLOGIES_TAGS="2_node_*_link_topo"
1095             ;;
1096         "3n_snr")
1097             TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_snr*.yaml )
1098             TOPOLOGIES_TAGS="3_node_single_link_topo"
1099             ;;
1100         "3n_tsh")
1101             TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_tsh*.yaml )
1102             TOPOLOGIES_TAGS="3_node_single_link_topo"
1103             ;;
1104         "2n_tx2")
1105             TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n_tx2*.yaml )
1106             TOPOLOGIES_TAGS="2_node_single_link_topo"
1107             ;;
1108         "3n_alt")
1109             TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n_alt*.yaml )
1110             TOPOLOGIES_TAGS="3_node_single_link_topo"
1111             ;;
1112         "1n_aws")
1113             TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*1n-aws*.yaml )
1114             TOPOLOGIES_TAGS="1_node_single_link_topo"
1115             ;;
1116         "2n_aws")
1117             TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*2n-aws*.yaml )
1118             TOPOLOGIES_TAGS="2_node_single_link_topo"
1119             ;;
1120         "3n_aws")
1121             TOPOLOGIES=( "${TOPOLOGIES_DIR}"/*3n-aws*.yaml )
1122             TOPOLOGIES_TAGS="3_node_single_link_topo"
1123             ;;
1124         *)
1125             # No falling back to default, that should have been done
1126             # by the function which has set NODENESS and FLAVOR.
1127             die "Unknown specification: ${case_text}"
1128     esac
1129
1130     if [[ -z "${TOPOLOGIES-}" ]]; then
1131         die "No applicable topology found!"
1132     fi
1133 }
1134
1135
1136 function set_environment_variables () {
1137
1138     # Depending on testbed topology, overwrite defaults set in the
1139     # resources/libraries/python/Constants.py file
1140     #
1141     # Variables read:
1142     # - TEST_CODE - String affecting test selection, usually jenkins job name.
1143     # Variables set:
1144     # See specific cases
1145
1146     set -exuo pipefail
1147
1148     case "${TEST_CODE}" in
1149         *"1n-aws"* | *"2n-aws"* | *"3n-aws"*)
1150             # T-Rex 2.88+ workaround for ENA NICs.
1151             export TREX_RX_DESCRIPTORS_COUNT=1024
1152             export TREX_EXTRA_CMDLINE="--mbuf-factor 19"
1153             export TREX_CORE_COUNT=6
1154             # Settings to prevent duration stretching.
1155             export PERF_TRIAL_STL_DELAY=0.1
1156             ;;
1157         *"2n-zn2"*)
1158             # Maciek's workaround for Zen2 with lower amount of cores.
1159             export TREX_CORE_COUNT=14
1160     esac
1161 }
1162
1163
1164 function untrap_and_unreserve_testbed () {
1165
1166     # Use this as a trap function to ensure testbed does not remain reserved.
1167     # Perhaps call directly before script exit, to free testbed for other jobs.
1168     # This function is smart enough to avoid multiple unreservations (so safe).
1169     # Topo cleanup is executed (call it best practice), ignoring failures.
1170     #
1171     # Hardcoded values:
1172     # - default message to die with if testbed might remain reserved.
1173     # Arguments:
1174     # - ${1} - Message to die with if unreservation fails. Default hardcoded.
1175     # Variables read (by inner function):
1176     # - WORKING_TOPOLOGY - Path to topology yaml file of the reserved testbed.
1177     # - PYTHON_SCRIPTS_DIR - Path to directory holding Python scripts.
1178     # Variables written:
1179     # - WORKING_TOPOLOGY - Set to empty string on successful unreservation.
1180     # Trap unregistered:
1181     # - EXIT - Failure to untrap is reported, but ignored otherwise.
1182     # Functions called:
1183     # - die - Print to stderr and exit.
1184     # - ansible_playbook - Perform an action using ansible, see ansible.sh
1185
1186     set -xo pipefail
1187     set +eu  # We do not want to exit early in a "teardown" function.
1188     trap - EXIT || echo "Trap deactivation failed, continuing anyway."
1189     wt="${WORKING_TOPOLOGY}"  # Just to avoid too long lines.
1190     if [[ -z "${wt-}" ]]; then
1191         set -eu
1192         warn "Testbed looks unreserved already. Trap removal failed before?"
1193     else
1194         ansible_playbook "cleanup" || true
1195         python3 "${PYTHON_SCRIPTS_DIR}/topo_reservation.py" -c -t "${wt}" || {
1196             die "${1:-FAILED TO UNRESERVE, FIX MANUALLY.}" 2
1197         }
1198         case "${TEST_CODE}" in
1199             *"1n-aws"* | *"2n-aws"* | *"3n-aws"*)
1200                 terraform_destroy || die "Failed to call terraform destroy."
1201                 ;;
1202             *)
1203                 ;;
1204         esac
1205         WORKING_TOPOLOGY=""
1206         set -eu
1207     fi
1208 }
1209
1210
1211 function warn () {
1212
1213     # Print the message to standard error.
1214     #
1215     # Arguments:
1216     # - ${@} - The text of the message.
1217
1218     set -exuo pipefail
1219
1220     echo "$@" >&2
1221 }