3 # Copyright 2016-2017 Huawei Technologies Co., Ltd.
4 # Modification Copyright 2019 © Samsung Electronics Co., Ltd.
5 # Modification Copyright 2021 © AT&T Intellectual Property.
6 # Modification Copyright 2021. Nordix Foundation.
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
29 if [[ ${WORKSPACE} ]]; then
30 if [[ ${WORKDIR} ]]; then
31 rsync -av "${WORKDIR}/" "${WORKSPACE}/csit/archives/${PROJECT}"
33 # Record list of active docker containers
34 docker ps --format "{{.Image}}" > "${WORKSPACE}/csit/archives/${PROJECT}/_docker-images.log"
36 # show memory consumption after all docker instances initialized
37 docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-2-after-robot.txt"
39 # Run teardown script plan if it exists
40 cd "${TESTPLANDIR}/plans/"
41 TEARDOWN="${TESTPLANDIR}/plans/teardown.sh"
42 if [ -f "${TEARDOWN}" ]; then
43 echo "Running teardown script ${TEARDOWN}"
44 source_safely "${TEARDOWN}"
46 # TODO: do something with the output
50 # ensure that teardown and other finalizing steps are always executed
53 function docker_stats(){
54 #General memory details
55 echo "> top -bn1 | head -3"
63 #Memory details per Docker
68 echo "> docker stats --no-stream"
69 docker stats --no-stream
73 # save current set options
75 RUN_CSIT_SAVE_SET="$-"
76 RUN_CSIT_SHELLOPTS="${SHELLOPTS}"
79 # load the saved set options
84 for i in $(echo "${SHELLOPTS}" | tr ':' ' ') ; do
87 for i in $(echo "${RUN_CSIT_SHELLOPTS}" | tr ':' ' ') ; do
92 for i in $(echo "$_setopts" | sed 's/./& /g') ; do
95 set -${RUN_CSIT_SAVE_SET}
98 # set options for quick bailout when error
99 function harden_set() {
101 set +u # enabled it would probably fail too many often
104 # relax set options so the sourced file will not fail
105 # the responsibility is shifted to the sourced file...
106 function relax_set() {
111 # wrapper for sourcing a file
112 function source_safely() {
113 [ -z "$1" ] && return 1
123 # set and save options for quick failure
124 harden_set && save_set
129 echo "Usage: $0 <project> [<robot-options>]"
131 echo " <project> <robot-options>: "
136 if [ -z "${WORKSPACE}" ]; then
137 export WORKSPACE=$(git rev-parse --show-toplevel)
140 # Add csit scripts to PATH
141 export PATH="${PATH}:${WORKSPACE}/csit:${WORKSPACE}/scripts:${ROBOT_VENV}/bin"
142 export SCRIPTS="${WORKSPACE}/csit"
143 export ROBOT_VARIABLES=
145 # get the plan from git clone
146 source ${SCRIPTS}/get-branch-mariadb.sh
148 export PROJECT="${1}"
152 export TESTPLANDIR="${WORKSPACE}/csit/${PROJECT}"
153 export TESTOPTIONS="${2}"
155 rm -rf "${WORKSPACE}/csit/archives/${PROJECT}"
156 mkdir -p "${WORKSPACE}/csit/archives/${PROJECT}"
158 # Run installation of prerequired libraries
159 source_safely "${SCRIPTS}/prepare-csit.sh"
161 # Activate the virtualenv containing all the required libraries installed by prepare-csit.sh
162 source_safely "${ROBOT_VENV}/bin/activate"
164 WORKDIR=$(mktemp -d --suffix=-robot-workdir)
167 # Sign in to nexus3 docker repo
168 docker login -u docker -p docker nexus3.onap.org:10001
170 # Generate truststore and keystore to be used by repos
171 ${SCRIPTS}/gen_truststore.sh
172 ${SCRIPTS}/gen_keystore.sh
173 cp ${SCRIPTS}/config/ks.jks ${SCRIPTS}/config/drools/custom/policy-keystore
174 cp ${SCRIPTS}/config/ks.jks ${SCRIPTS}/config/drools-apps/custom/policy-keystore
175 cp ${SCRIPTS}/config/policy-truststore \
176 ${SCRIPTS}/config/drools/custom/policy-truststore
177 cp ${SCRIPTS}/config/policy-truststore \
178 ${SCRIPTS}/config/drools-apps/custom/policy-truststore
180 ${SCRIPTS}/config/drools/custom/policy-* \
181 ${SCRIPTS}/config/drools-apps/custom/policy-*
183 # Run setup script plan if it exists
184 cd "${TESTPLANDIR}/plans/"
185 SETUP="${TESTPLANDIR}/plans/setup.sh"
186 if [ -f "${SETUP}" ]; then
187 echo "Running setup script ${SETUP}"
188 source_safely "${SETUP}"
191 # show memory consumption after all docker instances initialized
192 docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-1-after-setup.txt"
196 echo "Reading the testplan:"
197 cat "${TESTPLANDIR}/plans/testplan.txt" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${TESTPLANDIR}/tests/|" > testplan.txt
199 SUITES=$( xargs -a testplan.txt )
201 echo ROBOT_VARIABLES="${ROBOT_VARIABLES}"
202 echo "Starting Robot test suites ${SUITES} ..."
204 python3 -m robot.run -N ${PROJECT} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${SUITES}
207 echo "RESULT: ${RESULT}"
208 # Note that the final steps are done in on_exit function after this exit!