56f4d564d5b8f023af3363e5df711ef537926aec
[functest.git] / testcases / Controllers / ODL / CI / start_tests.sh
1 #!/bin/bash
2 # Script requires that test environment is created already
3 # it includes python2.7 virtual env with robot packages and git
4 # use create_env.sh script for creating python virtualenv
5
6 BASEDIR=`dirname $0`
7 # Colors
8 green='\033[0;32m'
9 light_green='\033[1;32m'
10 red='\033[1;31m'
11 nc='\033[0m' # No Color
12
13 usage="Script for starting ODL tests. Tests to be executed are specified in test_list.txt file.
14
15 usage:
16 [var=value] bash $(basename "$0") [-h]
17
18 where:
19     -h     show this help text
20     var    one of the following: ODL_IP, ODL_PORT, USR_NAME, PASS, NEUTRON_IP
21     value  new value for var
22
23 example:
24     ODL_IP=oscontro1 ODL_PORT=8080 bash $(basename "$0")"
25
26 while getopts ':h' option; do
27   case "$option" in
28     h) echo "$usage"
29        exit
30        ;;
31    \?) printf "illegal option: -%s\n" "$OPTARG" >&2
32        echo "$usage" >&2
33        exit 1
34        ;;
35   esac
36 done
37
38 echo -e "${green}Current environment parameters for ODL suite.${nc}"
39 # Following vars might be also specified as CLI params
40 set -x
41 ODL_IP=${ODL_IP:-'192.168.1.5'}
42 ODL_PORT=${ODL_PORT:-8081}
43 USR_NAME=${USR_NAME:-'neutron'}
44 PASS=${PASS:-'octopus'}
45 NEUTRON_IP=${NEUTRON_IP:-192.168.0.68}
46 set +x
47
48 echo -e "${green}Cloning ODL integration git repo.${nc}"
49 if [ -d ${BASEDIR}/integration ]; then
50     cd ${BASEDIR}/integration
51     git checkout -- .
52     git pull
53     cd -
54 else
55     git clone https://github.com/opendaylight/integration.git ${BASEDIR}/integration
56 fi
57
58 # Change openstack password for admin tenant in neutron suite
59 sed -i "s/\"password\": \".*\"/\"password\": \"${PASS}\"/" ${BASEDIR}/integration/test/csit/suites/openstack/neutron/__init__.robot
60
61 # Add Start Suite and Teardown Suite
62 sed -i "/^Documentation.*/a Suite Teardown     Stop Suite" ${BASEDIR}/integration/test/csit/suites/openstack/neutron/__init__.robot
63 sed -i "/^Documentation.*/a Suite Setup        Start Suite" ${BASEDIR}/integration/test/csit/suites/openstack/neutron/__init__.robot
64
65 if source $BASEDIR/venv/bin/activate; then
66     echo -e "${green}Python virtualenv activated.${nc}"
67 else
68     echo -e "${red}ERROR${nc}"
69     exit 1
70 fi
71
72 # add custom tests to suite, if there are more custom tests needed this will be reworked
73 echo -e "${green}Copy custom tests to suite.${nc}"
74 cp -vf $BASEDIR/custom_tests/neutron/* $BASEDIR/integration/test/csit/suites/openstack/neutron/
75
76 # List of tests are specified in test_list.txt
77 # those are relative paths to test directories from integartion suite
78 echo -e "${green}Executing chosen tests.${nc}"
79 test_num=0
80 while read line
81 do
82     # skip comments
83     [[ ${line:0:1} == "#" ]] && continue
84     # skip empty lines
85     [[ -z "${line}" ]] && continue
86
87     ((test_num++))
88     echo -e "${light_green}Starting test: $line ${nc}"
89     pybot -v OPENSTACK:${NEUTRON_IP} -v PORT:${ODL_PORT} -v CONTROLLER:${ODL_IP} ${BASEDIR}/$line
90     mkdir -p $BASEDIR/logs/${test_num}
91     mv log.html $BASEDIR/logs/${test_num}/
92     mv report.html $BASEDIR/logs/${test_num}/
93     mv output.xml $BASEDIR/logs/${test_num}/
94 done < ${BASEDIR}/test_list.txt
95
96 # create final report which includes all partial test reports
97 for i in $(seq $test_num); do
98   rebot_params="$rebot_params $BASEDIR/logs/$i/output.xml"
99 done
100
101 echo -e "${green}Final report is located:${nc}"
102 rebot $rebot_params
103
104 # deactivate venv
105 echo -e "${green}Deactivate venv.${nc}"
106 deactivate