blob: d77b06fa26ae82c9db0aef8214d38798fb6218f0 [file] [log] [blame]
Taka Cho6d188af2021-01-11 16:48:33 -05001#!/bin/bash -x
2#
3# Copyright 2016-2017 Huawei Technologies Co., Ltd.
4# Modification Copyright 2019 © Samsung Electronics Co., Ltd.
5# Modification Copyright 2021 © AT&T Intellectual Property.
arkadiusz.adamski2b1e8d02021-05-24 12:50:40 +01006# Modification Copyright 2021. Nordix Foundation.
Taka Cho6d188af2021-01-11 16:48:33 -05007#
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
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
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.
19#
20# $1 functionality
21# $2 robot options
22
23#
24# functions
25#
26
27function on_exit(){
28 rc=$?
29 if [[ ${WORKSPACE} ]]; then
30 if [[ ${WORKDIR} ]]; then
Jim Hahn3486a922021-05-10 15:36:30 -040031 rsync -av "${WORKDIR}/" "${WORKSPACE}/csit/archives/${PROJECT}"
Taka Cho6d188af2021-01-11 16:48:33 -050032 fi
33 # Record list of active docker containers
Jim Hahn3486a922021-05-10 15:36:30 -040034 docker ps --format "{{.Image}}" > "${WORKSPACE}/csit/archives/${PROJECT}/_docker-images.log"
Taka Cho6d188af2021-01-11 16:48:33 -050035
36 # show memory consumption after all docker instances initialized
Jim Hahn3486a922021-05-10 15:36:30 -040037 docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-2-after-robot.txt"
Taka Cho6d188af2021-01-11 16:48:33 -050038 fi
39 # Run teardown script plan if it exists
Jim Hahn3486a922021-05-10 15:36:30 -040040 cd "${TESTPLANDIR}/plans/"
41 TEARDOWN="${TESTPLANDIR}/plans/teardown.sh"
Taka Cho6d188af2021-01-11 16:48:33 -050042 if [ -f "${TEARDOWN}" ]; then
43 echo "Running teardown script ${TEARDOWN}"
44 source_safely "${TEARDOWN}"
45 fi
46 # TODO: do something with the output
47 exit $rc
48}
49
50# ensure that teardown and other finalizing steps are always executed
51trap on_exit EXIT
52
53function docker_stats(){
54 #General memory details
55 echo "> top -bn1 | head -3"
56 top -bn1 | head -3
57 echo
58
59 echo "> free -h"
60 free -h
61 echo
62
63 #Memory details per Docker
64 echo "> docker ps"
65 docker ps
66 echo
67
68 echo "> docker stats --no-stream"
69 docker stats --no-stream
70 echo
71}
72
73# save current set options
74function save_set() {
75 RUN_CSIT_SAVE_SET="$-"
Jim Hahn3486a922021-05-10 15:36:30 -040076 RUN_CSIT_SHELLOPTS="${SHELLOPTS}"
Taka Cho6d188af2021-01-11 16:48:33 -050077}
78
79# load the saved set options
80function load_set() {
81 _setopts="$-"
82
83 # bash shellopts
Jim Hahn3486a922021-05-10 15:36:30 -040084 for i in $(echo "${SHELLOPTS}" | tr ':' ' ') ; do
Taka Cho6d188af2021-01-11 16:48:33 -050085 set +o ${i}
86 done
Jim Hahn3486a922021-05-10 15:36:30 -040087 for i in $(echo "${RUN_CSIT_SHELLOPTS}" | tr ':' ' ') ; do
Taka Cho6d188af2021-01-11 16:48:33 -050088 set -o ${i}
89 done
90
91 # other options
92 for i in $(echo "$_setopts" | sed 's/./& /g') ; do
93 set +${i}
94 done
95 set -${RUN_CSIT_SAVE_SET}
96}
97
98# set options for quick bailout when error
99function harden_set() {
100 set -xeo pipefail
101 set +u # enabled it would probably fail too many often
102}
103
104# relax set options so the sourced file will not fail
105# the responsibility is shifted to the sourced file...
106function relax_set() {
107 set +e
108 set +o pipefail
109}
110
111# wrapper for sourcing a file
112function source_safely() {
113 [ -z "$1" ] && return 1
114 relax_set
115 . "$1"
116 load_set
117}
118
119#
120# main
121#
122
123# set and save options for quick failure
124harden_set && save_set
125
126if [ $# -eq 0 ]
127then
128 echo
129 echo "Usage: $0 <project> [<robot-options>]"
130 echo
131 echo " <project> <robot-options>: "
132 echo
133 exit 1
134fi
135
Jim Hahn3486a922021-05-10 15:36:30 -0400136if [ -z "${WORKSPACE}" ]; then
Taka Cho6d188af2021-01-11 16:48:33 -0500137 export WORKSPACE=$(git rev-parse --show-toplevel)
138fi
139
140# Add csit scripts to PATH
Taka Cho78bbba72021-01-15 11:20:06 -0500141export PATH="${PATH}:${WORKSPACE}/csit:${WORKSPACE}/scripts:${ROBOT_VENV}/bin"
142export SCRIPTS="${WORKSPACE}/csit"
Taka Cho6d188af2021-01-11 16:48:33 -0500143export ROBOT_VARIABLES=
144
145# get the plan from git clone
146source ${SCRIPTS}/get-branch-mariadb.sh
147
148export PROJECT="${1}"
Jim Hahn3486a922021-05-10 15:36:30 -0400149
Taka Cho6d188af2021-01-11 16:48:33 -0500150cd ${WORKSPACE}
151
Jim Hahnb3a962f2021-05-12 11:33:43 -0400152export TESTPLANDIR="${WORKSPACE}/csit/${PROJECT}"
Taka Cho6d188af2021-01-11 16:48:33 -0500153export TESTOPTIONS="${2}"
154
Jim Hahn3486a922021-05-10 15:36:30 -0400155rm -rf "${WORKSPACE}/csit/archives/${PROJECT}"
156mkdir -p "${WORKSPACE}/csit/archives/${PROJECT}"
Taka Cho6d188af2021-01-11 16:48:33 -0500157
158# Run installation of prerequired libraries
159source_safely "${SCRIPTS}/prepare-csit.sh"
160
161# Activate the virtualenv containing all the required libraries installed by prepare-csit.sh
162source_safely "${ROBOT_VENV}/bin/activate"
163
164WORKDIR=$(mktemp -d --suffix=-robot-workdir)
165cd "${WORKDIR}"
166
167# Sign in to nexus3 docker repo
168docker login -u docker -p docker nexus3.onap.org:10001
169
Jim Hahn548aa5a2021-06-14 12:00:48 -0400170# Generate truststore and keystore to be used by repos
171${SCRIPTS}/gen_truststore.sh
Jim Hahn39b7b982021-03-16 14:52:34 -0400172${SCRIPTS}/gen_keystore.sh
173cp ${SCRIPTS}/config/ks.jks ${SCRIPTS}/config/drools/custom/policy-keystore
174cp ${SCRIPTS}/config/ks.jks ${SCRIPTS}/config/drools-apps/custom/policy-keystore
Jim Hahnd6cc02e2021-06-11 13:23:20 -0400175cp ${SCRIPTS}/config/policy-truststore \
176 ${SCRIPTS}/config/drools/custom/policy-truststore
177cp ${SCRIPTS}/config/policy-truststore \
178 ${SCRIPTS}/config/drools-apps/custom/policy-truststore
179chmod 644 \
180 ${SCRIPTS}/config/drools/custom/policy-* \
181 ${SCRIPTS}/config/drools-apps/custom/policy-*
Jim Hahn39b7b982021-03-16 14:52:34 -0400182
Taka Cho6d188af2021-01-11 16:48:33 -0500183# Run setup script plan if it exists
Jim Hahn3486a922021-05-10 15:36:30 -0400184cd "${TESTPLANDIR}/plans/"
185SETUP="${TESTPLANDIR}/plans/setup.sh"
Taka Cho6d188af2021-01-11 16:48:33 -0500186if [ -f "${SETUP}" ]; then
187 echo "Running setup script ${SETUP}"
188 source_safely "${SETUP}"
189fi
190
191# show memory consumption after all docker instances initialized
Jim Hahn3486a922021-05-10 15:36:30 -0400192docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-1-after-setup.txt"
Taka Cho6d188af2021-01-11 16:48:33 -0500193
194# Run test plan
Jim Hahn3486a922021-05-10 15:36:30 -0400195cd "${WORKDIR}"
Taka Cho6d188af2021-01-11 16:48:33 -0500196echo "Reading the testplan:"
Jim Hahn3486a922021-05-10 15:36:30 -0400197cat "${TESTPLANDIR}/plans/testplan.txt" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${TESTPLANDIR}/tests/|" > testplan.txt
Taka Cho6d188af2021-01-11 16:48:33 -0500198cat testplan.txt
199SUITES=$( xargs -a testplan.txt )
200
201echo ROBOT_VARIABLES="${ROBOT_VARIABLES}"
202echo "Starting Robot test suites ${SUITES} ..."
203relax_set
arkadiusz.adamski2b1e8d02021-05-24 12:50:40 +0100204python3 -m robot.run -N ${PROJECT} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${SUITES}
Taka Cho6d188af2021-01-11 16:48:33 -0500205RESULT=$?
206load_set
Jim Hahn3486a922021-05-10 15:36:30 -0400207echo "RESULT: ${RESULT}"
Taka Cho6d188af2021-01-11 16:48:33 -0500208# Note that the final steps are done in on_exit function after this exit!
Jim Hahn3486a922021-05-10 15:36:30 -0400209exit ${RESULT}