Merge "Add a step to enable docker run without sudo"
[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     # historically most of the installers use the same IP for neutron and keystone API
46     neutron_ip=$keystone_ip
47     odl_ip=$(openstack catalog show network | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
48     usr_name=$(env | grep OS | grep OS_USERNAME | cut -f2 -d'=')
49     password=$(env | grep OS | grep OS_PASSWORD | cut -f2 -d'=')
50     odl_port=8181
51     if [ $INSTALLER_TYPE == "fuel" ]; then
52         odl_port=8282
53     elif [ $INSTALLER_TYPE == "apex" ]; then
54         :
55     elif [ $INSTALLER_TYPE == "joid" ]; then
56         odl_ip=$(env | grep SDN_CONTROLLER | cut -f2 -d'=')
57         neutron_ip=$(openstack catalog show network | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
58         odl_port=8080
59         :
60     elif [ $INSTALLER_TYPE == "compass" ]; then
61         :
62     else
63         error "INSTALLER_TYPE not valid."
64         exit 1
65     fi
66 }
67 function run_test(){
68     test_name=$1
69     echo -e "\n\n\n\n"
70     echo "----------------------------------------------"
71     echo "  Running test case: ${test_name}"
72     echo "----------------------------------------------"
73     echo ""
74     serial_flag=""
75     if [ $serial == "true" ]; then
76         serial_flag="-s"
77     fi
78
79     case $test_name in
80         "healthcheck")
81             echo "Running health check test..."
82             ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/healthcheck.sh
83         ;;
84         "vping_ssh")
85             echo "Running vPing-SSH test..."
86             python ${FUNCTEST_REPO_DIR}/testcases/vPing/CI/libraries/vPing_ssh.py \
87                 $debug $report
88         ;;
89         "vping_userdata")
90             echo "Running vPing-userdata test... "
91             python ${FUNCTEST_REPO_DIR}/testcases/vPing/CI/libraries/vPing_userdata.py \
92                 $debug $report
93         ;;
94         "odl")
95             echo "Running ODL test..."
96             odl_tests
97             ODL_PORT=$odl_port ODL_IP=$odl_ip KEYSTONE_IP=$keystone_ip NEUTRON_IP=$neutron_ip USR_NAME=$usr_name PASS=$password \
98                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/start_tests.sh
99
100             # push results to the DB in case of CI
101             if [[ -n "$DEPLOY_SCENARIO" && "$DEPLOY_SCENARIO" != "none" ]]; then
102                 odl_logs="/home/opnfv/functest/results/odl/logs/2"
103                 odl_path="${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI"
104                 node_name=$(env | grep NODE_NAME | cut -f2 -d'=')
105                 python ${odl_path}/odlreport2db.py -x ${odl_logs}/output.xml -i ${INSTALLER_TYPE} -p ${node_name} -s ${DEPLOY_SCENARIO}
106             fi
107         ;;
108         "tempest")
109             echo "Running Tempest tests..."
110             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_tempest.py \
111                 $debug $serial_flag $clean_flag -m smoke $report
112             # save tempest.conf for further troubleshooting
113             tempest_conf="${RALLY_VENV_DIR}/tempest/for-deployment-*/tempest.conf"
114             if [ -f ${tempest_conf} ]; then
115                 cp $tempest_conf ${FUNCTEST_CONF_DIR}
116             fi
117         ;;
118         "vims")
119             echo "Running vIMS test..."
120             python ${FUNCTEST_REPO_DIR}/testcases/vIMS/CI/vIMS.py \
121                 $debug $clean_flag $report
122         ;;
123         "rally")
124             echo "Running Rally benchmark suite..."
125             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_rally-cert.py \
126                 $debug $clean_flag all $report
127
128         ;;
129         "bgpvpn")
130             echo "Running BGPVPN Tempest test case..."
131             pushd ${repos_dir}/bgpvpn/
132               pip install --no-deps -e .
133             popd
134             tempest_dir=$(ls -t /home/opnfv/.rally/tempest/ |grep for-deploy |tail -1)
135             if [[ $tempest_dir == "" ]]; then
136                 error "Make sure tempest was running before"
137             fi
138             tempest_dir=/home/opnfv/.rally/tempest/$tempest_dir
139             pushd $tempest_dir
140               mkdir -p /etc/tempest/
141               cp tempest.conf /etc/tempest/
142               echo "[service_available]
143 bgpvpn = True" >> /etc/tempest/tempest.conf
144               ./run_tempest.sh -t -N -- networking_bgpvpn_tempest
145               rm -rf /etc/tempest/tempest.conf
146             popd
147         ;;
148         "onos")
149             echo "Running ONOS test case..."
150             if [ $INSTALLER_TYPE == "joid" ]; then
151                 python ${FUNCTEST_REPO_DIR}/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py -i joid
152             else
153                 python ${FUNCTEST_REPO_DIR}/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py
154             fi
155       ;;
156         "promise")
157             echo "Running PROMISE test case..."
158             python ${FUNCTEST_REPO_DIR}/testcases/features/promise.py $debug $report
159             sleep 10 # to let the instances terminate
160         ;;
161         "doctor")
162             echo "Running Doctor test..."
163             python ${FUNCTEST_REPO_DIR}/testcases/features/doctor.py
164         ;;
165         "ovno")
166             echo "Running OpenContrail test..."
167             ${repos_dir}/ovno/Testcases/RunTests.sh
168         ;;
169     esac
170 }
171
172
173 # Parse parameters
174 while [[ $# > 0 ]]
175     do
176     key="$1"
177     case $key in
178         -h|--help)
179             echo "$usage"
180             exit 0
181             shift
182         ;;
183         -r|--report)
184             report="-r"
185         ;;
186         -s|--serial)
187             serial=true
188         ;;
189         -t|--test|--tests)
190             TEST="$2"
191             shift
192         ;;
193         *)
194             echo "unknown option $1 $2"
195             exit 1
196         ;;
197     esac
198     shift # past argument or value
199 done
200
201
202 # Source credentials
203 echo "Sourcing Credentials ${FUNCTEST_CONF_DIR}/openstack.creds to run the tests.."
204 source ${FUNCTEST_CONF_DIR}/openstack.creds
205
206
207 # Run test
208 run_test $TEST