Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 1 | #!/bin/bash -x |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2016-2017 Huawei Technologies Co., Ltd. |
kaihlavi | 203e43a | 2019-08-16 16:02:38 +0300 | [diff] [blame] | 4 | # Modification Copyright 2019 © Samsung Electronics Co., Ltd. |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | # $1 project/functionality |
| 19 | # $2 robot options |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 20 | |
| 21 | function docker_stats(){ |
| 22 | #General memory details |
| 23 | echo "> top -bn1 | head -3" |
| 24 | top -bn1 | head -3 |
| 25 | echo |
| 26 | |
| 27 | echo "> free -h" |
| 28 | free -h |
| 29 | echo |
| 30 | |
| 31 | #Memory details per Docker |
| 32 | echo "> docker ps" |
| 33 | docker ps |
| 34 | echo |
| 35 | |
| 36 | echo "> docker stats --no-stream" |
| 37 | docker stats --no-stream |
| 38 | echo |
| 39 | } |
| 40 | |
| 41 | if [ $# -eq 0 ] |
| 42 | then |
kaihlavi | 203e43a | 2019-08-16 16:02:38 +0300 | [diff] [blame] | 43 | echo |
| 44 | echo "Usage: $0 plans/<project>/<functionality> [<robot-options>]" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 45 | echo |
| 46 | echo " <project>, <functionality>, <robot-options>: " |
| 47 | echo " The same values as for the '{project}-csit-{functionality}' JJB job template." |
| 48 | echo |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 49 | exit 1 |
| 50 | fi |
| 51 | |
| 52 | if [ -z "$WORKSPACE" ]; then |
| 53 | export WORKSPACE=`git rev-parse --show-toplevel` |
| 54 | fi |
kaihlavi | 203e43a | 2019-08-16 16:02:38 +0300 | [diff] [blame] | 55 | |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 56 | rm -rf $WORKSPACE/archives |
| 57 | mkdir -p $WORKSPACE/archives |
| 58 | |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 59 | if [ -f ${WORKSPACE}/${1}/testplan.txt ]; then |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 60 | export TESTPLAN="${1}" |
| 61 | else |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 62 | echo "testplan not found: ${WORKSPACE}/${TESTPLAN}/testplan.txt" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 63 | exit 2 |
| 64 | fi |
| 65 | |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 66 | export TESTOPTIONS="${2}" |
| 67 | |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 68 | TESTPLANDIR=${WORKSPACE}/${TESTPLAN} |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 69 | |
kaihlavi | 9f5700f | 2019-08-27 11:30:51 +0300 | [diff] [blame] | 70 | # Run installation of prerequired libraries |
| 71 | source ${WORKSPACE}/prepare-csit.sh |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 72 | |
kaihlavi | 203e43a | 2019-08-16 16:02:38 +0300 | [diff] [blame] | 73 | # Activate the virtualenv containing all the required libraries installed by prepare-csit.sh |
| 74 | source "${ROBOT_VENV}/bin/activate" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 75 | |
| 76 | WORKDIR=`mktemp -d --suffix=-robot-workdir` |
| 77 | cd ${WORKDIR} |
| 78 | |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 79 | set +u |
| 80 | set -x |
| 81 | |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 82 | # Add csit scripts to PATH |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 83 | export PATH=${PATH}:${WORKSPACE}/docker/scripts:${WORKSPACE}/scripts:${ROBOT_VENV}/bin |
| 84 | export SCRIPTS=${WORKSPACE}/scripts |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 85 | export ROBOT_VARIABLES= |
| 86 | |
| 87 | # Sign in to nexus3 docker repo |
| 88 | docker login -u anonymous -p anonymous nexus3.onap.org:10001 |
| 89 | |
| 90 | # Run setup script plan if it exists |
| 91 | cd ${TESTPLANDIR} |
| 92 | SETUP=${TESTPLANDIR}/setup.sh |
| 93 | if [ -f ${SETUP} ]; then |
| 94 | echo "Running setup script ${SETUP}" |
| 95 | source ${SETUP} |
| 96 | fi |
| 97 | |
| 98 | # show memory consumption after all docker instances initialized |
| 99 | docker_stats | tee $WORKSPACE/archives/_sysinfo-1-after-setup.txt |
| 100 | |
| 101 | # Run test plan |
| 102 | cd $WORKDIR |
| 103 | echo "Reading the testplan:" |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 104 | cat ${TESTPLANDIR}/testplan.txt | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${WORKSPACE}/tests/|" > testplan.txt |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 105 | cat testplan.txt |
| 106 | SUITES=$( xargs -a testplan.txt ) |
| 107 | |
| 108 | echo ROBOT_VARIABLES=${ROBOT_VARIABLES} |
| 109 | echo "Starting Robot test suites ${SUITES} ..." |
| 110 | set +e |
| 111 | python -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${TESTOPTIONS} ${SUITES} |
| 112 | RESULT=$? |
| 113 | set -e |
| 114 | echo "RESULT: " $RESULT |
| 115 | rsync -av $WORKDIR/ $WORKSPACE/archives |
| 116 | |
| 117 | # Record list of active docker containers |
| 118 | docker ps --format "{{.Image}}" > $WORKSPACE/archives/_docker-images.log |
| 119 | |
| 120 | # show memory consumption after all docker instances initialized |
| 121 | docker_stats | tee $WORKSPACE/archives/_sysinfo-2-after-robot.txt |
| 122 | |
| 123 | # Run teardown script plan if it exists |
| 124 | cd ${TESTPLANDIR} |
| 125 | TEARDOWN=${TESTPLANDIR}/teardown.sh |
| 126 | if [ -f ${TEARDOWN} ]; then |
| 127 | echo "Running teardown script ${TEARDOWN}" |
| 128 | source ${TEARDOWN} |
| 129 | fi |
| 130 | |
| 131 | # TODO: do something with the output |
| 132 | |
| 133 | exit $RESULT |