3 # Copyright 2016-2017 Huawei Technologies Co., Ltd.
4 # Modification Copyright 2019-2021 © Samsung Electronics Co., Ltd.
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # $1 project/functionality
21 # Branched from ccsdk/distribution to this repository Feb 23, 2021
23 echo "---> run-csit.sh"
25 WORKDIR=$(mktemp -d --suffix=-robot-workdir)
27 # Version should match those used to setup robot-framework in other jobs/stages
28 # Use pyenv for selecting the python version
29 if [[ -d "/opt/pyenv" ]]; then
31 export PYENV_ROOT="/opt/pyenv"
32 export PATH="$PYENV_ROOT/bin:$PATH"
34 if command -v pyenv 1>/dev/null 2>&1; then
35 eval "$(pyenv init - --no-rehash)"
36 # Choose the latest numeric Python version from installed list
37 version=$(pyenv versions --bare | sed '/^[^0-9]/d' | sort -V | tail -n 1)
38 pyenv local "${version}"
46 # relax set options so the sourced file will not fail
47 # the responsibility is shifted to the sourced file...
48 function relax_set() {
53 # load the saved set options
58 for i in $(echo "$SHELLOPTS" | tr ':' ' ') ; do
61 for i in $(echo "$RUN_CSIT_SHELLOPTS" | tr ':' ' ') ; do
66 for i in $(echo "$_setopts" | sed 's/./& /g') ; do
69 set -${RUN_CSIT_SAVE_SET}
72 # wrapper for sourcing a file
73 function source_safely() {
74 [ -z "$1" ] && return 1
79 # Activate the virtualenv containing all the required libraries installed by prepare-csit.sh
80 source_safely "${ROBOT3_VENV}/bin/activate"
84 if [[ ${WORKSPACE} ]]; then
85 if [[ ${WORKDIR} ]]; then
86 rsync -av "$WORKDIR/" "$WORKSPACE/archives/$TESTPLAN"
88 # Record list of active docker containers
89 docker ps --format "{{.Image}}" > "$WORKSPACE/archives/$TESTPLAN/_docker-images.log"
91 # show memory consumption after all docker instances initialized
92 docker_stats | tee "$WORKSPACE/archives/$TESTPLAN/_sysinfo-2-after-robot.txt"
94 # Run teardown script plan if it exists
96 TEARDOWN="${TESTPLANDIR}/teardown.sh"
97 if [ -f "${TEARDOWN}" ]; then
98 echo "Running teardown script ${TEARDOWN}"
99 source_safely "${TEARDOWN}"
101 # TODO: do something with the output
104 # ensure that teardown and other finalizing steps are always executed
107 function docker_stats(){
108 #General memory details
109 echo "> top -bn1 | head -3"
117 #Memory details per Docker
122 echo "> docker stats --no-stream"
123 docker stats --no-stream
127 # save current set options
128 function save_set() {
129 RUN_CSIT_SAVE_SET="$-"
130 RUN_CSIT_SHELLOPTS="$SHELLOPTS"
133 # set options for quick bailout when error
134 function harden_set() {
136 set +u # enabled it would probably fail too many often
139 function run_test_plan() {
143 echo "Reading the testplan:"
144 cat "${TESTPLANDIR}/${testplan}.txt" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${WORKSPACE}/tests/|" > ${testplan}.txt
146 SUITES=$( xargs -a ${testplan}.txt )
148 python3 -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp --legacy-output ${ROBOT_VARIABLES} ${TESTOPTIONS} ${SUITES}
151 echo "RESULT: $RESULT"
159 # set and save options for quick failure
160 harden_set && save_set
165 echo "Usage: $0 plans/<project>/<functionality> [<robot-options>]"
167 echo " <project>, <functionality>, <robot-options>: "
168 echo " The same values as for the '{project}-csit-{functionality}' JJB job template."
173 if [ -z "$WORKSPACE" ]; then
174 export WORKSPACE=$(git rev-parse --show-toplevel)
177 if [ -f "${WORKSPACE}/${1}/testplanCps.txt" ]; then
178 export TESTPLAN="${1}"
180 echo "testplan not found: ${WORKSPACE}/${TESTPLAN}/testplanCps.txt or testplanNcmp.txt"
184 export TESTOPTIONS="${2}"
186 rm -rf "$WORKSPACE/archives/$TESTPLAN"
187 mkdir -p "$WORKSPACE/archives/$TESTPLAN"
189 TESTPLANDIR="${WORKSPACE}/${TESTPLAN}"
191 # Run installation of prerequired libraries
192 source_safely "${WORKSPACE}/prepare-csit.sh"
194 # Use robot framework working directory
197 # Add csit scripts to PATH
198 export PATH="${PATH}:${WORKSPACE}/docker/scripts:${WORKSPACE}/scripts:${ROBOT3_VENV}/bin"
199 export SCRIPTS="${WORKSPACE}/scripts"
200 export ROBOT_VARIABLES=
202 # Sign in to nexus3 docker repo
203 docker login -u docker -p docker nexus3.onap.org:10001
205 # Run setup script plan if it exists
207 SETUP="${TESTPLANDIR}/setup.sh"
208 if [ -f "${SETUP}" ]; then
209 echo "Running setup script ${SETUP}"
210 source_safely "${SETUP}"
213 # show memory consumption after all docker instances initialized
214 docker_stats | tee "$WORKSPACE/archives/$TESTPLAN/_sysinfo-1-after-setup.txt"
217 echo ROBOT_VARIABLES="${ROBOT_VARIABLES}"
218 echo "Starting Robot test suites ${SUITES} ..."
221 echo "Versioning information:"
224 python3 -m robot.run --version || :
226 run_test_plan "testplanCps"
230 checkandmount="${TESTPLANDIR}/sdnc/check_sdnc_mount_node.sh"
231 if [ -f "${checkandmount}" ]; then
232 echo "Running check_sdnc_mount_node script ${checkandmount}"
233 source_safely "${checkandmount}"
236 run_test_plan "testplanNcmp"
239 # Note that the final steps are done in on_exit function after this exit!
240 exit $CPSRESULT || $NCMPRESULT