3 # Copyright 2016-2017 Huawei Technologies Co., Ltd.
4 # Modification Copyright 2019-2021 © 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
28 if [[ ${WORKSPACE} ]]; then
29 if [[ ${WORKDIR} ]]; then
30 rsync -av "$WORKDIR/" "$WORKSPACE/archives/$TESTPLAN"
32 # Record list of active docker containers
33 docker ps --format "{{.Image}}" > "$WORKSPACE/archives/$TESTPLAN/_docker-images.log"
35 # show memory consumption after all docker instances initialized
36 docker_stats | tee "$WORKSPACE/archives/$TESTPLAN/_sysinfo-2-after-robot.txt"
38 # Run teardown script plan if it exists
40 TEARDOWN="${TESTPLANDIR}/teardown.sh"
41 if [ -f "${TEARDOWN}" ]; then
42 echo "Running teardown script ${TEARDOWN}"
43 source_safely "${TEARDOWN}"
45 # TODO: do something with the output
48 # ensure that teardown and other finalizing steps are always executed
51 function docker_stats(){
52 #General memory details
53 echo "> top -bn1 | head -3"
61 #Memory details per Docker
66 echo "> docker stats --no-stream"
67 docker stats --no-stream
71 # save current set options
73 RUN_CSIT_SAVE_SET="$-"
74 RUN_CSIT_SHELLOPTS="$SHELLOPTS"
77 # load the saved set options
82 for i in $(echo "$SHELLOPTS" | tr ':' ' ') ; do
85 for i in $(echo "$RUN_CSIT_SHELLOPTS" | tr ':' ' ') ; do
90 for i in $(echo "$_setopts" | sed 's/./& /g') ; do
93 set -${RUN_CSIT_SAVE_SET}
96 # set options for quick bailout when error
97 function harden_set() {
99 set +u # enabled it would probably fail too many often
102 # relax set options so the sourced file will not fail
103 # the responsibility is shifted to the sourced file...
104 function relax_set() {
109 # wrapper for sourcing a file
110 function source_safely() {
111 [ -z "$1" ] && return 1
122 # set and save options for quick failure
123 harden_set && save_set
128 echo "Usage: $0 plans/<project>/<functionality> [<robot-options>]"
130 echo " <project>, <functionality>, <robot-options>: "
131 echo " The same values as for the '{project}-csit-{functionality}' JJB job template."
136 if [ -z "$WORKSPACE" ]; then
137 export WORKSPACE=$(git rev-parse --show-toplevel)
140 if [ -f "${WORKSPACE}/${1}/testplan.txt" ]; then
141 export TESTPLAN="${1}"
143 echo "testplan not found: ${WORKSPACE}/${TESTPLAN}/testplan.txt"
147 export TESTOPTIONS="${2}"
149 rm -rf "$WORKSPACE/archives/$TESTPLAN"
150 mkdir -p "$WORKSPACE/archives/$TESTPLAN"
152 TESTPLANDIR="${WORKSPACE}/${TESTPLAN}"
155 source_safely "${WORKSPACE}/sdnc-csit.env"
157 # Run installation of prerequired libraries
158 source_safely "${WORKSPACE}/prepare-csit.sh"
160 # Activate the virtualenv containing all the required libraries installed by prepare-csit.sh
161 source_safely "${ROBOT_VENV}/bin/activate"
163 WORKDIR=$(mktemp -d --suffix=-robot-workdir)
166 # Add csit scripts to PATH
167 export PATH="${PATH}:${WORKSPACE}/docker/scripts:${WORKSPACE}/scripts:${ROBOT_VENV}/bin"
168 export SCRIPTS="${WORKSPACE}/scripts"
169 export ROBOT_VARIABLES=
171 # Sign in to nexus3 docker repo
172 docker login -u docker -p docker nexus3.onap.org:10001
174 # Run setup script plan if it exists
176 SETUP="${TESTPLANDIR}/setup.sh"
177 if [ -f "${SETUP}" ]; then
178 echo "Running setup script ${SETUP}"
179 source_safely "${SETUP}"
182 # show memory consumption after all docker instances initialized
183 docker_stats | tee "$WORKSPACE/archives/$TESTPLAN/_sysinfo-1-after-setup.txt"
187 echo "Reading the testplan:"
188 cat "${TESTPLANDIR}/testplan.txt" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${WORKSPACE}/tests/|" > testplan.txt
190 SUITES=$( xargs -a testplan.txt )
192 echo ROBOT_VARIABLES="${ROBOT_VARIABLES}"
193 echo "Starting Robot test suites ${SUITES} ..."
195 python -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${TESTOPTIONS} ${SUITES}
198 echo "RESULT: $RESULT"
199 # Note that the final steps are done in on_exit function after this exit!