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. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
| 17 | # $1 project/functionality |
| 18 | # $2 robot options |
| 19 | # $3 ci-management repo location |
| 20 | |
| 21 | |
| 22 | function docker_stats(){ |
| 23 | #General memory details |
| 24 | echo "> top -bn1 | head -3" |
| 25 | top -bn1 | head -3 |
| 26 | echo |
| 27 | |
| 28 | echo "> free -h" |
| 29 | free -h |
| 30 | echo |
| 31 | |
| 32 | #Memory details per Docker |
| 33 | echo "> docker ps" |
| 34 | docker ps |
| 35 | echo |
| 36 | |
| 37 | echo "> docker stats --no-stream" |
| 38 | docker stats --no-stream |
| 39 | echo |
| 40 | } |
| 41 | |
| 42 | if [ $# -eq 0 ] |
| 43 | then |
| 44 | echo |
| 45 | echo "Usage: $0 plans/<project>/<functionality> [<robot-options>] [<ci-management-dir>]" |
| 46 | echo |
| 47 | echo " <project>, <functionality>, <robot-options>: " |
| 48 | echo " The same values as for the '{project}-csit-{functionality}' JJB job template." |
| 49 | echo |
| 50 | echo " <ci-management-dir>: " |
| 51 | echo " Path to the ci-management repo checked out locally. It not specified, " |
| 52 | echo " assumed to be adjacent to the integration repo directory." |
| 53 | echo |
| 54 | exit 1 |
| 55 | fi |
| 56 | |
| 57 | if [ -z "$WORKSPACE" ]; then |
| 58 | export WORKSPACE=`git rev-parse --show-toplevel` |
| 59 | fi |
| 60 | rm -rf $WORKSPACE/archives |
| 61 | mkdir -p $WORKSPACE/archives |
| 62 | |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 63 | if [ -f ${WORKSPACE}/${1}/testplan.txt ]; then |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 64 | export TESTPLAN="${1}" |
| 65 | else |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 66 | echo "testplan not found: ${WORKSPACE}/${TESTPLAN}/testplan.txt" |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 67 | exit 2 |
| 68 | fi |
| 69 | |
| 70 | |
| 71 | export TESTOPTIONS="${2}" |
| 72 | |
| 73 | if [ -z "$3" ]; then |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 74 | CI=${WORKSPACE}/../../ci-management |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 75 | else |
| 76 | CI=${3} |
| 77 | fi |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 82 | TESTPLANDIR=${WORKSPACE}/${TESTPLAN} |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 83 | |
| 84 | # Assume that if ROBOT_VENV is set, we don't need to reinstall robot |
| 85 | if [ -f ${WORKSPACE}/env.properties ]; then |
| 86 | source ${WORKSPACE}/env.properties |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 87 | fi |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 88 | if [ -f ${ROBOT_VENV}/bin/activate ]; then |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 89 | source ${ROBOT_VENV}/bin/activate |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 90 | else |
| 91 | source $CI/jjb/integration/include-raw-integration-install-robotframework.sh |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 92 | fi |
| 93 | |
| 94 | # install required Robot libraries |
| 95 | pip install robotframework-selenium2library==1.8.0 robotframework-extendedselenium2library==0.9.1 |
| 96 | |
| 97 | # install eteutils |
| 98 | mkdir -p ${ROBOT_VENV}/src/onap |
| 99 | rm -rf ${ROBOT_VENV}/src/onap/testsuite |
DR695H | 401430c | 2019-05-30 16:35:26 -0400 | [diff] [blame] | 100 | pip install --upgrade --extra-index-url="https://nexus3.onap.org/repository/PyPi.staging/simple" 'robotframework-onap==0.4' |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 101 | |
| 102 | pip freeze |
| 103 | |
| 104 | # install chrome driver |
| 105 | google-chrome --version |
| 106 | if [ ! -x ${ROBOT_VENV}/bin/chromedriver ]; then |
| 107 | pushd ${ROBOT_VENV}/bin |
| 108 | wget -N http://chromedriver.storage.googleapis.com/2.35/chromedriver_linux64.zip |
| 109 | unzip chromedriver_linux64.zip |
| 110 | chmod +x chromedriver |
| 111 | popd |
| 112 | fi |
| 113 | |
| 114 | |
| 115 | WORKDIR=`mktemp -d --suffix=-robot-workdir` |
| 116 | cd ${WORKDIR} |
| 117 | |
| 118 | |
| 119 | set +u |
| 120 | set -x |
| 121 | |
| 122 | |
| 123 | # Add csit scripts to PATH |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 124 | export PATH=${PATH}:${WORKSPACE}/docker/scripts:${WORKSPACE}/scripts:${ROBOT_VENV}/bin |
| 125 | export SCRIPTS=${WORKSPACE}/scripts |
Gary Wu | 9abb61c | 2018-09-27 10:38:50 -0700 | [diff] [blame] | 126 | export ROBOT_VARIABLES= |
| 127 | |
| 128 | # Sign in to nexus3 docker repo |
| 129 | docker login -u anonymous -p anonymous nexus3.onap.org:10001 |
| 130 | |
| 131 | # Run setup script plan if it exists |
| 132 | cd ${TESTPLANDIR} |
| 133 | SETUP=${TESTPLANDIR}/setup.sh |
| 134 | if [ -f ${SETUP} ]; then |
| 135 | echo "Running setup script ${SETUP}" |
| 136 | source ${SETUP} |
| 137 | fi |
| 138 | |
| 139 | # show memory consumption after all docker instances initialized |
| 140 | docker_stats | tee $WORKSPACE/archives/_sysinfo-1-after-setup.txt |
| 141 | |
| 142 | # Run test plan |
| 143 | cd $WORKDIR |
| 144 | echo "Reading the testplan:" |
Gary Wu | 13111e9 | 2018-09-27 11:31:33 -0700 | [diff] [blame] | 145 | 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] | 146 | cat testplan.txt |
| 147 | SUITES=$( xargs -a testplan.txt ) |
| 148 | |
| 149 | echo ROBOT_VARIABLES=${ROBOT_VARIABLES} |
| 150 | echo "Starting Robot test suites ${SUITES} ..." |
| 151 | set +e |
| 152 | python -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${TESTOPTIONS} ${SUITES} |
| 153 | RESULT=$? |
| 154 | set -e |
| 155 | echo "RESULT: " $RESULT |
| 156 | rsync -av $WORKDIR/ $WORKSPACE/archives |
| 157 | |
| 158 | # Record list of active docker containers |
| 159 | docker ps --format "{{.Image}}" > $WORKSPACE/archives/_docker-images.log |
| 160 | |
| 161 | # show memory consumption after all docker instances initialized |
| 162 | docker_stats | tee $WORKSPACE/archives/_sysinfo-2-after-robot.txt |
| 163 | |
| 164 | # Run teardown script plan if it exists |
| 165 | cd ${TESTPLANDIR} |
| 166 | TEARDOWN=${TESTPLANDIR}/teardown.sh |
| 167 | if [ -f ${TEARDOWN} ]; then |
| 168 | echo "Running teardown script ${TEARDOWN}" |
| 169 | source ${TEARDOWN} |
| 170 | fi |
| 171 | |
| 172 | # TODO: do something with the output |
| 173 | |
| 174 | exit $RESULT |