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. |
| 6 | # |
| 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | # you may not use this file except in compliance with the License. |
| 9 | # You may obtain a copy of the License at |
| 10 | # |
| 11 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | # |
| 13 | # Unless required by applicable law or agreed to in writing, software |
| 14 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | # See the License for the specific language governing permissions and |
| 17 | # limitations under the License. |
| 18 | # |
| 19 | # $1 functionality |
| 20 | # $2 robot options |
| 21 | |
| 22 | # |
| 23 | # functions |
| 24 | # |
| 25 | |
| 26 | function on_exit(){ |
| 27 | rc=$? |
| 28 | if [[ ${WORKSPACE} ]]; then |
| 29 | if [[ ${WORKDIR} ]]; then |
Taka Cho | 63d6592 | 2021-01-19 13:56:54 -0500 | [diff] [blame] | 30 | rsync -av "$WORKDIR/" "$WORKSPACE/csit/archives/$TESTPLAN" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 31 | fi |
| 32 | # Record list of active docker containers |
Taka Cho | 63d6592 | 2021-01-19 13:56:54 -0500 | [diff] [blame] | 33 | docker ps --format "{{.Image}}" > "$WORKSPACE/csit/archives/$TESTPLAN/_docker-images.log" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 34 | |
| 35 | # show memory consumption after all docker instances initialized |
Taka Cho | 63d6592 | 2021-01-19 13:56:54 -0500 | [diff] [blame] | 36 | docker_stats | tee "$WORKSPACE/csit/archives/$TESTPLAN/_sysinfo-2-after-robot.txt" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 37 | fi |
| 38 | # Run teardown script plan if it exists |
| 39 | cd "${TESTPLANDIR}/csit/plans/" |
| 40 | TEARDOWN="${TESTPLANDIR}/csit/plans/teardown.sh" |
| 41 | if [ -f "${TEARDOWN}" ]; then |
| 42 | echo "Running teardown script ${TEARDOWN}" |
| 43 | source_safely "${TEARDOWN}" |
| 44 | fi |
| 45 | # TODO: do something with the output |
| 46 | exit $rc |
| 47 | } |
| 48 | |
| 49 | # ensure that teardown and other finalizing steps are always executed |
| 50 | trap on_exit EXIT |
| 51 | |
| 52 | function docker_stats(){ |
| 53 | #General memory details |
| 54 | echo "> top -bn1 | head -3" |
| 55 | top -bn1 | head -3 |
| 56 | echo |
| 57 | |
| 58 | echo "> free -h" |
| 59 | free -h |
| 60 | echo |
| 61 | |
| 62 | #Memory details per Docker |
| 63 | echo "> docker ps" |
| 64 | docker ps |
| 65 | echo |
| 66 | |
| 67 | echo "> docker stats --no-stream" |
| 68 | docker stats --no-stream |
| 69 | echo |
| 70 | } |
| 71 | |
| 72 | # save current set options |
| 73 | function save_set() { |
| 74 | RUN_CSIT_SAVE_SET="$-" |
| 75 | RUN_CSIT_SHELLOPTS="$SHELLOPTS" |
| 76 | } |
| 77 | |
| 78 | # load the saved set options |
| 79 | function load_set() { |
| 80 | _setopts="$-" |
| 81 | |
| 82 | # bash shellopts |
| 83 | for i in $(echo "$SHELLOPTS" | tr ':' ' ') ; do |
| 84 | set +o ${i} |
| 85 | done |
| 86 | for i in $(echo "$RUN_CSIT_SHELLOPTS" | tr ':' ' ') ; do |
| 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 | |
| 135 | if [ -z "$WORKSPACE" ]; then |
| 136 | export WORKSPACE=$(git rev-parse --show-toplevel) |
| 137 | fi |
| 138 | |
| 139 | # Add csit scripts to PATH |
Taka Cho | 78bbba7 | 2021-01-15 11:20:06 -0500 | [diff] [blame] | 140 | export PATH="${PATH}:${WORKSPACE}/csit:${WORKSPACE}/scripts:${ROBOT_VENV}/bin" |
| 141 | export SCRIPTS="${WORKSPACE}/csit" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 142 | export ROBOT_VARIABLES= |
| 143 | |
| 144 | # get the plan from git clone |
| 145 | source ${SCRIPTS}/get-branch-mariadb.sh |
| 146 | |
| 147 | export PROJECT="${1}" |
| 148 | rm -rf ${WORKSPACE}/${PROJECT} |
| 149 | mkdir ${WORKSPACE}/${PROJECT} |
| 150 | cd ${WORKSPACE} |
| 151 | |
| 152 | # get the plan from git clone |
| 153 | if ! `git clone -b ${GERRIT_BRANCH} --single-branch git://gerrit-mirror-ap.onap.org/mirror/policy/${PROJECT}.git` ; then |
| 154 | echo "repo not found: policy/${PROJECT}" |
| 155 | exit 1 |
| 156 | fi |
| 157 | |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 158 | if [ -f "${WORKSPACE}/${1}/csit/plans/testplan.txt" ]; then |
| 159 | export TESTPLAN="${1}" |
| 160 | else |
| 161 | echo "testplan not found: ${WORKSPACE}/${1}/csit/plans/testplan.txt" |
| 162 | exit 2 |
| 163 | fi |
| 164 | |
| 165 | export TESTOPTIONS="${2}" |
| 166 | |
Taka Cho | 63d6592 | 2021-01-19 13:56:54 -0500 | [diff] [blame] | 167 | rm -rf "$WORKSPACE/csit/archives/$TESTPLAN" |
| 168 | mkdir -p "$WORKSPACE/csit/archives/$TESTPLAN" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 169 | |
| 170 | TESTPLANDIR="${WORKSPACE}/${TESTPLAN}" |
| 171 | |
| 172 | # Run installation of prerequired libraries |
| 173 | source_safely "${SCRIPTS}/prepare-csit.sh" |
| 174 | |
| 175 | # Activate the virtualenv containing all the required libraries installed by prepare-csit.sh |
| 176 | source_safely "${ROBOT_VENV}/bin/activate" |
| 177 | |
| 178 | WORKDIR=$(mktemp -d --suffix=-robot-workdir) |
| 179 | cd "${WORKDIR}" |
| 180 | |
| 181 | # Sign in to nexus3 docker repo |
| 182 | docker login -u docker -p docker nexus3.onap.org:10001 |
| 183 | |
Jim Hahn | 39b7b98 | 2021-03-16 14:52:34 -0400 | [diff] [blame] | 184 | # Generate keystore to be used by repos |
| 185 | ${SCRIPTS}/gen_keystore.sh |
| 186 | cp ${SCRIPTS}/config/ks.jks ${SCRIPTS}/config/drools/custom/policy-keystore |
| 187 | cp ${SCRIPTS}/config/ks.jks ${SCRIPTS}/config/drools-apps/custom/policy-keystore |
| 188 | |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 189 | # Run setup script plan if it exists |
| 190 | cd "${TESTPLANDIR}/csit/plans/" |
| 191 | SETUP="${TESTPLANDIR}/csit/plans/setup.sh" |
| 192 | if [ -f "${SETUP}" ]; then |
| 193 | echo "Running setup script ${SETUP}" |
| 194 | source_safely "${SETUP}" |
| 195 | fi |
| 196 | |
| 197 | # show memory consumption after all docker instances initialized |
Taka Cho | 63d6592 | 2021-01-19 13:56:54 -0500 | [diff] [blame] | 198 | docker_stats | tee "$WORKSPACE/csit/archives/$TESTPLAN/_sysinfo-1-after-setup.txt" |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 199 | |
| 200 | # Run test plan |
| 201 | cd "$WORKDIR" |
| 202 | echo "Reading the testplan:" |
| 203 | cat "${TESTPLANDIR}/csit/plans/testplan.txt" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${TESTPLANDIR}/csit/tests/|" > testplan.txt |
| 204 | cat testplan.txt |
| 205 | SUITES=$( xargs -a testplan.txt ) |
| 206 | |
| 207 | echo ROBOT_VARIABLES="${ROBOT_VARIABLES}" |
| 208 | echo "Starting Robot test suites ${SUITES} ..." |
| 209 | relax_set |
Taka Cho | 78bbba7 | 2021-01-15 11:20:06 -0500 | [diff] [blame] | 210 | python -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${SUITES} |
Taka Cho | 6d188af | 2021-01-11 16:48:33 -0500 | [diff] [blame] | 211 | RESULT=$? |
| 212 | load_set |
| 213 | echo "RESULT: $RESULT" |
| 214 | # Note that the final steps are done in on_exit function after this exit! |
| 215 | exit $RESULT |