3 # Copyright 2016-2017 Huawei Technologies Co., Ltd.
4 # Modification Copyright 2019-2021 © Samsung Electronics Co., Ltd.
5 # Modification Copyright 2021 © highstreet-technologies GmbH
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
19 # $1 project/functionality
29 if [[ ${WORKSPACE} ]]; then
30 if [[ ${WORKDIR} ]]; then
31 rsync -av "$WORKDIR/" "$WORKSPACE/archives/$TESTPLAN"
33 # Record list of active docker containers
34 docker ps --format "{{.Image}}" > "$WORKSPACE/archives/$TESTPLAN/_docker-images.log"
36 # show memory consumption after all docker instances initialized
37 docker_stats | tee "$WORKSPACE/archives/$TESTPLAN/_sysinfo-2-after-robot.txt"
39 # Run teardown script plan if it exists
41 TEARDOWN="${TESTPLANDIR}/teardown.sh"
42 if [ -f "${TEARDOWN}" ]; then
43 echo "Running teardown script ${TEARDOWN}"
44 source_safely "${TEARDOWN}"
46 # TODO: do something with the output
49 # ensure that teardown and other finalizing steps are always executed
52 function docker_stats(){
53 #General memory details
54 echo "> top -bn1 | head -3"
62 #Memory details per Docker
67 echo "> docker stats --no-stream"
68 docker stats --no-stream
72 # save current set options
74 RUN_CSIT_SAVE_SET="$-"
75 RUN_CSIT_SHELLOPTS="$SHELLOPTS"
78 # load the saved set options
83 for i in $(echo "$SHELLOPTS" | tr ':' ' ') ; do
86 for i in $(echo "$RUN_CSIT_SHELLOPTS" | tr ':' ' ') ; do
91 for i in $(echo "$_setopts" | sed 's/./& /g') ; do
94 set -${RUN_CSIT_SAVE_SET}
97 # set options for quick bailout when error
98 function harden_set() {
100 set +u # enabled it would probably fail too many often
103 # relax set options so the sourced file will not fail
104 # the responsibility is shifted to the sourced file...
105 function relax_set() {
110 # wrapper for sourcing a file
111 function source_safely() {
112 [ -z "$1" ] && return 1
123 # set and save options for quick failure
124 harden_set && save_set
129 echo "Usage: $0 plans/<project>/<functionality> [<robot-options>]"
131 echo " <project>, <functionality>, <robot-options>: "
132 echo " The same values as for the '{project}-csit-{functionality}' JJB job template."
137 if [ -z "$WORKSPACE" ]; then
138 export WORKSPACE=$(git rev-parse --show-toplevel)
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 rm -rf "$WORKSPACE/archives/$TESTPLAN"
151 mkdir -p "$WORKSPACE/archives/$TESTPLAN"
153 TESTPLANDIR="${WORKSPACE}/${TESTPLAN}"
156 source_safely "${WORKSPACE}/sdnc-csit.env"
157 if [[ -z $ROBOT_IMAGE ]]; then
158 # Run installation of prerequired libraries
159 source_safely "${WORKSPACE}/prepare-csit.sh"
162 # Activate the virtualenv containing all the required libraries installed by prepare-csit.sh
163 source_safely "${ROBOT_VENV}/bin/activate"
166 WORKDIR=$(mktemp -d --suffix=-robot-workdir)
167 chmod a+rwx "${WORKDIR}"
168 echo "Additional info"
172 # Add csit scripts to PATH
173 export PATH="${PATH}:${WORKSPACE}/docker/scripts:${WORKSPACE}/scripts:${ROBOT_VENV}/bin"
174 export SCRIPTS="${WORKSPACE}/scripts"
175 export ROBOT_VARIABLES=
177 # Sign in to nexus3 docker repo
178 docker login -u docker -p docker nexus3.onap.org:10001
180 # Run setup script plan if it exists
182 SETUP="${TESTPLANDIR}/setup.sh"
183 if [ -f "${SETUP}" ]; then
184 echo "Running setup script ${SETUP}"
185 source_safely "${SETUP}"
188 # show memory consumption after all docker instances initialized
189 docker_stats | tee "$WORKSPACE/archives/$TESTPLAN/_sysinfo-1-after-setup.txt"
193 echo "Reading the testplan:"
194 cat "${TESTPLANDIR}/testplan.txt" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${WORKSPACE}/tests/|" > testplan.txt
196 SUITES=$( xargs -a testplan.txt )
198 echo ROBOT_VARIABLES="${ROBOT_VARIABLES}"
199 echo "Starting Robot test suites ${SUITES} ..."
202 # Runs an alternative robotframework setup as docker image in $ROBOT_IMAGE
203 # test suites will be executed within this docker container
204 # and results are stored as usual
205 if [[ -z $ROBOT_IMAGE ]]; then
206 echo "*** TRACE **** python is $(which python) [version $(python --version)]"
208 python -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${TESTOPTIONS} ${SUITES}
210 echo "*** TRACE **** python is running in a container"
211 docker run --net="host" \
212 -v ${WORKSPACE}:${WORKSPACE} -v ${WORKDIR}:${WORKDIR} $ROBOT_IMAGE \
213 python3 -B -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp --outputdir ${WORKDIR} ${ROBOT_VARIABLES} ${TESTOPTIONS} ${SUITES}
217 echo "RESULT: $RESULT"
218 # Note that the final steps are done in on_exit function after this exit!