Merge "Correct path for service-instance"
[integration/csit.git] / run-csit.sh
1 #!/bin/bash -x
2 #
3 # Copyright 2016-2017 Huawei Technologies Co., Ltd.
4 # Modification Copyright 2019 © Samsung Electronics Co., Ltd.
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
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
43     echo
44     echo "Usage: $0 plans/<project>/<functionality> [<robot-options>]"
45     echo
46     echo "    <project>, <functionality>, <robot-options>:  "
47     echo "        The same values as for the '{project}-csit-{functionality}' JJB job template."
48     echo
49     exit 1
50 fi
51
52 if [ -z "$WORKSPACE" ]; then
53     export WORKSPACE=`git rev-parse --show-toplevel`
54 fi
55
56 rm -rf $WORKSPACE/archives
57 mkdir -p $WORKSPACE/archives
58
59 if [ -f ${WORKSPACE}/${1}/testplan.txt ]; then
60     export TESTPLAN="${1}"
61 else
62     echo "testplan not found: ${WORKSPACE}/${TESTPLAN}/testplan.txt"
63     exit 2
64 fi
65
66 export TESTOPTIONS="${2}"
67
68 TESTPLANDIR=${WORKSPACE}/${TESTPLAN}
69
70 # Run installation of prerequired libraries
71 source ${WORKSPACE}/prepare-csit.sh
72
73 # Activate the virtualenv containing all the required libraries installed by prepare-csit.sh
74 source "${ROBOT_VENV}/bin/activate"
75
76 WORKDIR=`mktemp -d --suffix=-robot-workdir`
77 cd ${WORKDIR}
78
79 set +u
80 set -x
81
82 # Add csit scripts to PATH
83 export PATH=${PATH}:${WORKSPACE}/docker/scripts:${WORKSPACE}/scripts:${ROBOT_VENV}/bin
84 export SCRIPTS=${WORKSPACE}/scripts
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:"
104 cat ${TESTPLANDIR}/testplan.txt | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${WORKSPACE}/tests/|" > testplan.txt
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