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-2023 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 # Record list of active docker containers
31 docker ps --format "table {{ .Names }}\t{{ .Status }}"
33 # show memory consumption after all docker instances initialized
36 source_safely ${WORKSPACE}/compose/stop-compose.sh
37 rsync "${WORKSPACE}/compose/docker_compose.log" "${WORKSPACE}/csit/archives/${PROJECT}"
39 if [[ ${WORKDIR} ]]; then
40 rsync -av "${WORKDIR}/" "${WORKSPACE}/csit/archives/${PROJECT}"
42 rm -rf ${WORKSPACE}/models
44 # TODO: do something with the output
48 # ensure that teardown and other finalizing steps are always executed
51 function docker_stats(){
52 # General memory details
53 if [ "$(uname -s)" == "Darwin" ]
55 sh -c "top -l1 | head -10"
58 sh -c "top -bn1 | head -3"
65 # Memory details per Docker
66 docker ps --format "table {{ .Names }}\t{{ .Status }}"
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 WORKSPACE=$(git rev-parse --show-toplevel)
141 # Add csit scripts to PATH
142 export PATH="${PATH}:${WORKSPACE}/csit:${WORKSPACE}/scripts:${ROBOT_VENV}/bin"
143 export SCRIPTS="${WORKSPACE}/csit/resources/scripts"
144 export ROBOT_VARIABLES=
146 export PROJECT="${1}"
150 rm -rf "${WORKSPACE}/csit/archives/${PROJECT}"
151 mkdir -p "${WORKSPACE}/csit/archives/${PROJECT}"
153 # Run installation of pre-required libraries
154 source_safely "${SCRIPTS}/prepare-robot-env.sh"
156 # Activate the virtualenv containing all the required libraries installed by prepare-robot-env.sh
157 source_safely "${ROBOT_VENV}/bin/activate"
159 export TEST_PLAN_DIR="${WORKSPACE}/csit/resources/tests"
160 export TEST_OPTIONS="${2}"
165 # Sign in to nexus3 docker repo
166 docker login -u docker -p docker nexus3.onap.org:10001
168 # Run setup script plan if it exists
169 SETUP="${SCRIPTS}/setup-${PROJECT}.sh"
170 if [ -f "${SETUP}" ]; then
171 echo "Running setup script ${SETUP}"
172 source_safely "${SETUP}"
175 # show memory consumption after all docker instances initialized
176 docker_stats | tee "${WORKSPACE}/csit/archives/${PROJECT}/_sysinfo-1-after-setup.txt"
180 echo "Reading the testplan:"
181 echo "${SUITES}" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${TEST_PLAN_DIR}/|" > testplan.txt
183 SUITES=$( xargs < testplan.txt )
185 echo ROBOT_VARIABLES="${ROBOT_VARIABLES}"
186 echo "Starting Robot test suites ${SUITES} ..."
188 python3 -m robot.run -N "${PROJECT}" -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${SUITES}
191 echo "RESULT: ${RESULT}"
192 # Note that the final steps are done in on_exit function after this exit!