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