blob: c3d67d9e5b74b7ce71b0814e73afb52b8e17c126 [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.
6#
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
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
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.
18#
19# $1 functionality
20# $2 robot options
21
22#
23# functions
24#
25
26function on_exit(){
27 rc=$?
28 if [[ ${WORKSPACE} ]]; then
29 if [[ ${WORKDIR} ]]; then
Taka Cho63d65922021-01-19 13:56:54 -050030 rsync -av "$WORKDIR/" "$WORKSPACE/csit/archives/$TESTPLAN"
Taka Cho6d188af2021-01-11 16:48:33 -050031 fi
32 # Record list of active docker containers
Taka Cho63d65922021-01-19 13:56:54 -050033 docker ps --format "{{.Image}}" > "$WORKSPACE/csit/archives/$TESTPLAN/_docker-images.log"
Taka Cho6d188af2021-01-11 16:48:33 -050034
35 # show memory consumption after all docker instances initialized
Taka Cho63d65922021-01-19 13:56:54 -050036 docker_stats | tee "$WORKSPACE/csit/archives/$TESTPLAN/_sysinfo-2-after-robot.txt"
Taka Cho6d188af2021-01-11 16:48:33 -050037 fi
38 # Run teardown script plan if it exists
39 cd "${TESTPLANDIR}/csit/plans/"
40 TEARDOWN="${TESTPLANDIR}/csit/plans/teardown.sh"
41 if [ -f "${TEARDOWN}" ]; then
42 echo "Running teardown script ${TEARDOWN}"
43 source_safely "${TEARDOWN}"
44 fi
45 # TODO: do something with the output
46 exit $rc
47}
48
49# ensure that teardown and other finalizing steps are always executed
50trap on_exit EXIT
51
52function docker_stats(){
53 #General memory details
54 echo "> top -bn1 | head -3"
55 top -bn1 | head -3
56 echo
57
58 echo "> free -h"
59 free -h
60 echo
61
62 #Memory details per Docker
63 echo "> docker ps"
64 docker ps
65 echo
66
67 echo "> docker stats --no-stream"
68 docker stats --no-stream
69 echo
70}
71
72# save current set options
73function save_set() {
74 RUN_CSIT_SAVE_SET="$-"
75 RUN_CSIT_SHELLOPTS="$SHELLOPTS"
76}
77
78# load the saved set options
79function load_set() {
80 _setopts="$-"
81
82 # bash shellopts
83 for i in $(echo "$SHELLOPTS" | tr ':' ' ') ; do
84 set +o ${i}
85 done
86 for i in $(echo "$RUN_CSIT_SHELLOPTS" | tr ':' ' ') ; do
87 set -o ${i}
88 done
89
90 # other options
91 for i in $(echo "$_setopts" | sed 's/./& /g') ; do
92 set +${i}
93 done
94 set -${RUN_CSIT_SAVE_SET}
95}
96
97# set options for quick bailout when error
98function harden_set() {
99 set -xeo pipefail
100 set +u # enabled it would probably fail too many often
101}
102
103# relax set options so the sourced file will not fail
104# the responsibility is shifted to the sourced file...
105function relax_set() {
106 set +e
107 set +o pipefail
108}
109
110# wrapper for sourcing a file
111function source_safely() {
112 [ -z "$1" ] && return 1
113 relax_set
114 . "$1"
115 load_set
116}
117
118#
119# main
120#
121
122# set and save options for quick failure
123harden_set && save_set
124
125if [ $# -eq 0 ]
126then
127 echo
128 echo "Usage: $0 <project> [<robot-options>]"
129 echo
130 echo " <project> <robot-options>: "
131 echo
132 exit 1
133fi
134
135if [ -z "$WORKSPACE" ]; then
136 export WORKSPACE=$(git rev-parse --show-toplevel)
137fi
138
139# Add csit scripts to PATH
Taka Cho78bbba72021-01-15 11:20:06 -0500140export PATH="${PATH}:${WORKSPACE}/csit:${WORKSPACE}/scripts:${ROBOT_VENV}/bin"
141export SCRIPTS="${WORKSPACE}/csit"
Taka Cho6d188af2021-01-11 16:48:33 -0500142export ROBOT_VARIABLES=
143
144# get the plan from git clone
145source ${SCRIPTS}/get-branch-mariadb.sh
146
147export PROJECT="${1}"
148rm -rf ${WORKSPACE}/${PROJECT}
149mkdir ${WORKSPACE}/${PROJECT}
150cd ${WORKSPACE}
151
152# get the plan from git clone
153if ! `git clone -b ${GERRIT_BRANCH} --single-branch git://gerrit-mirror-ap.onap.org/mirror/policy/${PROJECT}.git` ; then
154 echo "repo not found: policy/${PROJECT}"
155 exit 1
156fi
157
Taka Cho6d188af2021-01-11 16:48:33 -0500158if [ -f "${WORKSPACE}/${1}/csit/plans/testplan.txt" ]; then
159 export TESTPLAN="${1}"
160else
161 echo "testplan not found: ${WORKSPACE}/${1}/csit/plans/testplan.txt"
162 exit 2
163fi
164
165export TESTOPTIONS="${2}"
166
Taka Cho63d65922021-01-19 13:56:54 -0500167rm -rf "$WORKSPACE/csit/archives/$TESTPLAN"
168mkdir -p "$WORKSPACE/csit/archives/$TESTPLAN"
Taka Cho6d188af2021-01-11 16:48:33 -0500169
170TESTPLANDIR="${WORKSPACE}/${TESTPLAN}"
171
172# Run installation of prerequired libraries
173source_safely "${SCRIPTS}/prepare-csit.sh"
174
175# Activate the virtualenv containing all the required libraries installed by prepare-csit.sh
176source_safely "${ROBOT_VENV}/bin/activate"
177
178WORKDIR=$(mktemp -d --suffix=-robot-workdir)
179cd "${WORKDIR}"
180
181# Sign in to nexus3 docker repo
182docker login -u docker -p docker nexus3.onap.org:10001
183
Jim Hahn39b7b982021-03-16 14:52:34 -0400184# Generate keystore to be used by repos
185${SCRIPTS}/gen_keystore.sh
186cp ${SCRIPTS}/config/ks.jks ${SCRIPTS}/config/drools/custom/policy-keystore
187cp ${SCRIPTS}/config/ks.jks ${SCRIPTS}/config/drools-apps/custom/policy-keystore
188
Taka Cho6d188af2021-01-11 16:48:33 -0500189# Run setup script plan if it exists
190cd "${TESTPLANDIR}/csit/plans/"
191SETUP="${TESTPLANDIR}/csit/plans/setup.sh"
192if [ -f "${SETUP}" ]; then
193 echo "Running setup script ${SETUP}"
194 source_safely "${SETUP}"
195fi
196
197# show memory consumption after all docker instances initialized
Taka Cho63d65922021-01-19 13:56:54 -0500198docker_stats | tee "$WORKSPACE/csit/archives/$TESTPLAN/_sysinfo-1-after-setup.txt"
Taka Cho6d188af2021-01-11 16:48:33 -0500199
200# Run test plan
201cd "$WORKDIR"
202echo "Reading the testplan:"
203cat "${TESTPLANDIR}/csit/plans/testplan.txt" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${TESTPLANDIR}/csit/tests/|" > testplan.txt
204cat testplan.txt
205SUITES=$( xargs -a testplan.txt )
206
207echo ROBOT_VARIABLES="${ROBOT_VARIABLES}"
208echo "Starting Robot test suites ${SUITES} ..."
209relax_set
Taka Cho78bbba72021-01-15 11:20:06 -0500210python -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${SUITES}
Taka Cho6d188af2021-01-11 16:48:33 -0500211RESULT=$?
212load_set
213echo "RESULT: $RESULT"
214# Note that the final steps are done in on_exit function after this exit!
215exit $RESULT