6fdc42666cdde29634bba886123efc3044132e6f
[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 export PYTHONUNBUFFERED=1
43
44 function odl_tests(){
45     keystone_ip=$(openstack catalog show identity |grep publicURL| cut -f3 -d"/" | cut -f1 -d":")
46     neutron_ip=$(openstack catalog show network | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
47     odl_ip=${neutron_ip}
48     odl_port=8080
49     if [ "$INSTALLER_TYPE" == "fuel" ]; then
50         odl_port=8282
51     elif [ "$INSTALLER_TYPE" == "apex" ]; then
52         odl_ip=$SDN_CONTROLLER_IP
53         odl_port=8181
54     elif [ "$INSTALLER_TYPE" == "joid" ]; then
55         odl_ip=$SDN_CONTROLLER
56     elif [ "$INSTALLER_TYPE" == "compass" ]; then
57         odl_port=8181
58     else
59         odl_ip=$SDN_CONTROLLER_IP
60     fi
61 }
62
63 function sfc_prepare(){
64     ids=($(neutron security-group-list|grep default|awk '{print $2}'))
65     for id in ${ids[@]}; do
66         if ! neutron security-group-show $id|grep "22/tcp" &>/dev/null; then
67             neutron security-group-rule-create --protocol tcp \
68                 --port-range-min 22 --port-range-max 22 --direction ingress $id
69             neutron security-group-rule-create --protocol tcp \
70                 --port-range-min 22 --port-range-max 22 --direction egress $id
71         fi
72     done
73 }
74
75 function run_test(){
76     test_name=$1
77     serial_flag=""
78     if [ $serial == "true" ]; then
79         serial_flag="-s"
80     fi
81
82     case $test_name in
83         "healthcheck")
84             ${FUNCTEST_REPO_DIR}/testcases/OpenStack/healthcheck/healthcheck.sh
85         ;;
86         "vping_ssh")
87             python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/vPing/vping.py -m ssh $report
88         ;;
89         "vping_userdata")
90             python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/vPing/vping.py -m userdata $report
91         ;;
92         "odl")
93             odl_tests
94             [[ "$report" == "-r" ]] && args=-p
95             ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/OpenDaylightTesting.py \
96                 --keystoneip $keystone_ip --neutronip $neutron_ip \
97                 --osusername ${OS_USERNAME} --ostenantname ${OS_TENANT_NAME} \
98                 --ospassword ${OS_PASSWORD} \
99                 --odlip $odl_ip --odlwebport $odl_port ${args}
100         ;;
101         "tempest_smoke_serial")
102             python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/tempest/run_tempest.py \
103                 $clean_flag -s -m smoke $report
104         ;;
105         "tempest_full_parallel")
106             python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/tempest/run_tempest.py \
107                 $serial_flag $clean_flag -m full $report
108         ;;
109         "vims")
110             python ${FUNCTEST_REPO_DIR}/testcases/vnf/vIMS/vIMS.py $clean_flag $report
111         ;;
112         "rally_full")
113             python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/rally/run_rally-cert.py $clean_flag all $report
114         ;;
115         "rally_sanity")
116             python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/rally/run_rally-cert.py \
117                 $clean_flag --sanity all $report
118         ;;
119         "bgpvpn")
120             sdnvpn_repo_dir=${repos_dir}/sdnvpn/test/functest/
121             python ${sdnvpn_repo_dir}/run_tests.py $report
122         ;;
123         "onos")
124             python ${FUNCTEST_REPO_DIR}/testcases/Controllers/ONOS/Teston/onosfunctest.py
125         ;;
126         "onos_sfc")
127             python ${FUNCTEST_REPO_DIR}/testcases/Controllers/ONOS/Teston/onosfunctest.py -t sfc
128         ;;
129         "promise")
130             python ${FUNCTEST_REPO_DIR}/testcases/features/promise.py $report
131             sleep 10 # to let the instances terminate
132         ;;
133         "doctor")
134             python ${FUNCTEST_REPO_DIR}/testcases/features/doctor.py $report
135         ;;
136         "ovno")
137             # suite under rewritting for colorado
138             # no need to run anything until refactoring done
139             # ${repos_dir}/ovno/Testcases/RunTests.sh
140         ;;
141         "security_scan")
142             echo "Sourcing Credentials ${FUNCTEST_CONF_DIR}/stackrc for undercloud .."
143             source ${FUNCTEST_CONF_DIR}/stackrc
144             python ${repos_dir}/securityscanning/security_scan.py --config ${repos_dir}/securityscanning/config.ini
145         ;;
146         "copper")
147             python ${FUNCTEST_REPO_DIR}/testcases/features/copper.py $report
148         ;;
149         "moon")
150             python ${repos_dir}/moon/tests/run_tests.py $report
151         ;;
152         "multisite")
153             python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/tempest/gen_tempest_conf.py
154             python ${FUNCTEST_REPO_DIR}/testcases/OpenStack/tempest/run_tempest.py \
155                 $clean_flag -s -m feature_multisite $report \
156                 -c ${FUNCTEST_REPO_DIR}/testcases/OpenStack/tempest/tempest_multisite.conf
157         ;;
158         "domino")
159             python ${FUNCTEST_REPO_DIR}/testcases/features/domino.py $report
160         ;;
161         "odl-sfc")
162             ODL_SFC_DIR=${FUNCTEST_REPO_DIR}/testcases/features/sfc
163             # pass FUNCTEST_REPO_DIR inside prepare_odl_sfc.bash
164             FUNCTEST_REPO_DIR=${FUNCTEST_REPO_DIR} python ${ODL_SFC_DIR}/prepare_odl_sfc.py || exit $?
165             source ${ODL_SFC_DIR}/tackerc
166             python ${ODL_SFC_DIR}/sfc_colorado1.py $report
167         ;;
168         "parser")
169             python ${FUNCTEST_REPO_DIR}/testcases/vnf/vRNC/parser.py $report
170         ;;
171         *)
172             echo "The test case '${test_name}' does not exist."
173             exit 1
174     esac
175
176     if [[ $? != 0 ]]; then exit 1
177     else exit 0
178     fi
179 }
180
181
182 # Parse parameters
183 while [[ $# > 0 ]]
184     do
185     key="$1"
186     case $key in
187         -h|--help)
188             echo "$usage"
189             exit 0
190             shift
191         ;;
192         -r|--report)
193             report="-r"
194         ;;
195         -s|--serial)
196             serial=true
197         ;;
198         -t|--test|--tests)
199             TEST="$2"
200             shift
201         ;;
202         *)
203             echo "unknown option $1 $2"
204             exit 1
205         ;;
206     esac
207     shift # past argument or value
208 done
209
210
211 # Source credentials
212 echo "Sourcing Credentials ${FUNCTEST_CONF_DIR}/openstack.creds to run the test.."
213 source ${FUNCTEST_CONF_DIR}/openstack.creds
214
215 # ODL Boron workaround to create additional flow rules to allow port 22 TCP
216 if [[ $DEPLOY_SCENARIO == *"odl_l2-sfc"* ]]; then
217     sfc_prepare
218 fi
219
220 # Run test
221 run_test $TEST