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 if [[ ${WORKSPACE} ]]; then
28 if [[ ${WORKDIR} ]]; then
29 rsync -av "$WORKDIR/" "$WORKSPACE/archives"
31 # Record list of active docker containers
32 docker ps --format "{{.Image}}" > "$WORKSPACE/archives/_docker-images.log"
34 # show memory consumption after all docker instances initialized
35 docker_stats | tee "$WORKSPACE/archives/_sysinfo-2-after-robot.txt"
37 # Run teardown script plan if it exists
39 TEARDOWN="${TESTPLANDIR}/teardown.sh"
40 if [ -f "${TEARDOWN}" ]; then
41 echo "Running teardown script ${TEARDOWN}"
42 source_safely "${TEARDOWN}"
44 # TODO: do something with the output
47 # ensure that teardown and other finalizing steps are always executed
50 function docker_stats(){
51 #General memory details
52 echo "> top -bn1 | head -3"
60 #Memory details per Docker
65 echo "> docker stats --no-stream"
66 docker stats --no-stream
70 # save current set options
72 RUN_CSIT_SAVE_SET="$-"
73 RUN_CSIT_SHELLOPTS="$SHELLOPTS"
76 # load the saved set options
81 for i in $(echo "$SHELLOPTS" | tr ':' ' ') ; do
84 for i in $(echo "$RUN_CSIT_SHELLOPTS" | tr ':' ' ') ; do
89 for i in $(echo "$_setopts" | sed 's/./& /g') ; do
92 set -${RUN_CSIT_SAVE_SET}
95 # set options for quick bailout when error
96 function harden_set() {
98 set +u # enabled it would probably fail too many often
101 # relax set options so the sourced file will not fail
102 # the responsibility is shifted to the sourced file...
103 function relax_set() {
108 # wrapper for sourcing a file
109 function source_safely() {
110 [ -z "$1" ] && return 1
120 # set and save options for quick failure
121 harden_set && save_set
126 echo "Usage: $0 plans/<project>/<functionality> [<robot-options>]"
128 echo " <project>, <functionality>, <robot-options>: "
129 echo " The same values as for the '{project}-csit-{functionality}' JJB job template."
134 if [ -z "$WORKSPACE" ]; then
135 export WORKSPACE=$(git rev-parse --show-toplevel)
138 rm -rf "$WORKSPACE/archives"
139 mkdir -p "$WORKSPACE/archives"
141 if [ -f "${WORKSPACE}/${1}/testplan.txt" ]; then
142 export TESTPLAN="${1}"
144 echo "testplan not found: ${WORKSPACE}/${TESTPLAN}/testplan.txt"
148 export TESTOPTIONS="${2}"
150 TESTPLANDIR="${WORKSPACE}/${TESTPLAN}"
152 # Run installation of prerequired libraries
153 source_safely "${WORKSPACE}/prepare-csit.sh"
155 # Activate the virtualenv containing all the required libraries installed by prepare-csit.sh
156 source_safely "${ROBOT_VENV}/bin/activate"
158 WORKDIR=$(mktemp -d --suffix=-robot-workdir)
161 # Add csit scripts to PATH
162 export PATH="${PATH}:${WORKSPACE}/docker/scripts:${WORKSPACE}/scripts:${ROBOT_VENV}/bin"
163 export SCRIPTS="${WORKSPACE}/scripts"
164 export ROBOT_VARIABLES=
166 # Sign in to nexus3 docker repo
167 docker login -u docker -p docker nexus3.onap.org:10001
169 # Run setup script plan if it exists
171 SETUP="${TESTPLANDIR}/setup.sh"
172 if [ -f "${SETUP}" ]; then
173 echo "Running setup script ${SETUP}"
174 source_safely "${SETUP}"
177 # show memory consumption after all docker instances initialized
178 docker_stats | tee "$WORKSPACE/archives/_sysinfo-1-after-setup.txt"
182 echo "Reading the testplan:"
183 cat "${TESTPLANDIR}/testplan.txt" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${WORKSPACE}/tests/|" > testplan.txt
185 SUITES=$( xargs -a testplan.txt )
187 echo ROBOT_VARIABLES="${ROBOT_VARIABLES}"
188 echo "Starting Robot test suites ${SUITES} ..."
190 python -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${TESTOPTIONS} ${SUITES}
193 echo "RESULT: $RESULT"
194 # Note that the final steps are done in on_exit function after this exit!