blob: 5551d212a215dfc90d464c11d7e43b50ca6023cb [file] [log] [blame]
Gary Wu13111e92018-09-27 11:31:33 -07001#!/bin/bash -x
Gary Wu9abb61c2018-09-27 10:38:50 -07002#
3# Copyright 2016-2017 Huawei Technologies Co., Ltd.
kaihlavi203e43a2019-08-16 16:02:38 +03004# Modification Copyright 2019 © Samsung Electronics Co., Ltd.
Gary Wu9abb61c2018-09-27 10:38:50 -07005#
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
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
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.
17#
18# $1 project/functionality
19# $2 robot options
Gary Wu9abb61c2018-09-27 10:38:50 -070020
Petr Ospalý5cf13912019-09-09 18:00:05 +020021#
22# functions
23#
24
Gary Wu9abb61c2018-09-27 10:38:50 -070025function docker_stats(){
26 #General memory details
27 echo "> top -bn1 | head -3"
28 top -bn1 | head -3
29 echo
30
31 echo "> free -h"
32 free -h
33 echo
34
35 #Memory details per Docker
36 echo "> docker ps"
37 docker ps
38 echo
39
40 echo "> docker stats --no-stream"
41 docker stats --no-stream
42 echo
43}
44
Petr Ospalý5cf13912019-09-09 18:00:05 +020045# save current set options
46function save_set() {
47 RUN_CSIT_SAVE_SET="$-"
48 RUN_CSIT_SHELLOPTS="$SHELLOPTS"
49}
50
51# load the saved set options
52function load_set() {
53 _setopts="$-"
54
55 # bash shellopts
56 for i in $(echo "$SHELLOPTS" | tr ':' ' ') ; do
57 set +o ${i}
58 done
59 for i in $(echo "$RUN_CSIT_SHELLOPTS" | tr ':' ' ') ; do
60 set -o ${i}
61 done
62
63 # other options
64 for i in $(echo "$_setopts" | sed 's/./& /g') ; do
65 set +${i}
66 done
67 set -${RUN_CSIT_SAVE_SET}
68}
69
70# set options for quick bailout when error
71function harden_set() {
72 set -xeo pipefail
73 set +u # enabled it would probably fail too many often
74}
75
76# relax set options so the sourced file will not fail
77# the responsibility is shifted to the sourced file...
78function relax_set() {
79 set +e
80 set +o pipefail
81}
82
83# wrapper for sourcing a file
84function source_safely() {
85 [ -z "$1" ] && return 1
86 relax_set
87 . "$1"
88 load_set
89}
90
91#
92# main
93#
94
95# set and save options for quick failure
96harden_set && save_set
97
Gary Wu9abb61c2018-09-27 10:38:50 -070098if [ $# -eq 0 ]
99then
kaihlavi203e43a2019-08-16 16:02:38 +0300100 echo
101 echo "Usage: $0 plans/<project>/<functionality> [<robot-options>]"
Gary Wu9abb61c2018-09-27 10:38:50 -0700102 echo
103 echo " <project>, <functionality>, <robot-options>: "
104 echo " The same values as for the '{project}-csit-{functionality}' JJB job template."
105 echo
Gary Wu9abb61c2018-09-27 10:38:50 -0700106 exit 1
107fi
108
109if [ -z "$WORKSPACE" ]; then
Petr Ospalý5cf13912019-09-09 18:00:05 +0200110 export WORKSPACE=$(git rev-parse --show-toplevel)
Gary Wu9abb61c2018-09-27 10:38:50 -0700111fi
kaihlavi203e43a2019-08-16 16:02:38 +0300112
Petr Ospalý5cf13912019-09-09 18:00:05 +0200113rm -rf "$WORKSPACE/archives"
114mkdir -p "$WORKSPACE/archives"
Gary Wu9abb61c2018-09-27 10:38:50 -0700115
Petr Ospalý5cf13912019-09-09 18:00:05 +0200116if [ -f "${WORKSPACE}/${1}/testplan.txt" ]; then
Gary Wu9abb61c2018-09-27 10:38:50 -0700117 export TESTPLAN="${1}"
118else
Gary Wu13111e92018-09-27 11:31:33 -0700119 echo "testplan not found: ${WORKSPACE}/${TESTPLAN}/testplan.txt"
Gary Wu9abb61c2018-09-27 10:38:50 -0700120 exit 2
121fi
122
Gary Wu9abb61c2018-09-27 10:38:50 -0700123export TESTOPTIONS="${2}"
124
Petr Ospalý5cf13912019-09-09 18:00:05 +0200125TESTPLANDIR="${WORKSPACE}/${TESTPLAN}"
Gary Wu9abb61c2018-09-27 10:38:50 -0700126
kaihlavi9f5700f2019-08-27 11:30:51 +0300127# Run installation of prerequired libraries
Petr Ospalý5cf13912019-09-09 18:00:05 +0200128source_safely "${WORKSPACE}/prepare-csit.sh"
Gary Wu9abb61c2018-09-27 10:38:50 -0700129
kaihlavi203e43a2019-08-16 16:02:38 +0300130# Activate the virtualenv containing all the required libraries installed by prepare-csit.sh
Petr Ospalý5cf13912019-09-09 18:00:05 +0200131source_safely "${ROBOT_VENV}/bin/activate"
Gary Wu9abb61c2018-09-27 10:38:50 -0700132
Petr Ospalý5cf13912019-09-09 18:00:05 +0200133WORKDIR=$(mktemp -d --suffix=-robot-workdir)
134cd "${WORKDIR}"
Gary Wu9abb61c2018-09-27 10:38:50 -0700135
Gary Wu9abb61c2018-09-27 10:38:50 -0700136# Add csit scripts to PATH
Petr Ospalý5cf13912019-09-09 18:00:05 +0200137export PATH="${PATH}:${WORKSPACE}/docker/scripts:${WORKSPACE}/scripts:${ROBOT_VENV}/bin"
138export SCRIPTS="${WORKSPACE}/scripts"
Gary Wu9abb61c2018-09-27 10:38:50 -0700139export ROBOT_VARIABLES=
140
141# Sign in to nexus3 docker repo
142docker login -u anonymous -p anonymous nexus3.onap.org:10001
143
144# Run setup script plan if it exists
Petr Ospalý5cf13912019-09-09 18:00:05 +0200145cd "${TESTPLANDIR}"
146SETUP="${TESTPLANDIR}/setup.sh"
147if [ -f "${SETUP}" ]; then
Gary Wu9abb61c2018-09-27 10:38:50 -0700148 echo "Running setup script ${SETUP}"
Petr Ospalý5cf13912019-09-09 18:00:05 +0200149 source_safely "${SETUP}"
Gary Wu9abb61c2018-09-27 10:38:50 -0700150fi
151
152# show memory consumption after all docker instances initialized
Petr Ospalý5cf13912019-09-09 18:00:05 +0200153docker_stats | tee "$WORKSPACE/archives/_sysinfo-1-after-setup.txt"
Gary Wu9abb61c2018-09-27 10:38:50 -0700154
155# Run test plan
Petr Ospalý5cf13912019-09-09 18:00:05 +0200156cd "$WORKDIR"
Gary Wu9abb61c2018-09-27 10:38:50 -0700157echo "Reading the testplan:"
Petr Ospalý5cf13912019-09-09 18:00:05 +0200158cat "${TESTPLANDIR}/testplan.txt" | egrep -v '(^[[:space:]]*#|^[[:space:]]*$)' | sed "s|^|${WORKSPACE}/tests/|" > testplan.txt
Gary Wu9abb61c2018-09-27 10:38:50 -0700159cat testplan.txt
160SUITES=$( xargs -a testplan.txt )
161
Petr Ospalý5cf13912019-09-09 18:00:05 +0200162echo ROBOT_VARIABLES="${ROBOT_VARIABLES}"
Gary Wu9abb61c2018-09-27 10:38:50 -0700163echo "Starting Robot test suites ${SUITES} ..."
Petr Ospalý5cf13912019-09-09 18:00:05 +0200164relax_set
Gary Wu9abb61c2018-09-27 10:38:50 -0700165python -m robot.run -N ${TESTPLAN} -v WORKSPACE:/tmp ${ROBOT_VARIABLES} ${TESTOPTIONS} ${SUITES}
166RESULT=$?
Petr Ospalý5cf13912019-09-09 18:00:05 +0200167load_set
168echo "RESULT: $RESULT"
169rsync -av "$WORKDIR/" "$WORKSPACE/archives"
Gary Wu9abb61c2018-09-27 10:38:50 -0700170
171# Record list of active docker containers
Petr Ospalý5cf13912019-09-09 18:00:05 +0200172docker ps --format "{{.Image}}" > "$WORKSPACE/archives/_docker-images.log"
Gary Wu9abb61c2018-09-27 10:38:50 -0700173
174# show memory consumption after all docker instances initialized
Petr Ospalý5cf13912019-09-09 18:00:05 +0200175docker_stats | tee "$WORKSPACE/archives/_sysinfo-2-after-robot.txt"
Gary Wu9abb61c2018-09-27 10:38:50 -0700176
177# Run teardown script plan if it exists
Petr Ospalý5cf13912019-09-09 18:00:05 +0200178cd "${TESTPLANDIR}"
179TEARDOWN="${TESTPLANDIR}/teardown.sh"
180if [ -f "${TEARDOWN}" ]; then
Gary Wu9abb61c2018-09-27 10:38:50 -0700181 echo "Running teardown script ${TEARDOWN}"
Petr Ospalý5cf13912019-09-09 18:00:05 +0200182 source_safely "${TEARDOWN}"
Gary Wu9abb61c2018-09-27 10:38:50 -0700183fi
184
185# TODO: do something with the output
186
187exit $RESULT