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