blob: 47ad3b153a83a4a6860a980ac844b34a7233a294 [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.
adheli.tavaresc6eb02a2023-02-02 08:44:51 +00006# Modification Copyright 2021-2023 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
Taka Cho6d188af2021-01-11 16:48:33 -050030 # Record list of active docker containers
adheli.tavares9fc9fa42023-02-09 11:56:27 +000031 docker ps --format "table {{ .Names }}\t{{ .Status }}"
liamfallonc4bd9e42022-09-08 09:56:47 +010032
Taka Cho6d188af2021-01-11 16:48:33 -050033 # show memory consumption after all docker instances initialized
liamfallonc4bd9e42022-09-08 09:56:47 +010034 docker_stats
adheli.tavares9fc9fa42023-02-09 11:56:27 +000035
adheli.tavares1f339f82023-02-17 15:14:07 +000036 source_safely ${WORKSPACE}/compose/stop-compose.sh
37
adheli.tavares9fc9fa42023-02-09 11:56:27 +000038 if [[ ${WORKDIR} ]]; then
39 rsync -av "${WORKDIR}/" "${WORKSPACE}/csit/archives/${PROJECT}"
40 fi
adheli.tavares1f339f82023-02-17 15:14:07 +000041 rm -rf ${WORKSPACE}/models
Taka Cho6d188af2021-01-11 16:48:33 -050042 fi
43 # TODO: do something with the output
44 exit $rc
45}
46
47# ensure that teardown and other finalizing steps are always executed
48trap on_exit EXIT
49
50function docker_stats(){
liamfallonfaac45b2022-09-01 12:05:47 +010051 # General memory details
52 if [ "$(uname -s)" == "Darwin" ]
53 then
liamfallonfaac45b2022-09-01 12:05:47 +010054 sh -c "top -l1 | head -10"
55 echo
56 else
liamfallonfaac45b2022-09-01 12:05:47 +010057 sh -c "top -bn1 | head -3"
58 echo
Taka Cho6d188af2021-01-11 16:48:33 -050059
liamfallonfaac45b2022-09-01 12:05:47 +010060 sh -c "free -h"
61 echo
62 fi
Taka Cho6d188af2021-01-11 16:48:33 -050063
liamfallonfaac45b2022-09-01 12:05:47 +010064 # Memory details per Docker
adheli.tavares9fc9fa42023-02-09 11:56:27 +000065 docker ps --format "table {{ .Names }}\t{{ .Status }}"
Taka Cho6d188af2021-01-11 16:48:33 -050066 echo
67
Taka Cho6d188af2021-01-11 16:48:33 -050068 docker stats --no-stream
69 echo
70}
71
72# save current set options
73function save_set() {
74 RUN_CSIT_SAVE_SET="$-"
Jim Hahn3486a922021-05-10 15:36:30 -040075 RUN_CSIT_SHELLOPTS="${SHELLOPTS}"
Taka Cho6d188af2021-01-11 16:48:33 -050076}
77
78# load the saved set options
79function load_set() {
80 _setopts="$-"
81
82 # bash shellopts
Jim Hahn3486a922021-05-10 15:36:30 -040083 for i in $(echo "${SHELLOPTS}" | tr ':' ' ') ; do
Taka Cho6d188af2021-01-11 16:48:33 -050084 set +o ${i}
85 done
Jim Hahn3486a922021-05-10 15:36:30 -040086 for i in $(echo "${RUN_CSIT_SHELLOPTS}" | tr ':' ' ') ; do
Taka Cho6d188af2021-01-11 16:48:33 -050087 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
Jim Hahn3486a922021-05-10 15:36:30 -0400135if [ -z "${WORKSPACE}" ]; then
adheli.tavares1f339f82023-02-17 15:14:07 +0000136 WORKSPACE=$(git rev-parse --show-toplevel)
137 export WORKSPACE
Taka Cho6d188af2021-01-11 16:48:33 -0500138fi
139
140# Add csit scripts to PATH
Taka Cho78bbba72021-01-15 11:20:06 -0500141export PATH="${PATH}:${WORKSPACE}/csit:${WORKSPACE}/scripts:${ROBOT_VENV}/bin"
adheli.tavares1f339f82023-02-17 15:14:07 +0000142export SCRIPTS="${WORKSPACE}/csit/resources/scripts"
Taka Cho6d188af2021-01-11 16:48:33 -0500143export ROBOT_VARIABLES=
144
Taka Cho6d188af2021-01-11 16:48:33 -0500145export PROJECT="${1}"
Jim Hahn3486a922021-05-10 15:36:30 -0400146
adheli.tavares1f339f82023-02-17 15:14:07 +0000147cd "${WORKSPACE}"
Taka Cho6d188af2021-01-11 16:48:33 -0500148
Jim Hahn3486a922021-05-10 15:36:30 -0400149rm -rf "${WORKSPACE}/csit/archives/${PROJECT}"
150mkdir -p "${WORKSPACE}/csit/archives/${PROJECT}"
Taka Cho6d188af2021-01-11 16:48:33 -0500151
adheli.tavares1f339f82023-02-17 15:14:07 +0000152# Run installation of pre-required libraries
adheli.tavaresc6eb02a2023-02-02 08:44:51 +0000153source_safely "${SCRIPTS}/prepare-robot-env.sh"
Taka Cho6d188af2021-01-11 16:48:33 -0500154
adheli.tavaresc6eb02a2023-02-02 08:44:51 +0000155# Activate the virtualenv containing all the required libraries installed by prepare-robot-env.sh
Taka Cho6d188af2021-01-11 16:48:33 -0500156source_safely "${ROBOT_VENV}/bin/activate"
157
adheli.tavares1f339f82023-02-17 15:14:07 +0000158export TEST_PLAN_DIR="${WORKSPACE}/csit/resources/tests"
159export TEST_OPTIONS="${2}"
160
liamfallonfaac45b2022-09-01 12:05:47 +0100161WORKDIR=$(mktemp -d)
Taka Cho6d188af2021-01-11 16:48:33 -0500162cd "${WORKDIR}"
163
164# Sign in to nexus3 docker repo
165docker login -u docker -p docker nexus3.onap.org:10001
166
167# Run setup script plan if it exists
adheli.tavares1f339f82023-02-17 15:14:07 +0000168SETUP="${SCRIPTS}/setup-${PROJECT}.sh"
Taka Cho6d188af2021-01-11 16:48:33 -0500169if [ -f "${SETUP}" ]; then
170 echo "Running setup script ${SETUP}"
171 source_safely "${SETUP}"
172fi
173
174# show memory consumption after all docker instances initialized
Jim Hahn3486a922021-05-10 15:36:30 -0400175docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-1-after-setup.txt"
Taka Cho6d188af2021-01-11 16:48:33 -0500176
177# Run test plan
Jim Hahn3486a922021-05-10 15:36:30 -0400178cd "${WORKDIR}"
Taka Cho6d188af2021-01-11 16:48:33 -0500179echo "Reading the testplan:"
adheli.tavares1f339f82023-02-17 15:14:07 +0000180echo "${SUITES}" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${TEST_PLAN_DIR}/|" > testplan.txt
Taka Cho6d188af2021-01-11 16:48:33 -0500181cat testplan.txt
liamfallonfaac45b2022-09-01 12:05:47 +0100182SUITES=$( xargs < testplan.txt )
Taka Cho6d188af2021-01-11 16:48:33 -0500183
184echo ROBOT_VARIABLES="${ROBOT_VARIABLES}"
185echo "Starting Robot test suites ${SUITES} ..."
186relax_set
adheli.tavares1f339f82023-02-17 15:14:07 +0000187python3 -m robot.run -N "${PROJECT}" -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${SUITES}
Taka Cho6d188af2021-01-11 16:48:33 -0500188RESULT=$?
189load_set
Jim Hahn3486a922021-05-10 15:36:30 -0400190echo "RESULT: ${RESULT}"
Taka Cho6d188af2021-01-11 16:48:33 -0500191# Note that the final steps are done in on_exit function after this exit!
Jim Hahn3486a922021-05-10 15:36:30 -0400192exit ${RESULT}