Gary Wu | 9138702 | 2017-06-16 13:06:20 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 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 | |
| 63 | if [ -f ${WORKSPACE}/test/csit/${1}/testplan.txt ]; then |
| 64 | export TESTPLAN="${1}" |
| 65 | else |
| 66 | echo "testplan not found: ${WORKSPACE}/test/csit/${TESTPLAN}/testplan.txt" |
| 67 | exit 2 |
| 68 | fi |
| 69 | |
| 70 | |
| 71 | export TESTOPTIONS="${2}" |
| 72 | |
| 73 | if [ -z "$3" ]; then |
| 74 | CI=${WORKSPACE}/../ci-management |
| 75 | else |
| 76 | CI=${3} |
| 77 | fi |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | TESTPLANDIR=${WORKSPACE}/test/csit/${TESTPLAN} |
| 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 |
| 87 | source ${ROBOT_VENV}/bin/activate |
| 88 | fi |
| 89 | if ! type pybot > /dev/null; then |
| 90 | rm -f ${WORKSPACE}/env.properties |
| 91 | source $CI/jjb/integration/include-raw-integration-install-robotframework.sh |
| 92 | source ${WORKSPACE}/env.properties |
| 93 | source ${ROBOT_VENV}/bin/activate |
| 94 | fi |
| 95 | |
Gary Wu | 94f347b | 2017-09-18 12:45:00 -0700 | [diff] [blame^] | 96 | # install required Robot libraries |
| 97 | pip install --upgrade robotframework-extendedselenium2library |
| 98 | |
Gary Wu | 290fe98 | 2017-09-14 15:18:09 -0700 | [diff] [blame] | 99 | # install eteutils |
Gary Wu | 84d2f20 | 2017-09-15 13:17:56 -0700 | [diff] [blame] | 100 | mkdir -p ${ROBOT_VENV}/src/onap |
| 101 | rm -rf ${ROBOT_VENV}/src/onap/testsuite |
| 102 | git clone https://gerrit.onap.org/r/testsuite/python-testing-utils.git ${ROBOT_VENV}/src/onap/testsuite/python-testing-utils |
| 103 | pip install --upgrade ${ROBOT_VENV}/src/onap/testsuite/python-testing-utils |
Gary Wu | 290fe98 | 2017-09-14 15:18:09 -0700 | [diff] [blame] | 104 | |
Gary Wu | 9138702 | 2017-06-16 13:06:20 -0700 | [diff] [blame] | 105 | |
| 106 | WORKDIR=`mktemp -d --suffix=-robot-workdir` |
| 107 | cd ${WORKDIR} |
| 108 | |
| 109 | |
| 110 | set +u |
| 111 | set -x |
| 112 | |
| 113 | |
| 114 | # Add csit scripts to PATH |
| 115 | export PATH=${PATH}:${WORKSPACE}/test/csit/docker/scripts:${WORKSPACE}/test/csit/scripts |
| 116 | export SCRIPTS=${WORKSPACE}/test/csit/scripts |
| 117 | export ROBOT_VARIABLES= |
| 118 | |
Gary Wu | 1346b68 | 2017-08-08 08:04:44 -0700 | [diff] [blame] | 119 | # Sign in to nexus3 docker repo |
| 120 | docker login -u anonymous -p anonymous nexus3.onap.org:10001 |
| 121 | |
Gary Wu | 9138702 | 2017-06-16 13:06:20 -0700 | [diff] [blame] | 122 | # Run setup script plan if it exists |
| 123 | cd ${TESTPLANDIR} |
| 124 | SETUP=${TESTPLANDIR}/setup.sh |
| 125 | if [ -f ${SETUP} ]; then |
| 126 | echo "Running setup script ${SETUP}" |
| 127 | source ${SETUP} |
| 128 | fi |
| 129 | |
| 130 | # show memory consumption after all docker instances initialized |
| 131 | docker_stats | tee $WORKSPACE/archives/_sysinfo-1-after-setup.txt |
| 132 | |
| 133 | # Run test plan |
| 134 | cd $WORKDIR |
| 135 | echo "Reading the testplan:" |
| 136 | cat ${TESTPLANDIR}/testplan.txt | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${WORKSPACE}/test/csit/tests/|" > testplan.txt |
| 137 | cat testplan.txt |
| 138 | SUITES=$( xargs -a testplan.txt ) |
| 139 | |
| 140 | echo ROBOT_VARIABLES=${ROBOT_VARIABLES} |
| 141 | echo "Starting Robot test suites ${SUITES} ..." |
| 142 | set +e |
| 143 | pybot -N ${TESTPLAN} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${TESTOPTIONS} ${SUITES} |
| 144 | RESULT=$? |
| 145 | set -e |
| 146 | echo "RESULT: " $RESULT |
| 147 | rsync -av $WORKDIR/ $WORKSPACE/archives |
| 148 | |
| 149 | # Record list of active docker containers |
| 150 | docker ps --format "{{.Image}}" > $WORKSPACE/archives/_docker-images.log |
| 151 | |
| 152 | # show memory consumption after all docker instances initialized |
| 153 | docker_stats | tee $WORKSPACE/archives/_sysinfo-2-after-robot.txt |
| 154 | |
| 155 | # Run teardown script plan if it exists |
| 156 | cd ${TESTPLANDIR} |
| 157 | TEARDOWN=${TESTPLANDIR}/teardown.sh |
| 158 | if [ -f ${TEARDOWN} ]; then |
| 159 | echo "Running teardown script ${TEARDOWN}" |
| 160 | source ${TEARDOWN} |
| 161 | fi |
| 162 | |
| 163 | # TODO: do something with the output |
| 164 | |
| 165 | exit $RESULT |