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. |
arkadiusz.adamski | 2b1e8d0 | 2021-05-24 12:50:40 +0100 | [diff] [blame] | 6 | # Modification Copyright 2021. 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 |
| 30 | if [[ ${WORKDIR} ]]; then |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 31 | rsync -av "${WORKDIR}/" "${WORKSPACE}/csit/archives/${PROJECT}" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 32 | fi |
| 33 | # Record list of active docker containers |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 34 | docker ps --format "{{.Image}}" > "${WORKSPACE}/csit/archives/${PROJECT}/_docker-images.log" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 35 | |
| 36 | # show memory consumption after all docker instances initialized |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 37 | docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-2-after-robot.txt" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 38 | fi |
| 39 | # Run teardown script plan if it exists |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 40 | cd "${TESTPLANDIR}/plans/" |
| 41 | TEARDOWN="${TESTPLANDIR}/plans/teardown.sh" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 42 | if [ -f "${TEARDOWN}" ]; then |
| 43 | echo "Running teardown script ${TEARDOWN}" |
| 44 | source_safely "${TEARDOWN}" |
| 45 | fi |
| 46 | # TODO: do something with the output |
| 47 | exit $rc |
| 48 | } |
| 49 | |
| 50 | # ensure that teardown and other finalizing steps are always executed |
| 51 | trap on_exit EXIT |
| 52 | |
| 53 | function docker_stats(){ |
| 54 | #General memory details |
| 55 | echo "> top -bn1 | head -3" |
| 56 | top -bn1 | head -3 |
| 57 | echo |
| 58 | |
| 59 | echo "> free -h" |
| 60 | free -h |
| 61 | echo |
| 62 | |
| 63 | #Memory details per Docker |
| 64 | echo "> docker ps" |
| 65 | docker ps |
| 66 | echo |
| 67 | |
| 68 | echo "> docker stats --no-stream" |
| 69 | docker stats --no-stream |
| 70 | echo |
| 71 | } |
| 72 | |
| 73 | # save current set options |
| 74 | function save_set() { |
| 75 | RUN_CSIT_SAVE_SET="$-" |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 76 | RUN_CSIT_SHELLOPTS="${SHELLOPTS}" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | # load the saved set options |
| 80 | function load_set() { |
| 81 | _setopts="$-" |
| 82 | |
| 83 | # bash shellopts |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 84 | for i in $(echo "${SHELLOPTS}" | tr ':' ' ') ; do |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 85 | set +o ${i} |
| 86 | done |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 87 | for i in $(echo "${RUN_CSIT_SHELLOPTS}" | tr ':' ' ') ; do |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 88 | set -o ${i} |
| 89 | done |
| 90 | |
| 91 | # other options |
| 92 | for i in $(echo "$_setopts" | sed 's/./& /g') ; do |
| 93 | set +${i} |
| 94 | done |
| 95 | set -${RUN_CSIT_SAVE_SET} |
| 96 | } |
| 97 | |
| 98 | # set options for quick bailout when error |
| 99 | function harden_set() { |
| 100 | set -xeo pipefail |
| 101 | set +u # enabled it would probably fail too many often |
| 102 | } |
| 103 | |
| 104 | # relax set options so the sourced file will not fail |
| 105 | # the responsibility is shifted to the sourced file... |
| 106 | function relax_set() { |
| 107 | set +e |
| 108 | set +o pipefail |
| 109 | } |
| 110 | |
| 111 | # wrapper for sourcing a file |
| 112 | function source_safely() { |
| 113 | [ -z "$1" ] && return 1 |
| 114 | relax_set |
| 115 | . "$1" |
| 116 | load_set |
| 117 | } |
| 118 | |
| 119 | # |
| 120 | # main |
| 121 | # |
| 122 | |
| 123 | # set and save options for quick failure |
| 124 | harden_set && save_set |
| 125 | |
| 126 | if [ $# -eq 0 ] |
| 127 | then |
| 128 | echo |
| 129 | echo "Usage: $0 <project> [<robot-options>]" |
| 130 | echo |
| 131 | echo " <project> <robot-options>: " |
| 132 | echo |
| 133 | exit 1 |
| 134 | fi |
| 135 | |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 136 | if [ -z "${WORKSPACE}" ]; then |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 137 | export WORKSPACE=$(git rev-parse --show-toplevel) |
| 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" |
| 142 | export SCRIPTS="${WORKSPACE}/csit" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 143 | export ROBOT_VARIABLES= |
| 144 | |
| 145 | # get the plan from git clone |
| 146 | source ${SCRIPTS}/get-branch-mariadb.sh |
| 147 | |
| 148 | export PROJECT="${1}" |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 149 | |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 150 | cd ${WORKSPACE} |
| 151 | |
Jim Hahn | b3a962f | 2021-05-12 11:33:43 -0400 | [diff] [blame] | 152 | export TESTPLANDIR="${WORKSPACE}/csit/${PROJECT}" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 153 | export TESTOPTIONS="${2}" |
| 154 | |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 155 | rm -rf "${WORKSPACE}/csit/archives/${PROJECT}" |
| 156 | mkdir -p "${WORKSPACE}/csit/archives/${PROJECT}" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 157 | |
| 158 | # Run installation of prerequired libraries |
| 159 | source_safely "${SCRIPTS}/prepare-csit.sh" |
| 160 | |
| 161 | # Activate the virtualenv containing all the required libraries installed by prepare-csit.sh |
| 162 | source_safely "${ROBOT_VENV}/bin/activate" |
| 163 | |
| 164 | WORKDIR=$(mktemp -d --suffix=-robot-workdir) |
| 165 | cd "${WORKDIR}" |
| 166 | |
| 167 | # Sign in to nexus3 docker repo |
| 168 | docker login -u docker -p docker nexus3.onap.org:10001 |
| 169 | |
Jim Hahn | 39b7b98 | 2021-03-16 14:52:34 -0400 | [diff] [blame] | 170 | # Generate keystore to be used by repos |
| 171 | ${SCRIPTS}/gen_keystore.sh |
| 172 | cp ${SCRIPTS}/config/ks.jks ${SCRIPTS}/config/drools/custom/policy-keystore |
| 173 | cp ${SCRIPTS}/config/ks.jks ${SCRIPTS}/config/drools-apps/custom/policy-keystore |
| 174 | |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 175 | # Run setup script plan if it exists |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 176 | cd "${TESTPLANDIR}/plans/" |
| 177 | SETUP="${TESTPLANDIR}/plans/setup.sh" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 178 | if [ -f "${SETUP}" ]; then |
| 179 | echo "Running setup script ${SETUP}" |
| 180 | source_safely "${SETUP}" |
| 181 | fi |
| 182 | |
| 183 | # show memory consumption after all docker instances initialized |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 184 | docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-1-after-setup.txt" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 185 | |
| 186 | # Run test plan |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 187 | cd "${WORKDIR}" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 188 | echo "Reading the testplan:" |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 189 | cat "${TESTPLANDIR}/plans/testplan.txt" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${TESTPLANDIR}/tests/|" > testplan.txt |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 190 | cat testplan.txt |
| 191 | SUITES=$( xargs -a testplan.txt ) |
| 192 | |
| 193 | echo ROBOT_VARIABLES="${ROBOT_VARIABLES}" |
| 194 | echo "Starting Robot test suites ${SUITES} ..." |
| 195 | relax_set |
arkadiusz.adamski | 2b1e8d0 | 2021-05-24 12:50:40 +0100 | [diff] [blame] | 196 | python3 -m robot.run -N ${PROJECT} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${SUITES} |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 197 | RESULT=$? |
| 198 | load_set |
Jim Hahn | 3486a92 | 2021-05-10 15:36:30 -0400 | [diff] [blame] | 199 | echo "RESULT: ${RESULT}" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 200 | # 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] | 201 | exit ${RESULT} |