blob: 93f4b7e2b19cc96318e1fa3b8e2ec5fb8bc6a126 [file] [log] [blame]
Gary Wu13111e92018-09-27 11:31:33 -07001#!/bin/bash -x
Gary Wu9abb61c2018-09-27 10:38:50 -07002#
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
22function 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
42if [ $# -eq 0 ]
43then
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
55fi
56
57if [ -z "$WORKSPACE" ]; then
58 export WORKSPACE=`git rev-parse --show-toplevel`
59fi
60rm -rf $WORKSPACE/archives
61mkdir -p $WORKSPACE/archives
62
Gary Wu13111e92018-09-27 11:31:33 -070063if [ -f ${WORKSPACE}/${1}/testplan.txt ]; then
Gary Wu9abb61c2018-09-27 10:38:50 -070064 export TESTPLAN="${1}"
65else
Gary Wu13111e92018-09-27 11:31:33 -070066 echo "testplan not found: ${WORKSPACE}/${TESTPLAN}/testplan.txt"
Gary Wu9abb61c2018-09-27 10:38:50 -070067 exit 2
68fi
69
70
71export TESTOPTIONS="${2}"
72
73if [ -z "$3" ]; then
Gary Wu13111e92018-09-27 11:31:33 -070074 CI=${WORKSPACE}/../../ci-management
Gary Wu9abb61c2018-09-27 10:38:50 -070075else
76 CI=${3}
77fi
78
79
80
81
Gary Wu13111e92018-09-27 11:31:33 -070082TESTPLANDIR=${WORKSPACE}/${TESTPLAN}
Gary Wu9abb61c2018-09-27 10:38:50 -070083
84# Assume that if ROBOT_VENV is set, we don't need to reinstall robot
85if [ -f ${WORKSPACE}/env.properties ]; then
86 source ${WORKSPACE}/env.properties
Gary Wu9abb61c2018-09-27 10:38:50 -070087fi
Gary Wu13111e92018-09-27 11:31:33 -070088if [ -f ${ROBOT_VENV}/bin/activate ]; then
Gary Wu9abb61c2018-09-27 10:38:50 -070089 source ${ROBOT_VENV}/bin/activate
Gary Wu13111e92018-09-27 11:31:33 -070090else
91 source $CI/jjb/integration/include-raw-integration-install-robotframework.sh
Gary Wu9abb61c2018-09-27 10:38:50 -070092fi
93
94# install required Robot libraries
95pip install robotframework-selenium2library==1.8.0 robotframework-extendedselenium2library==0.9.1
96
97# install eteutils
98mkdir -p ${ROBOT_VENV}/src/onap
99rm -rf ${ROBOT_VENV}/src/onap/testsuite
100git clone https://gerrit.onap.org/r/testsuite/python-testing-utils.git ${ROBOT_VENV}/src/onap/testsuite/python-testing-utils
DR695H9d4cf182019-04-25 11:34:38 -0400101git -C ${ROBOT_VENV}/src/onap/testsuite/python-testing-utils checkout master
kaihlavi59175682019-04-25 15:58:23 +0300102pip install --upgrade ${ROBOT_VENV}/src/onap/testsuite/python-testing-utils/robotframework-onap
Gary Wu9abb61c2018-09-27 10:38:50 -0700103
104pip freeze
105
106# install chrome driver
107google-chrome --version
108if [ ! -x ${ROBOT_VENV}/bin/chromedriver ]; then
109 pushd ${ROBOT_VENV}/bin
110 wget -N http://chromedriver.storage.googleapis.com/2.35/chromedriver_linux64.zip
111 unzip chromedriver_linux64.zip
112 chmod +x chromedriver
113 popd
114fi
115
116
117WORKDIR=`mktemp -d --suffix=-robot-workdir`
118cd ${WORKDIR}
119
120
121set +u
122set -x
123
124
125# Add csit scripts to PATH
Gary Wu13111e92018-09-27 11:31:33 -0700126export PATH=${PATH}:${WORKSPACE}/docker/scripts:${WORKSPACE}/scripts:${ROBOT_VENV}/bin
127export SCRIPTS=${WORKSPACE}/scripts
Gary Wu9abb61c2018-09-27 10:38:50 -0700128export ROBOT_VARIABLES=
129
130# Sign in to nexus3 docker repo
131docker login -u anonymous -p anonymous nexus3.onap.org:10001
132
133# Run setup script plan if it exists
134cd ${TESTPLANDIR}
135SETUP=${TESTPLANDIR}/setup.sh
136if [ -f ${SETUP} ]; then
137 echo "Running setup script ${SETUP}"
138 source ${SETUP}
139fi
140
141# show memory consumption after all docker instances initialized
142docker_stats | tee $WORKSPACE/archives/_sysinfo-1-after-setup.txt
143
144# Run test plan
145cd $WORKDIR
146echo "Reading the testplan:"
Gary Wu13111e92018-09-27 11:31:33 -0700147cat ${TESTPLANDIR}/testplan.txt | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${WORKSPACE}/tests/|" > testplan.txt
Gary Wu9abb61c2018-09-27 10:38:50 -0700148cat testplan.txt
149SUITES=$( xargs -a testplan.txt )
150
151echo ROBOT_VARIABLES=${ROBOT_VARIABLES}
152echo "Starting Robot test suites ${SUITES} ..."
153set +e
154python -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${TESTOPTIONS} ${SUITES}
155RESULT=$?
156set -e
157echo "RESULT: " $RESULT
158rsync -av $WORKDIR/ $WORKSPACE/archives
159
160# Record list of active docker containers
161docker ps --format "{{.Image}}" > $WORKSPACE/archives/_docker-images.log
162
163# show memory consumption after all docker instances initialized
164docker_stats | tee $WORKSPACE/archives/_sysinfo-2-after-robot.txt
165
166# Run teardown script plan if it exists
167cd ${TESTPLANDIR}
168TEARDOWN=${TESTPLANDIR}/teardown.sh
169if [ -f ${TEARDOWN} ]; then
170 echo "Running teardown script ${TEARDOWN}"
171 source ${TEARDOWN}
172fi
173
174# TODO: do something with the output
175
176exit $RESULT