3 # Copyright 2016-2017 Huawei Technologies Co., Ltd.
4 # Modification Copyright 2019 © Samsung Electronics Co., Ltd.
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 # $1 project/functionality
27 rsync -av "$WORKDIR/" "$WORKSPACE/archives"
29 # Record list of active docker containers
30 docker ps --format "{{.Image}}" > "$WORKSPACE/archives/_docker-images.log"
32 # show memory consumption after all docker instances initialized
33 docker_stats | tee "$WORKSPACE/archives/_sysinfo-2-after-robot.txt"
35 # Run teardown script plan if it exists
37 TEARDOWN="${TESTPLANDIR}/teardown.sh"
38 if [ -f "${TEARDOWN}" ]; then
39 echo "Running teardown script ${TEARDOWN}"
40 source_safely "${TEARDOWN}"
42 # TODO: do something with the output
45 # ensure that teardown and other finalizing steps are always executed
48 function docker_stats(){
49 #General memory details
50 echo "> top -bn1 | head -3"
58 #Memory details per Docker
63 echo "> docker stats --no-stream"
64 docker stats --no-stream
68 # save current set options
70 RUN_CSIT_SAVE_SET="$-"
71 RUN_CSIT_SHELLOPTS="$SHELLOPTS"
74 # load the saved set options
79 for i in $(echo "$SHELLOPTS" | tr ':' ' ') ; do
82 for i in $(echo "$RUN_CSIT_SHELLOPTS" | tr ':' ' ') ; do
87 for i in $(echo "$_setopts" | sed 's/./& /g') ; do
90 set -${RUN_CSIT_SAVE_SET}
93 # set options for quick bailout when error
94 function harden_set() {
96 set +u # enabled it would probably fail too many often
99 # relax set options so the sourced file will not fail
100 # the responsibility is shifted to the sourced file...
101 function relax_set() {
106 # wrapper for sourcing a file
107 function source_safely() {
108 [ -z "$1" ] && return 1
118 # set and save options for quick failure
119 harden_set && save_set
124 echo "Usage: $0 plans/<project>/<functionality> [<robot-options>]"
126 echo " <project>, <functionality>, <robot-options>: "
127 echo " The same values as for the '{project}-csit-{functionality}' JJB job template."
132 if [ -z "$WORKSPACE" ]; then
133 export WORKSPACE=$(git rev-parse --show-toplevel)
136 rm -rf "$WORKSPACE/archives"
137 mkdir -p "$WORKSPACE/archives"
139 if [ -f "${WORKSPACE}/${1}/testplan.txt" ]; then
140 export TESTPLAN="${1}"
142 echo "testplan not found: ${WORKSPACE}/${TESTPLAN}/testplan.txt"
146 export TESTOPTIONS="${2}"
148 TESTPLANDIR="${WORKSPACE}/${TESTPLAN}"
150 # Run installation of prerequired libraries
151 source_safely "${WORKSPACE}/prepare-csit.sh"
153 # Activate the virtualenv containing all the required libraries installed by prepare-csit.sh
154 source_safely "${ROBOT_VENV}/bin/activate"
156 WORKDIR=$(mktemp -d --suffix=-robot-workdir)
159 # Add csit scripts to PATH
160 export PATH="${PATH}:${WORKSPACE}/docker/scripts:${WORKSPACE}/scripts:${ROBOT_VENV}/bin"
161 export SCRIPTS="${WORKSPACE}/scripts"
162 export ROBOT_VARIABLES=
164 # Sign in to nexus3 docker repo
165 docker login -u docker -p docker nexus3.onap.org:10001
167 # Run setup script plan if it exists
169 SETUP="${TESTPLANDIR}/setup.sh"
170 if [ -f "${SETUP}" ]; then
171 echo "Running setup script ${SETUP}"
172 source_safely "${SETUP}"
175 # show memory consumption after all docker instances initialized
176 docker_stats | tee "$WORKSPACE/archives/_sysinfo-1-after-setup.txt"
180 echo "Reading the testplan:"
181 cat "${TESTPLANDIR}/testplan.txt" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${WORKSPACE}/tests/|" > testplan.txt
183 SUITES=$( xargs -a testplan.txt )
185 echo ROBOT_VARIABLES="${ROBOT_VARIABLES}"
186 echo "Starting Robot test suites ${SUITES} ..."
188 python -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${TESTOPTIONS} ${SUITES}
191 echo "RESULT: $RESULT"
192 # Note that the final steps are done in on_exit function after this exit!