Merge "Bugfix Missing "$" in front of some variables"
[functest.git] / docker / run_tests.sh
1 #!/bin/bash
2
3 #
4 # Author: Jose Lausuch (jose.lausuch@ericsson.com)
5 #
6 # Installs the Functest framework within the Docker container
7 # and run the tests automatically
8 #
9
10 usage="Script to trigger the tests automatically.
11
12 usage:
13     bash $(basename "$0") [-h|--help] [-t <test_name>]
14
15 where:
16     -h|--help         show this help text
17     -r|--report       push results to database (false by default)
18     -t|--test         run specific set of tests
19       <test_name>     one or more of the following: vping,odl,rally,tempest,vims,onos,promise,ovno. Separated by comma.
20
21
22 examples:
23     $(basename "$0")
24     $(basename "$0") --test vping,odl
25     $(basename "$0") -t tempest,rally"
26
27
28 # Support for Functest offline
29 # NOTE: Still not 100% working when running the tests
30 offline=false
31 report=""
32 # Get the list of runnable tests
33 # Check if we are in CI mode
34
35
36 function clean_openstack(){
37     echo -e "\n\nCleaning Openstack environment..."
38     python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/clean_openstack.py \
39         --debug
40     echo -e "\n\n"
41 }
42
43 function run_test(){
44     test_name=$1
45     echo ""
46     echo "----------------------------------------------"
47     echo "  Running test cases: $i"
48     echo "----------------------------------------------"
49     echo ""
50     case $test_name in
51         "vping")
52             info "Running vPing test..."
53             python ${FUNCTEST_REPO_DIR}/testcases/vPing/CI/libraries/vPing.py \
54                 --debug ${report}
55         ;;
56         "odl")
57             info "Running ODL test..."
58             neutron_ip=$(keystone catalog --service identity | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
59             odl_ip=$(keystone catalog --service network | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
60             usr_name=$(env | grep OS | grep OS_USERNAME | cut -f2 -d'=')
61             password=$(env | grep OS | grep OS_PASSWORD | cut -f2 -d'=')
62             odl_port=8181
63             if [ $INSTALLER_TYPE == "fuel" ]; then
64                 odl_port=8282
65             elif [ $INSTALLER_TYPE == "apex" ]; then
66                 :
67             elif [ $INSTALLER_TYPE == "joid" ]; then
68                 :
69             elif [ $INSTALLER_TYPE == "compass" ]; then
70                 :
71             else
72                 error "INSTALLER_TYPE not valid."
73                 exit 1
74             fi
75             ODL_PORT=$odl_port ODL_IP=$odl_ip NEUTRON_IP=$neutron_ip USR_NAME=$usr_name PASS=$password \
76                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/start_tests.sh
77
78             # save ODL results
79             odl_logs="${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/logs"
80             if [ -d ${odl_logs} ]; then
81                 cp -Rf  ${odl_logs} ${FUNCTEST_CONF_DIR}/ODL/
82             fi
83         ;;
84         "tempest")
85             info "Running Tempest tests..."
86             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_tempest.py \
87                 --debug -m custom ${report}
88             # save tempest.conf for further troubleshooting
89             tempest_conf="${RALLY_VENV_DIR}/tempest/for-deployment-*/tempest.conf"
90             if [ -f ${tempest_conf} ]; then
91                 cp $tempest_conf ${FUNCTEST_CONF_DIR}
92             fi
93             clean_openstack
94         ;;
95         "vims")
96             info "Running vIMS test..."
97             python ${FUNCTEST_REPO_DIR}/testcases/vIMS/CI/vIMS.py \
98                 --debug ${report}
99             clean_openstack
100         ;;
101         "rally")
102             info "Running Rally benchmark suite..."
103             cinder type-create volume-test #provisional
104             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_rally.py \
105                 --debug all ${report}
106             cinder type-delete $(cinder type-list|grep test|awk '{print $2}')
107             clean_openstack
108
109         ;;
110         "bgpvpn_template")
111             info "Running BGPVPN Tempest test case..."
112             tempest_dir=$(find /root/.rally -type d -name for-deploy*)
113             # TODO:
114             # do the call of your test case here.
115             # the bgpvpn repo is cloned in $BGPVPN_REPO_DIR
116             # tempest is installed in $tempest_dir
117             # Suggestion:
118             #   mkdir ${tempest_dir}/tempest/api/bgpvpn/
119             #   cp ${BGPVPN_REPO_DIR}/networking_bgpvpn_tempest/<whatever you need> \
120             #       ${tempest_dir}/tempest/api/bgpvpn/
121             #   ${tempest_dir}/run_tempest.sh tempest.api.bgpvpn.<test_case_name>
122        ;;
123         "onos")
124             info "Running ONOS test case..."
125             python ${FUNCTEST_REPO_DIR}/testcases/Controllers/ONOS/Teston/CI/onosfunctest.py
126       ;;
127         "promise")
128             info "Running PROMISE test case..."
129             # TODO
130         ;;
131         "doctor")
132             info "Running Doctor test..."
133             python ${FUNCTEST_REPO_DIR}/testcases/features/doctor.py
134         ;;
135         "ovno")
136             info "Running OpenContrail test..."
137             # TODO
138         ;;
139     esac
140 }
141
142
143 # Parse parameters
144 while [[ $# > 0 ]]
145     do
146     key="$1"
147     case $key in
148         -h|--help)
149             echo "$usage"
150             exit 0
151             shift
152         ;;
153         -o|--offline)
154             offline=true
155         ;;
156         -r|--report)
157             report="-r"
158         ;;
159         -t|--test|--tests)
160             TEST="$2"
161             shift
162         ;;
163         *)
164             echo "unknown option $1 $2"
165             exit 1
166         ;;
167     esac
168     shift # past argument or value
169 done
170
171
172 tests_file="/home/opnfv/functest/conf/testcase-list.txt"
173 if [[ -n "$DEPLOY_SCENARIO" && "$DEPLOY_SCENARIO" != "none" ]] &&\
174    [[ -f $tests_file ]]; then
175     echo "testcase-list.txt content:";cat $test_file; echo ""
176     arr_test=($(cat $tests_file))
177 else
178     arr_test=(vping tempest vims rally)
179 fi
180 echo "arr_test: "${arr_test[@]}
181
182 BASEDIR=`dirname $0`
183 source ${BASEDIR}/common.sh
184
185
186 # Check that the given tests are correct
187 if [ "${TEST}" != "" ]; then
188     arr_test_exec=(${TEST//,/ })
189     for i in "${arr_test_exec[@]}"; do
190         if [[ " ${arr_test[*]} " != *" $i "* ]]; then
191             error "Unknown test: $i. Available tests are: ${arr_test[@]}"
192         fi
193     done
194     info "Tests to execute: ${TEST}."
195 fi
196
197 if [ $offline == false ]; then
198     info "MODE: online"
199 else
200     info "MODE: offline"
201 fi
202
203 # Check that the functest environment has been installed
204 if [ ! -f ${FUNCTEST_CONF_DIR}/env_active ]; then
205     error "The Functest environment is not installed. \
206         Please run prepare_env.sh before running this script...."
207 fi
208
209
210 # Source credentials
211 info "Sourcing Credentials ${FUNCTEST_CONF_DIR}/openstack.creds to run the tests.."
212 source ${FUNCTEST_CONF_DIR}/openstack.creds
213
214 # Run tests
215 if [ "${TEST}" != "" ]; then
216     for i in "${arr_test_exec[@]}"; do
217         run_test $i
218     done
219 else
220     info "Executing tests..."
221     for i in "${arr_test[@]}"; do
222         run_test $i
223     done
224 fi