3 # Copyright 2016-2017 Huawei Technologies Co., Ltd.
4 # Modification Copyright 2019 © Samsung Electronics Co., Ltd.
5 # Modification Copyright 2021 © AT&T Intellectual Property.
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.
28 if [[ ${WORKSPACE} ]]; then
29 if [[ ${WORKDIR} ]]; then
30 rsync -av "${WORKDIR}/" "${WORKSPACE}/csit/archives/${PROJECT}"
32 # Record list of active docker containers
33 docker ps --format "{{.Image}}" > "${WORKSPACE}/csit/archives/${PROJECT}/_docker-images.log"
35 # show memory consumption after all docker instances initialized
36 docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-2-after-robot.txt"
38 # Run teardown script plan if it exists
39 cd "${TESTPLANDIR}/plans/"
40 TEARDOWN="${TESTPLANDIR}/plans/teardown.sh"
41 if [ -f "${TEARDOWN}" ]; then
42 echo "Running teardown script ${TEARDOWN}"
43 source_safely "${TEARDOWN}"
45 # 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
122 # set and save options for quick failure
123 harden_set && save_set
128 echo "Usage: $0 <project> [<robot-options>]"
130 echo " <project> <robot-options>: "
135 if [ -z "${WORKSPACE}" ]; then
136 export WORKSPACE=$(git rev-parse --show-toplevel)
139 # Add csit scripts to PATH
140 export PATH="${PATH}:${WORKSPACE}/csit:${WORKSPACE}/scripts:${ROBOT_VENV}/bin"
141 export SCRIPTS="${WORKSPACE}/csit"
142 export ROBOT_VARIABLES=
144 # get the plan from git clone
145 source ${SCRIPTS}/get-branch-mariadb.sh
147 export PROJECT="${1}"
153 export TESTPLANDIR="${WORKSPACE}/csit/${PROJECT}"
156 export TESTPLANDIR="${WORKSPACE}/${PROJECT}/csit"
158 rm -rf ${WORKSPACE}/${PROJECT}
159 mkdir ${WORKSPACE}/${PROJECT}
161 # get the plan from git clone
162 if ! `git clone -b ${GERRIT_BRANCH} --single-branch https://github.com/onap/policy-${PROJECT}.git ${PROJECT}` ; then
163 echo "repo not found: policy/${PROJECT}"
167 if [ ! -f "${TESTPLANDIR}/plans/testplan.txt" ]; then
168 echo "testplan not found: ${TESTPLANDIR}/plans/testplan.txt"
174 export TESTOPTIONS="${2}"
176 rm -rf "${WORKSPACE}/csit/archives/${PROJECT}"
177 mkdir -p "${WORKSPACE}/csit/archives/${PROJECT}"
179 # Run installation of prerequired libraries
180 source_safely "${SCRIPTS}/prepare-csit.sh"
182 # Activate the virtualenv containing all the required libraries installed by prepare-csit.sh
183 source_safely "${ROBOT_VENV}/bin/activate"
185 WORKDIR=$(mktemp -d --suffix=-robot-workdir)
188 # Sign in to nexus3 docker repo
189 docker login -u docker -p docker nexus3.onap.org:10001
191 # Generate keystore to be used by repos
192 ${SCRIPTS}/gen_keystore.sh
193 cp ${SCRIPTS}/config/ks.jks ${SCRIPTS}/config/drools/custom/policy-keystore
194 cp ${SCRIPTS}/config/ks.jks ${SCRIPTS}/config/drools-apps/custom/policy-keystore
196 # Run setup script plan if it exists
197 cd "${TESTPLANDIR}/plans/"
198 SETUP="${TESTPLANDIR}/plans/setup.sh"
199 if [ -f "${SETUP}" ]; then
200 echo "Running setup script ${SETUP}"
201 source_safely "${SETUP}"
204 # show memory consumption after all docker instances initialized
205 docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-1-after-setup.txt"
209 echo "Reading the testplan:"
210 cat "${TESTPLANDIR}/plans/testplan.txt" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${TESTPLANDIR}/tests/|" > testplan.txt
212 SUITES=$( xargs -a testplan.txt )
214 echo ROBOT_VARIABLES="${ROBOT_VARIABLES}"
215 echo "Starting Robot test suites ${SUITES} ..."
217 python -m robot.run -N ${PROJECT} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${SUITES}
220 echo "RESULT: ${RESULT}"
221 # Note that the final steps are done in on_exit function after this exit!