Merge "Change log level when pod, scenario or build_tag cannot be retrieved"
[functest.git] / functest / ci / exec_test.sh
1 #!/bin/bash
2
3 #
4 # Author: Jose Lausuch (jose.lausuch@ericsson.com)
5 #         Morgan Richomme (morgan.richomme@orange.com)
6 # Installs the Functest framework within the Docker container
7 # and run the tests automatically
8 #
9 #
10 # All rights reserved. This program and the accompanying materials
11 # are made available under the terms of the Apache License, Version 2.0
12 # which accompanies this distribution, and is available at
13 # http://www.apache.org/licenses/LICENSE-2.0
14 #
15
16 usage="Script to trigger the tests automatically.
17
18 usage:
19     bash $(basename "$0") [-h|--help] [-t <test_name>]
20
21 where:
22     -h|--help         show this help text
23     -r|--report       push results to database (false by default)
24     -s|--serial       run Tempest tests in one thread
25     -t|--test         run specific test case
26       <test_name>"
27
28
29 report=""
30 serial=false
31
32 # Get the list of runnable tests
33 # Check if we are in CI mode
34 debug=""
35 if [[ "${CI_DEBUG,,}" == "true" ]];then
36     debug="--debug"
37 fi
38
39 FUNCTEST_REPO_DIR=${REPOS_DIR}/functest
40 FUNCTEST_TEST_DIR=${REPOS_DIR}/functest/functest/opnfv_tests
41 FUNCTEST_CONF_DIR=/home/opnfv/functest/conf
42
43 export PYTHONUNBUFFERED=1
44
45 function odl_tests(){
46     keystone_ip=$(openstack catalog show identity |grep publicURL| cut -f3 -d"/" | cut -f1 -d":")
47     neutron_ip=$(openstack catalog show network | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
48     odl_ip=${neutron_ip}
49     odl_port=8080
50     odl_restport=8181
51     if [ "$INSTALLER_TYPE" == "fuel" ]; then
52         odl_port=8282
53     elif [ "$INSTALLER_TYPE" == "apex" ]; then
54         odl_ip=$SDN_CONTROLLER_IP
55         odl_port=8081
56         odl_restport=8081
57     elif [ "$INSTALLER_TYPE" == "netvirt" ]; then
58         odl_ip=$SDN_CONTROLLER_IP
59         odl_port=8081
60         odl_restport=8081
61     elif [ "$INSTALLER_TYPE" == "joid" ]; then
62         odl_ip=$SDN_CONTROLLER
63     elif [ "$INSTALLER_TYPE" == "compass" ]; then
64         odl_port=8181
65     else
66         odl_ip=$SDN_CONTROLLER_IP
67     fi
68 }
69
70
71
72 function run_test(){
73     test_name=$1
74     serial_flag=""
75     if [ $serial == "true" ]; then
76         serial_flag="-s"
77     fi
78
79     case $test_name in
80         "healthcheck")
81             ${FUNCTEST_TEST_DIR}/openstack/healthcheck/healthcheck.sh
82         ;;
83         "odl")
84             odl_tests
85             [[ "$report" == "-r" ]] && args=-p
86             ${FUNCTEST_TEST_DIR}/sdn/odl/odl.py \
87                 --keystoneip $keystone_ip \
88                 --neutronip $neutron_ip \
89                 --odlip $odl_ip \
90                 --odlrestconfport $odl_restport \
91                 --odlwebport $odl_port \
92                 --ospassword ${OS_PASSWORD} \
93                 --ostenantname ${OS_TENANT_NAME} \
94                 --osusername ${OS_USERNAME} \
95                 ${args}
96         ;;
97         "onos")
98             python ${FUNCTEST_TEST_DIR}/sdn/onos/teston/onos.py
99         ;;
100         "onos_sfc")
101             python ${FUNCTEST_TEST_DIR}/sdn/onos/teston/onos.py -t sfc
102         ;;
103         "ovno")
104             # suite under rewritting for colorado
105             # no need to run anything until refactoring done
106             # ${REPOS_DIR}/ovno/Testcases/RunTests.sh
107         ;;
108         "security_scan")
109             echo "Sourcing Credentials ${FUNCTEST_CONF_DIR}/stackrc for undercloud .."
110             source ${FUNCTEST_CONF_DIR}/stackrc
111             python ${FUNCTEST_TEST_DIR}/security_scan/security_scan.py --config ${FUNCTEST_TEST_DIR}/security_scan/config.ini
112         ;;
113         "moon")
114             python ${REPOS_DIR}/moon/tests/run_tests.py $report
115         ;;
116         *)
117             echo "The test case '${test_name}' does not exist."
118             exit 1
119     esac
120
121     if [[ $? != 0 ]]; then exit 1
122     else exit 0
123     fi
124 }
125
126
127 # Parse parameters
128 while [[ $# > 0 ]]
129     do
130     key="$1"
131     case $key in
132         -h|--help)
133             echo "$usage"
134             exit 0
135             shift
136         ;;
137         -r|--report)
138             report="-r"
139         ;;
140         -s|--serial)
141             serial=true
142         ;;
143         -t|--test|--tests)
144             TEST="$2"
145             shift
146         ;;
147         *)
148             echo "unknown option $1 $2"
149             exit 1
150         ;;
151     esac
152     shift # past argument or value
153 done
154
155
156 # Source credentials
157 echo "Sourcing Credentials ${creds} to run the test.."
158 source ${creds}
159
160
161 # Run test
162 run_test $TEST