Add openstack cleanup after running the tests
[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") [--offline] [-h|--help] [-t <test_name>]
14
15 where:
16     -o|--offline      optional offline mode (experimental)
17     -h|--help         show this help text
18     -r|--report       push results to database (false by default)
19     -t|--test         run specific set of tests
20       <test_name>     one or more of the following: vping,odl,rally,tempest,vims. Separated by comma.
21
22
23 examples:
24     $(basename "$0")
25     $(basename "$0") --test vping,odl
26     $(basename "$0") --offline -t tempest,rally"
27
28
29 # Support for Functest offline
30 # NOTE: Still not 100% working when running the tests
31 offline=false
32 report=""
33 arr_test=(vping odl tempest vims rally)
34
35 function clean_openstack(){
36     python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/clean_openstack.py \
37         --debug ${FUNCTEST_REPO_DIR}/
38 }
39
40 function run_test(){
41     test_name=$1
42     echo "----------------------------------------------"
43     echo "------------- Running $i test case  "
44     echo "----------------------------------------------"
45     case $test_name in
46         "vping")
47             info "Running vPing test..."
48             python ${FUNCTEST_REPO_DIR}/testcases/vPing/CI/libraries/vPing.py \
49                 --debug ${FUNCTEST_REPO_DIR}/ ${report}
50         ;;
51         "odl")
52             info "Running ODL test..."
53             if [ $INSTALLER_TYPE == "fuel" ]; then
54                 odl_ip=$(keystone catalog --service network | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
55                 neutron_ip=$(keystone catalog --service identity | grep publicURL | cut -f3 -d"/" | cut -f1 -d":")
56                 usr_name=$(env | grep OS | grep OS_USERNAME | cut -f2 -d'=')
57                 pass=$(env | grep OS | grep OS_PASSWORD | cut -f2 -d'=')
58                 odl_port=8181
59                 ODL_PORT=$odl_port ODL_IP=$odl_ip NEUTRON_IP=$neutron_ip USR_NAME=$usr_name PASS=$pass \
60                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/start_tests.sh
61             elif [ $INSTALLER_TYPE == "foreman" ]; then
62                 #odl_port=8081
63                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/start_tests.sh
64             elif [ $INSTALLER_TYPE == "apex" ]; then
65                 # TODO
66                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/start_tests.sh
67             elif [ $INSTALLER_TYPE == "joid" ]; then
68                 # TODO
69                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/start_tests.sh
70             elif [ $INSTALLER_TYPE == "compass" ]; then
71                 # TODO
72                 ${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/start_tests.sh
73             else
74                 error "INSTALLER_TYPE not valid."
75                 exit 1
76             fi
77             # save ODL results
78             odl_logs="${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/logs"
79             if [ -d ${odl_logs} ]; then
80                 cp -Rf  ${odl_logs} ${FUNCTEST_CONF_DIR}/ODL/
81             fi
82         ;;
83         "tempest")
84             info "Running Tempest smoke tests..."
85             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_tempest.py \
86                 --debug ${FUNCTEST_REPO_DIR}/ -m smoke ${report}
87             # save tempest.conf for further troubleshooting
88             tempest_conf="${RALLY_VENV_DIR}/tempest/for-deployment-*/tempest.conf"
89             if [ -f ${tempest_conf} ]; then
90                 cp $tempest_conf ${FUNCTEST_CONF_DIR}
91             fi
92             clean_openstack
93         ;;
94         "vims")
95             info "Running vIMS test..."
96             python ${FUNCTEST_REPO_DIR}/testcases/vIMS/CI/vIMS.py \
97                 --debug ${FUNCTEST_REPO_DIR}/ ${report}
98             clean_openstack
99         ;;
100         "rally")
101             info "Running Rally benchmark suite..."
102             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_rally.py \
103                 --debug ${FUNCTEST_REPO_DIR}/ all ${report}
104             clean_openstack
105         ;;
106         "bgpvpn_template")
107             info "Running BGPVPN Tempest test case..."
108             tempest_dir=$(find /root/.rally -type d -name for-deploy*)
109             # TODO:
110             # do the call of your test case here.
111             # the bgpvpn repo is cloned in $BGPVPN_REPO_DIR
112             # tempest is installed in $tempest_dir
113             # Suggestion:
114             #   mkdir ${tempest_dir}/tempest/api/bgpvpn/
115             #   cp ${BGPVPN_REPO_DIR}/networking_bgpvpn_tempest/<whatever you need> \
116             #       ${tempest_dir}/tempest/api/bgpvpn/
117             #   ${tempest_dir}/run_tempest.sh tempest.api.bgpvpn.<test_case_name>
118     esac
119 }
120
121
122 # Parse parameters
123 while [[ $# > 0 ]]
124     do
125     key="$1"
126     case $key in
127         -h|--help)
128             echo "$usage"
129             exit 0
130             shift
131         ;;
132         -o|--offline)
133             offline=true
134         ;;
135         -r|--report)
136             report="-r"
137         ;;
138         -t|--test|--tests)
139             TEST="$2"
140             shift
141         ;;
142         *)
143             echo "unknown option $1 $2"
144             exit 1
145         ;;
146     esac
147     shift # past argument or value
148 done
149
150 BASEDIR=`dirname $0`
151 source ${BASEDIR}/common.sh
152
153
154 # Check that the given tests are correct
155 if [ "${TEST}" != "" ]; then
156     arr_test_exec=(${TEST//,/ })
157     for i in "${arr_test_exec[@]}"; do
158         if [[ " ${arr_test[*]} " != *" $i "* ]]; then
159             error "Unknown test: $i. Available tests are: ${arr_test[@]}"
160         fi
161     done
162     info "Tests to execute: ${TEST}."
163 fi
164
165 if [ $offline == false ]; then
166     info "MODE: online"
167 else
168     info "MODE: offline"
169 fi
170
171 # Check that the functest environment has been installed
172 if [ ! -f ${FUNCTEST_CONF_DIR}/env_active ]; then
173     error "The Functest environment is not installed. \
174         Please run prepare_env.sh before running this script...."
175 fi
176
177
178 # Source credentials
179 info "Sourcing Credentials ${FUNCTEST_CONF_DIR}/openstack.creds to run the tests.."
180 source ${FUNCTEST_CONF_DIR}/openstack.creds
181
182
183 # Run tests
184 if [ "${TEST}" != "" ]; then
185     for i in "${arr_test_exec[@]}"; do
186         run_test $i
187     done
188 else
189     info "Executing all the tests"
190     for i in "${arr_test[@]}"; do
191         run_test $i
192     done
193 fi