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