Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 1 | #!/bin/bash -x |
| 2 | # |
| 3 | # Copyright 2016-2017 Huawei Technologies Co., Ltd. |
| 4 | # Modification Copyright 2019 © Samsung Electronics Co., Ltd. |
| 5 | # Modification Copyright 2021 © AT&T Intellectual Property. |
adheli.tavares | c6eb02a | 2023-02-02 08:44:51 +0000 | [diff] [blame] | 6 | # Modification Copyright 2021-2023 Nordix Foundation. |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 7 | # |
| 8 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | # you may not use this file except in compliance with the License. |
| 10 | # You may obtain a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | # See the License for the specific language governing permissions and |
| 18 | # limitations under the License. |
| 19 | # |
| 20 | # $1 functionality |
| 21 | # $2 robot options |
| 22 | |
| 23 | # |
| 24 | # functions |
| 25 | # |
| 26 | |
| 27 | function on_exit(){ |
| 28 | rc=$? |
| 29 | if [[ ${WORKSPACE} ]]; then |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 30 | # Record list of active docker containers |
adheli.tavares | 9fc9fa4 | 2023-02-09 11:56:27 +0000 | [diff] [blame] | 31 | docker ps --format "table {{ .Names }}\t{{ .Status }}" |
liamfallon | c4bd9e4 | 2022-09-08 09:56:47 +0100 | [diff] [blame] | 32 | |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 33 | # show memory consumption after all docker instances initialized |
liamfallon | c4bd9e4 | 2022-09-08 09:56:47 +0100 | [diff] [blame] | 34 | docker_stats |
adheli.tavares | 9fc9fa4 | 2023-02-09 11:56:27 +0000 | [diff] [blame] | 35 | |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 36 | source_safely ${WORKSPACE}/compose/stop-compose.sh |
| 37 | |
adheli.tavares | 9fc9fa4 | 2023-02-09 11:56:27 +0000 | [diff] [blame] | 38 | if [[ ${WORKDIR} ]]; then |
| 39 | rsync -av "${WORKDIR}/" "${WORKSPACE}/csit/archives/${PROJECT}" |
| 40 | fi |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 41 | rm -rf ${WORKSPACE}/models |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 42 | fi |
| 43 | # TODO: do something with the output |
| 44 | exit $rc |
| 45 | } |
| 46 | |
| 47 | # ensure that teardown and other finalizing steps are always executed |
| 48 | trap on_exit EXIT |
| 49 | |
| 50 | function docker_stats(){ |
liamfallon | faac45b | 2022-09-01 12:05:47 +0100 | [diff] [blame] | 51 | # General memory details |
| 52 | if [ "$(uname -s)" == "Darwin" ] |
| 53 | then |
liamfallon | faac45b | 2022-09-01 12:05:47 +0100 | [diff] [blame] | 54 | sh -c "top -l1 | head -10" |
| 55 | echo |
| 56 | else |
liamfallon | faac45b | 2022-09-01 12:05:47 +0100 | [diff] [blame] | 57 | sh -c "top -bn1 | head -3" |
| 58 | echo |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 59 | |
liamfallon | faac45b | 2022-09-01 12:05:47 +0100 | [diff] [blame] | 60 | sh -c "free -h" |
| 61 | echo |
| 62 | fi |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 63 | |
liamfallon | faac45b | 2022-09-01 12:05:47 +0100 | [diff] [blame] | 64 | # Memory details per Docker |
adheli.tavares | 9fc9fa4 | 2023-02-09 11:56:27 +0000 | [diff] [blame] | 65 | docker ps --format "table {{ .Names }}\t{{ .Status }}" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 66 | echo |
| 67 | |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 68 | docker stats --no-stream |
| 69 | echo |
| 70 | } |
| 71 | |
| 72 | # save current set options |
| 73 | function save_set() { |
| 74 | RUN_CSIT_SAVE_SET="$-" |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 75 | RUN_CSIT_SHELLOPTS="${SHELLOPTS}" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | # load the saved set options |
| 79 | function load_set() { |
| 80 | _setopts="$-" |
| 81 | |
| 82 | # bash shellopts |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 83 | for i in $(echo "${SHELLOPTS}" | tr ':' ' ') ; do |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 84 | set +o ${i} |
| 85 | done |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 86 | for i in $(echo "${RUN_CSIT_SHELLOPTS}" | tr ':' ' ') ; do |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 87 | set -o ${i} |
| 88 | done |
| 89 | |
| 90 | # other options |
| 91 | for i in $(echo "$_setopts" | sed 's/./& /g') ; do |
| 92 | set +${i} |
| 93 | done |
| 94 | set -${RUN_CSIT_SAVE_SET} |
| 95 | } |
| 96 | |
| 97 | # set options for quick bailout when error |
| 98 | function harden_set() { |
| 99 | set -xeo pipefail |
| 100 | set +u # enabled it would probably fail too many often |
| 101 | } |
| 102 | |
| 103 | # relax set options so the sourced file will not fail |
| 104 | # the responsibility is shifted to the sourced file... |
| 105 | function relax_set() { |
| 106 | set +e |
| 107 | set +o pipefail |
| 108 | } |
| 109 | |
| 110 | # wrapper for sourcing a file |
| 111 | function source_safely() { |
| 112 | [ -z "$1" ] && return 1 |
| 113 | relax_set |
| 114 | . "$1" |
| 115 | load_set |
| 116 | } |
| 117 | |
| 118 | # |
| 119 | # main |
| 120 | # |
| 121 | |
| 122 | # set and save options for quick failure |
| 123 | harden_set && save_set |
| 124 | |
| 125 | if [ $# -eq 0 ] |
| 126 | then |
| 127 | echo |
| 128 | echo "Usage: $0 <project> [<robot-options>]" |
| 129 | echo |
| 130 | echo " <project> <robot-options>: " |
| 131 | echo |
| 132 | exit 1 |
| 133 | fi |
| 134 | |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 135 | if [ -z "${WORKSPACE}" ]; then |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 136 | WORKSPACE=$(git rev-parse --show-toplevel) |
| 137 | export WORKSPACE |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 138 | fi |
| 139 | |
| 140 | # Add csit scripts to PATH |
Taka Cho | 78bbba7 | 2021-01-15 11:20:06 -0500 | [diff] [blame] | 141 | export PATH="${PATH}:${WORKSPACE}/csit:${WORKSPACE}/scripts:${ROBOT_VENV}/bin" |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 142 | export SCRIPTS="${WORKSPACE}/csit/resources/scripts" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 143 | export ROBOT_VARIABLES= |
| 144 | |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 145 | export PROJECT="${1}" |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 146 | |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 147 | cd "${WORKSPACE}" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 148 | |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 149 | rm -rf "${WORKSPACE}/csit/archives/${PROJECT}" |
| 150 | mkdir -p "${WORKSPACE}/csit/archives/${PROJECT}" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 151 | |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 152 | # Run installation of pre-required libraries |
adheli.tavares | c6eb02a | 2023-02-02 08:44:51 +0000 | [diff] [blame] | 153 | source_safely "${SCRIPTS}/prepare-robot-env.sh" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 154 | |
adheli.tavares | c6eb02a | 2023-02-02 08:44:51 +0000 | [diff] [blame] | 155 | # Activate the virtualenv containing all the required libraries installed by prepare-robot-env.sh |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 156 | source_safely "${ROBOT_VENV}/bin/activate" |
| 157 | |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 158 | export TEST_PLAN_DIR="${WORKSPACE}/csit/resources/tests" |
| 159 | export TEST_OPTIONS="${2}" |
| 160 | |
liamfallon | faac45b | 2022-09-01 12:05:47 +0100 | [diff] [blame] | 161 | WORKDIR=$(mktemp -d) |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 162 | cd "${WORKDIR}" |
| 163 | |
| 164 | # Sign in to nexus3 docker repo |
| 165 | docker login -u docker -p docker nexus3.onap.org:10001 |
| 166 | |
| 167 | # Run setup script plan if it exists |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 168 | SETUP="${SCRIPTS}/setup-${PROJECT}.sh" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 169 | if [ -f "${SETUP}" ]; then |
| 170 | echo "Running setup script ${SETUP}" |
| 171 | source_safely "${SETUP}" |
| 172 | fi |
| 173 | |
| 174 | # show memory consumption after all docker instances initialized |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 175 | docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-1-after-setup.txt" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 176 | |
| 177 | # Run test plan |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 178 | cd "${WORKDIR}" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 179 | echo "Reading the testplan:" |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 180 | echo "${SUITES}" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${TEST_PLAN_DIR}/|" > testplan.txt |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 181 | cat testplan.txt |
liamfallon | faac45b | 2022-09-01 12:05:47 +0100 | [diff] [blame] | 182 | SUITES=$( xargs < testplan.txt ) |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 183 | |
| 184 | echo ROBOT_VARIABLES="${ROBOT_VARIABLES}" |
| 185 | echo "Starting Robot test suites ${SUITES} ..." |
| 186 | relax_set |
adheli.tavares | 1f339f8 | 2023-02-17 15:14:07 +0000 | [diff] [blame] | 187 | python3 -m robot.run -N "${PROJECT}" -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${SUITES} |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 188 | RESULT=$? |
| 189 | load_set |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 190 | echo "RESULT: ${RESULT}" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 191 | # Note that the final steps are done in on_exit function after this exit! |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 192 | exit ${RESULT} |