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