Enhance ips, ports and creds management
[functest.git] / 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_CONF_DIR=/home/opnfv/functest/conf/
41
42
43 function odl_tests(){
44     keystone_ip=$(openstack catalog show identity |grep publicURL| cut -f3 -d"/" | cut -f1 -d":")
45     neutron_ip=$(openstack catalog show network | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
46     odl_ip=${neutron_ip}
47     odl_port=8181
48     if [ "$INSTALLER_TYPE" == "fuel" ]; then
49         odl_port=8282
50     elif [ "$INSTALLER_TYPE" == "apex" ]; then
51         :
52     elif [ "$INSTALLER_TYPE" == "joid" ]; then
53         odl_ip=$SDN_CONTROLLER
54         odl_port=8080
55         :
56     elif [ "$INSTALLER_TYPE" == "compass" ]; then
57         :
58     else
59         odl_ip=$SDN_CONTROLLER
60         odl_port=8080
61     fi
62 }
63
64 function run_test(){
65     test_name=$1
66     serial_flag=""
67     if [ $serial == "true" ]; then
68         serial_flag="-s"
69     fi
70
71     case $test_name in
72         "healthcheck")
73             ${FUNCTEST_REPO_DIR}/testcases/OpenStack/healthcheck/healthcheck.sh
74         ;;
75         "vping_ssh")
76             python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/vPing/vPing_ssh.py $report
77         ;;
78         "vping_userdata")
79             python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/vPing/vPing_userdata.py $report
80         ;;
81         "odl")
82             odl_tests
83             ODL_WEB_PORT=$odl_port ODL_IP=$odl_ip KEYSTONE_IP=$keystone_ip NEUTRON_IP=$neutron_ip \
84                 TENANT_NAME=${OS_TENANT_NAME} USR_NAME=${OS_USERNAME} PASS=${OS_PASSWORD} \
85                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/start_tests.sh
86
87             # push results to the DB in case of CI
88             if [[ "$report" == "-r" &&
89                   -n "$DEPLOY_SCENARIO" && "$DEPLOY_SCENARIO" != "none" &&
90                   -n "$INSTALLER_TYPE" && "$INSTALLER_TYPE" != "none" ]] &&
91                env | grep NODE_NAME > /dev/null; then
92                 odl_logs="/home/opnfv/functest/results/odl/logs/2"
93                 odl_path="${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/"
94                 node_name=$(env | grep NODE_NAME | cut -f2 -d'=')
95                 python ${odl_path}/odlreport2db.py -x ${odl_logs}/output.xml -i ${INSTALLER_TYPE} -p ${node_name} -s ${DEPLOY_SCENARIO}
96             fi
97         ;;
98         "tempest_smoke_serial")
99             python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/tempest/run_tempest.py \
100                 $clean_flag -s -m smoke $report
101         ;;
102         "tempest_full_parallel")
103             python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/tempest/run_tempest.py \
104                 $serial_flag $clean_flag -m full $report
105         ;;
106         "vims")
107             python ${FUNCTEST_REPO_DIR}/testcases/vnf/vIMS/vIMS.py $clean_flag $report
108         ;;
109         "rally_full")
110             python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/rally/run_rally-cert.py $clean_flag all $report
111         ;;
112         "rally_sanity")
113             python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/rally/run_rally-cert.py \
114                 $clean_flag --sanity all $report
115         ;;
116         "bgpvpn")
117             python ${FUNCTEST_REPO_DIR}/testcases/features/bgpvpn.py
118         ;;
119         "onos")
120             python ${FUNCTEST_REPO_DIR}/testcases/Controllers/ONOS/Teston/onosfunctest.py
121       ;;
122         "promise")
123             python ${FUNCTEST_REPO_DIR}/testcases/features/promise.py $report
124             sleep 10 # to let the instances terminate
125         ;;
126         "doctor")
127             python ${FUNCTEST_REPO_DIR}/testcases/features/doctor.py
128         ;;
129         "ovno")
130             # suite under rewritting for colorado
131             # no need to run anything until refactoring done
132             # ${repos_dir}/ovno/Testcases/RunTests.sh
133         ;;
134         "security_scan")
135             echo "Sourcing Credentials ${FUNCTEST_CONF_DIR}/stackrc for undercloud .."
136             source ${FUNCTEST_CONF_DIR}/stackrc
137             python ${FUNCTEST_REPO_DIR}/testcases/security_scan/security_scan.py --config ${FUNCTEST_REPO_DIR}/testcases/security_scan/config.ini
138         ;;
139         "copper")
140             python ${FUNCTEST_REPO_DIR}/testcases/features/copper.py
141         ;;
142         "moon")
143             # TODO put the link to Moon script to be run (if test runnable) here
144             ${repos_dir}/moon/tests/run_tests.sh
145         ;;
146         "multisite")
147             python ${FUNCTEST_REPO_DIR}/testcases/features/multisite.py
148         ;;
149         *)
150             echo "The test case '${test_name}' does not exist."
151             exit 1
152     esac
153
154     if [[ $? != 0 ]]; then exit 1
155     else exit 0
156     fi
157 }
158
159
160 # Parse parameters
161 while [[ $# > 0 ]]
162     do
163     key="$1"
164     case $key in
165         -h|--help)
166             echo "$usage"
167             exit 0
168             shift
169         ;;
170         -r|--report)
171             report="-r"
172         ;;
173         -s|--serial)
174             serial=true
175         ;;
176         -t|--test|--tests)
177             TEST="$2"
178             shift
179         ;;
180         *)
181             echo "unknown option $1 $2"
182             exit 1
183         ;;
184     esac
185     shift # past argument or value
186 done
187
188
189 # Source credentials
190 echo "Sourcing Credentials ${FUNCTEST_CONF_DIR}/openstack.creds to run the test.."
191 source ${FUNCTEST_CONF_DIR}/openstack.creds
192
193
194 # Run test
195 run_test $TEST