7c289719dc5ceb0ad251ec79ecc4e49e06ad9a13
[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. 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 rally tempest)
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             else
58                 error "INSTALLER_TYPE not valid."
59                 exit 1
60             fi
61             # save ODL results
62             odl_logs="${FUNCTEST_REPO_DIR}/testcases/Controllers/ODL/CI/logs"
63             if [ -d ${odl_logs} ]; then
64                 cp -Rf  ${odl_logs} ${FUNCTEST_CONF_DIR}/ODL/
65             fi
66         ;;
67         "rally")
68             info "Running Rally benchmark suite..."
69             python ${FUNCTEST_REPO_DIR}/testcases/VIM/OpenStack/CI/libraries/run_rally.py --debug ${FUNCTEST_REPO_DIR}/ all
70         ;;
71         "tempest")
72             info "Running Tempest smoke tests..."
73             rally verify start smoke
74             rally verify list
75             # save tempest.conf for further troubleshooting
76             tempest_conf="${RALLY_VENV_DIR}/tempest/for-deployment-*/tempest.conf"
77             if [ -f ${tempest_conf} ]; then
78                 cp $tempest_conf ${FUNCTEST_CONF_DIR}
79             fi
80         ;;
81     esac
82 }
83
84
85 # Parse parameters
86 while [[ $# > 0 ]]
87     do
88     key="$1"
89     case $key in
90         -h|--help)
91             echo "$usage"
92             exit 0
93             shift
94         ;;
95         -o|--offline)
96             offline=true
97         ;;
98         -t|--test|--tests)
99             TEST="$2"
100             shift
101         ;;
102         *)
103             echo "unknown option $1 $2"
104             exit 1
105         ;;
106     esac
107     shift # past argument or value
108 done
109
110 BASEDIR=`dirname $0`
111 source ${BASEDIR}/common.sh
112
113
114 # Check that the given tests are correct
115 if [ "${TEST}" != "" ]; then
116     arr_test_exec=(${TEST//,/ })
117     for i in "${arr_test_exec[@]}"; do
118         if [[ " ${arr_test[*]} " != *" $i "* ]]; then
119             error "Unknown test: $i. Available tests are: ${arr_test[@]}"
120         fi
121     done
122     info "Tests to execute: ${TEST}."
123 fi
124
125 if [ $offline == false ]; then
126     info "MODE: online"
127 else
128     info "MODE: offline"
129 fi
130
131 # Check that the functest environment has been installed
132 if [ ! -f ${FUNCTEST_CONF_DIR}/env_active ]; then
133     error "The Functest environment is not installed. \
134         Please run prepare_env.sh before running this script...."
135 fi
136
137
138 # Source credentials
139 info "Sourcing Credentials ${FUNCTEST_CONF_DIR}/openstack.creds to run the tests.."
140 source ${FUNCTEST_CONF_DIR}/openstack.creds
141
142
143 # Run tests
144 if [ "${TEST}" != "" ]; then
145     for i in "${arr_test_exec[@]}"; do
146         run_test $i
147     done
148 else
149     info "Executing all the tests"
150     for i in "${arr_test[@]}"; do
151         run_test $i
152     done
153 fi