Allow executing ODL test as many times as wanted on the same env
[functest.git] / testcases / Controllers / ODL / CI / start_tests.sh
1 #!/bin/bash
2 # it includes python2.7 virtual env with robot packages and git
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9
10 BASEDIR=`dirname $0`
11 RESULTS_DIR='/home/opnfv/functest/results/odl/'
12 REPO_DIR='/home/opnfv/repos/odl_integration'
13 #TODO: read this form config_functest.yaml
14
15 # Colors
16 green='\033[0;32m'
17 light_green='\033[1;32m'
18 red='\033[1;31m'
19 nc='\033[0m' # No Color
20
21 usage="Script for starting ODL tests. Tests to be executed are specified in test_list.txt file.
22
23 usage:
24 [var=value] bash $(basename "$0") [-h]
25
26 where:
27     -h     show this help text
28     var    one of the following: ODL_IP, ODL_PORT, USR_NAME, PASS, NEUTRON_IP
29     value  new value for var
30
31 example:
32     ODL_IP=oscontro1 ODL_PORT=8080 bash $(basename "$0")"
33
34 while getopts ':h' option; do
35   case "$option" in
36     h) echo "$usage"
37        exit
38        ;;
39    \?) printf "illegal option: -%s\n" "$OPTARG" >&2
40        echo "$usage" >&2
41        exit 1
42        ;;
43   esac
44 done
45
46 echo -e "${green}Current environment parameters for ODL suite.${nc}"
47 # Following vars might be also specified as CLI params
48 set -x
49 ODL_IP=${ODL_IP:-'192.168.1.5'}
50 ODL_PORT=${ODL_PORT:-8081}
51 USR_NAME=${USR_NAME:-'neutron'}
52 PASS=${PASS:-'octopus'}
53 NEUTRON_IP=${NEUTRON_IP:-192.168.0.68}
54 set +x
55
56 init_file=${REPO_DIR}/test/csit/suites/openstack/neutron/__init__.robot
57 # Change openstack password for admin tenant in neutron suite
58 sed -i "s/\"password\": \".*\"/\"password\": \"${PASS}\"/" $init_file
59
60 # Add Start Suite and Teardown Suite
61 if [[ ! `grep 'Suite Teardown' ${init_file}` ]]; then
62     sed -i "/^Documentation.*/a Suite Teardown     Stop Suite" $init_file
63     sed -i "/^Documentation.*/a Suite Setup        Start Suite" $init_file
64 fi
65
66 # add custom tests to suite, if there are more custom tests needed this will be reworked
67 echo -e "${green}Copy custom tests to suite.${nc}"
68 cp -vf ${BASEDIR}/custom_tests/neutron/* ${REPO_DIR}/test/csit/suites/openstack/neutron/
69
70 # List of tests are specified in test_list.txt
71 # those are relative paths to test directories from integartion suite
72 echo -e "${green}Executing chosen tests.${nc}"
73 test_num=0
74 while read line
75 do
76     # skip comments
77     [[ ${line:0:1} == "#" ]] && continue
78     # skip empty lines
79     [[ -z "${line}" ]] && continue
80
81     ((test_num++))
82     echo -e "${light_green}Starting test: $line ${nc}"
83     pybot -v OPENSTACK:${NEUTRON_IP} -v PORT:${ODL_PORT} -v CONTROLLER:${ODL_IP} ${REPO_DIR}/$line
84     mkdir -p $RESULTS_DIR/logs/${test_num}
85     mv log.html $RESULTS_DIR/logs/${test_num}/
86     mv report.html $RESULTS_DIR/logs/${test_num}/
87     mv output.xml $RESULTS_DIR/logs/${test_num}/
88 done < ${BASEDIR}/test_list.txt
89
90 # create final report which includes all partial test reports
91 for i in $(seq $test_num); do
92   rebot_params="$rebot_params $RESULTS_DIR/logs/$i/output.xml"
93 done
94
95 echo -e "${green}Final report is located:${nc}"
96 rebot $rebot_params