blob: e7457adc22436fa3ddecd76d6a381100d9251c3e [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.
kaihlavi203e43a2019-08-16 16:02:38 +03004# Modification Copyright 2019 © Samsung Electronics Co., Ltd.
Gary Wu9abb61c2018-09-27 10:38:50 -07005#
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 Wu9abb61c2018-09-27 10:38:50 -070020
21function 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
41if [ $# -eq 0 ]
42then
kaihlavi203e43a2019-08-16 16:02:38 +030043 echo
44 echo "Usage: $0 plans/<project>/<functionality> [<robot-options>]"
Gary Wu9abb61c2018-09-27 10:38:50 -070045 echo
46 echo " <project>, <functionality>, <robot-options>: "
47 echo " The same values as for the '{project}-csit-{functionality}' JJB job template."
48 echo
Gary Wu9abb61c2018-09-27 10:38:50 -070049 exit 1
50fi
51
52if [ -z "$WORKSPACE" ]; then
53 export WORKSPACE=`git rev-parse --show-toplevel`
54fi
kaihlavi203e43a2019-08-16 16:02:38 +030055
Gary Wu9abb61c2018-09-27 10:38:50 -070056rm -rf $WORKSPACE/archives
57mkdir -p $WORKSPACE/archives
58
Gary Wu13111e92018-09-27 11:31:33 -070059if [ -f ${WORKSPACE}/${1}/testplan.txt ]; then
Gary Wu9abb61c2018-09-27 10:38:50 -070060 export TESTPLAN="${1}"
61else
Gary Wu13111e92018-09-27 11:31:33 -070062 echo "testplan not found: ${WORKSPACE}/${TESTPLAN}/testplan.txt"
Gary Wu9abb61c2018-09-27 10:38:50 -070063 exit 2
64fi
65
Gary Wu9abb61c2018-09-27 10:38:50 -070066export TESTOPTIONS="${2}"
67
Gary Wu13111e92018-09-27 11:31:33 -070068TESTPLANDIR=${WORKSPACE}/${TESTPLAN}
Gary Wu9abb61c2018-09-27 10:38:50 -070069
kaihlavi9f5700f2019-08-27 11:30:51 +030070# Run installation of prerequired libraries
71source ${WORKSPACE}/prepare-csit.sh
Gary Wu9abb61c2018-09-27 10:38:50 -070072
kaihlavi203e43a2019-08-16 16:02:38 +030073# Activate the virtualenv containing all the required libraries installed by prepare-csit.sh
74source "${ROBOT_VENV}/bin/activate"
Gary Wu9abb61c2018-09-27 10:38:50 -070075
76WORKDIR=`mktemp -d --suffix=-robot-workdir`
77cd ${WORKDIR}
78
Gary Wu9abb61c2018-09-27 10:38:50 -070079set +u
80set -x
81
Gary Wu9abb61c2018-09-27 10:38:50 -070082# Add csit scripts to PATH
Gary Wu13111e92018-09-27 11:31:33 -070083export PATH=${PATH}:${WORKSPACE}/docker/scripts:${WORKSPACE}/scripts:${ROBOT_VENV}/bin
84export SCRIPTS=${WORKSPACE}/scripts
Gary Wu9abb61c2018-09-27 10:38:50 -070085export ROBOT_VARIABLES=
86
87# Sign in to nexus3 docker repo
88docker login -u anonymous -p anonymous nexus3.onap.org:10001
89
90# Run setup script plan if it exists
91cd ${TESTPLANDIR}
92SETUP=${TESTPLANDIR}/setup.sh
93if [ -f ${SETUP} ]; then
94 echo "Running setup script ${SETUP}"
95 source ${SETUP}
96fi
97
98# show memory consumption after all docker instances initialized
99docker_stats | tee $WORKSPACE/archives/_sysinfo-1-after-setup.txt
100
101# Run test plan
102cd $WORKDIR
103echo "Reading the testplan:"
Gary Wu13111e92018-09-27 11:31:33 -0700104cat ${TESTPLANDIR}/testplan.txt | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${WORKSPACE}/tests/|" > testplan.txt
Gary Wu9abb61c2018-09-27 10:38:50 -0700105cat testplan.txt
106SUITES=$( xargs -a testplan.txt )
107
108echo ROBOT_VARIABLES=${ROBOT_VARIABLES}
109echo "Starting Robot test suites ${SUITES} ..."
110set +e
111python -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${TESTOPTIONS} ${SUITES}
112RESULT=$?
113set -e
114echo "RESULT: " $RESULT
115rsync -av $WORKDIR/ $WORKSPACE/archives
116
117# Record list of active docker containers
118docker ps --format "{{.Image}}" > $WORKSPACE/archives/_docker-images.log
119
120# show memory consumption after all docker instances initialized
121docker_stats | tee $WORKSPACE/archives/_sysinfo-2-after-robot.txt
122
123# Run teardown script plan if it exists
124cd ${TESTPLANDIR}
125TEARDOWN=${TESTPLANDIR}/teardown.sh
126if [ -f ${TEARDOWN} ]; then
127 echo "Running teardown script ${TEARDOWN}"
128 source ${TEARDOWN}
129fi
130
131# TODO: do something with the output
132
133exit $RESULT