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
25 function docker_stats(){
26 #General memory details
27 echo "> top -bn1 | head -3"
35 #Memory details per Docker
40 echo "> docker stats --no-stream"
41 docker stats --no-stream
45 # save current set options
47 RUN_CSIT_SAVE_SET="$-"
48 RUN_CSIT_SHELLOPTS="$SHELLOPTS"
51 # load the saved set options
56 for i in $(echo "$SHELLOPTS" | tr ':' ' ') ; do
59 for i in $(echo "$RUN_CSIT_SHELLOPTS" | tr ':' ' ') ; do
64 for i in $(echo "$_setopts" | sed 's/./& /g') ; do
67 set -${RUN_CSIT_SAVE_SET}
70 # set options for quick bailout when error
71 function harden_set() {
73 set +u # enabled it would probably fail too many often
76 # relax set options so the sourced file will not fail
77 # the responsibility is shifted to the sourced file...
78 function relax_set() {
83 # wrapper for sourcing a file
84 function source_safely() {
85 [ -z "$1" ] && return 1
95 # set and save options for quick failure
96 harden_set && save_set
101 echo "Usage: $0 plans/<project>/<functionality> [<robot-options>]"
103 echo " <project>, <functionality>, <robot-options>: "
104 echo " The same values as for the '{project}-csit-{functionality}' JJB job template."
109 if [ -z "$WORKSPACE" ]; then
110 export WORKSPACE=$(git rev-parse --show-toplevel)
113 rm -rf "$WORKSPACE/archives"
114 mkdir -p "$WORKSPACE/archives"
116 if [ -f "${WORKSPACE}/${1}/testplan.txt" ]; then
117 export TESTPLAN="${1}"
119 echo "testplan not found: ${WORKSPACE}/${TESTPLAN}/testplan.txt"
123 export TESTOPTIONS="${2}"
125 TESTPLANDIR="${WORKSPACE}/${TESTPLAN}"
127 # Run installation of prerequired libraries
128 source_safely "${WORKSPACE}/prepare-csit.sh"
130 # Activate the virtualenv containing all the required libraries installed by prepare-csit.sh
131 source_safely "${ROBOT_VENV}/bin/activate"
133 WORKDIR=$(mktemp -d --suffix=-robot-workdir)
136 # Add csit scripts to PATH
137 export PATH="${PATH}:${WORKSPACE}/docker/scripts:${WORKSPACE}/scripts:${ROBOT_VENV}/bin"
138 export SCRIPTS="${WORKSPACE}/scripts"
139 export ROBOT_VARIABLES=
141 # Sign in to nexus3 docker repo
142 docker login -u anonymous -p anonymous nexus3.onap.org:10001
144 # Run setup script plan if it exists
146 SETUP="${TESTPLANDIR}/setup.sh"
147 if [ -f "${SETUP}" ]; then
148 echo "Running setup script ${SETUP}"
149 source_safely "${SETUP}"
152 # show memory consumption after all docker instances initialized
153 docker_stats | tee "$WORKSPACE/archives/_sysinfo-1-after-setup.txt"
157 echo "Reading the testplan:"
158 cat "${TESTPLANDIR}/testplan.txt" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${WORKSPACE}/tests/|" > testplan.txt
160 SUITES=$( xargs -a testplan.txt )
162 echo ROBOT_VARIABLES="${ROBOT_VARIABLES}"
163 echo "Starting Robot test suites ${SUITES} ..."
165 python -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${TESTOPTIONS} ${SUITES}
168 echo "RESULT: $RESULT"
169 rsync -av "$WORKDIR/" "$WORKSPACE/archives"
171 # Record list of active docker containers
172 docker ps --format "{{.Image}}" > "$WORKSPACE/archives/_docker-images.log"
174 # show memory consumption after all docker instances initialized
175 docker_stats | tee "$WORKSPACE/archives/_sysinfo-2-after-robot.txt"
177 # Run teardown script plan if it exists
179 TEARDOWN="${TESTPLANDIR}/teardown.sh"
180 if [ -f "${TEARDOWN}" ]; then
181 echo "Running teardown script ${TEARDOWN}"
182 source_safely "${TEARDOWN}"
185 # TODO: do something with the output