Merge "add ppm into result of pktgen to make result clear"
[yardstick.git] / tests / ci / yardstick-verify
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 #
12 # Set up the environment and run yardstick test suites.
13 #
14 # Example invocation: yardstick-verify -r 10.4.4.4 suite1.yaml suite2.yaml
15 #
16 # Openstack credentials must be set and the script must be run from its
17 # original location in the yardstick repo.
18 #
19 # This script is intended to be used by the CI pipeline but it may also
20 # be invoked manually.
21 #
22
23 SCRIPT=$0
24 SCRIPT_ARGS=$@
25
26 usage()
27 {
28     cat << EOF
29 usage: $0 options [TEST_SUITE ...]
30
31 If no test suites are given ping.yaml is run.
32
33 OPTIONS:
34    -h      Show this message
35    -r      Http target (example: -r 213.77.62.197/results)
36    -i      Influxdb target (example: -i 127.0.0.1:8086)
37    -m      Reporting target (example: -m 213.77.62.197/results)
38
39            Default target is dump to file ($DISPATCHER_FILE_NAME)
40
41 EOF
42 }
43
44 DISPATCHER_TYPE=file
45 DISPATCHER_FILE_NAME="/tmp/yardstick.out"
46 DISPATCHER_HTTP_TARGET="http://testresults.opnfv.org/test/api/v1/results"
47 DISPATCHER_INFLUXDB_TARGET=
48 REPORTING_TARGET="${DISPATCHER_HTTP_TARGET}"
49
50 while getopts "r:i:m:h" OPTION; do
51     case $OPTION in
52         h)
53             usage
54             exit 0
55             ;;
56         r)
57             DISPATCHER_TYPE=http
58             DISPATCHER_HTTP_TARGET=http://${OPTARG}
59             DISPATCHER_FILE_NAME=
60             ;;
61         i)
62             DISPATCHER_TYPE=influxdb
63             DISPATCHER_INFLUXDB_TARGET=http://${OPTARG}
64             DISPATCHER_FILE_NAME=
65             ;;
66         m)
67             REPORTING_TARGET=http://${OPTARG}
68             ;;
69         *)
70             echo "${OPTION} is not a valid argument"
71             exit 1
72             ;;
73     esac
74 done
75
76 shift $[OPTIND - 1]
77 TEST_SUITES=$@
78
79 exitcode=""
80
81 error_exit()
82 {
83     local rc=$?
84
85     if [ -z "$exitcode" ]; then
86         # In case of recursive traps (!?)
87         exitcode=$rc
88     fi
89
90     cleanup
91
92     echo "Exiting with RC=$exitcode"
93
94     exit $exitcode
95 }
96
97 set -o errexit
98 set -o pipefail
99
100 install_storperf()
101 {
102     # Install Storper on huawei-pod1 and huawei-pod2
103     if [ "$NODE_NAME" == "huawei-pod1" -o "$NODE_NAME" == "huawei-pod2" ]; then
104         echo
105         echo "========== Installing storperf =========="
106
107         if ! yardstick -d plugin install plugin/CI/storperf.yaml; then
108             echo "Install storperf plugin FAILED";
109             exit 1
110         fi
111
112     fi
113 }
114
115 remove_storperf()
116 {
117     # remove Storper from huawei-pod1 and huawei-pod2
118     if [ "$NODE_NAME" == "huawei-pod1" -o "$NODE_NAME" == "huawei-pod2" ]; then
119         echo
120         echo "========== Removing storperf =========="
121
122         if ! yardstick -d plugin remove plugin/CI/storperf.yaml; then
123             echo "Remove storperf plugin FAILED";
124             exit 1
125         fi
126
127     fi
128 }
129
130 report(){
131
132     echo
133     echo "========== Reporting Status =========="
134     curl -i -H 'content-type: application/json' -X POST -d \
135         "{\"project_name\": \"yardstick\",
136           \"case_name\": \"scenario_status\",
137           \"pod_name\":\"${NODE_NAME}\",
138           \"installer\":\"${INSTALLER_TYPE}\",
139           \"version\":\"$(basename ${YARDSTICK_BRANCH})\",
140           \"scenario\":\"${DEPLOY_SCENARIO}\",
141           \"description\": \"yardstick ci scenario status\",
142           \"criteria\":\"${1}\",
143           \"start_date\":\"${2}\",
144           \"stop_date\":\"${3}\",
145           \"details\":\"\"}" \
146           "${REPORTING_TARGET}"
147 }
148
149 run_test()
150 {
151     echo
152     echo "========== Running yardstick test suites =========="
153
154     mkdir -p /etc/yardstick
155
156     cat << EOF > /etc/yardstick/yardstick.conf
157 [DEFAULT]
158 debug = False
159 dispatcher = ${DISPATCHER_TYPE}
160
161 [dispatcher_file]
162 file_name = ${DISPATCHER_FILE_NAME}
163
164 [dispatcher_http]
165 timeout = 5
166 target = ${DISPATCHER_HTTP_TARGET}
167
168 [dispatcher_influxdb]
169 timeout = 5
170 target = ${DISPATCHER_INFLUXDB_TARGET}
171 db_name = yardstick
172 username = opnfv
173 password = 0pnfv2015
174 EOF
175
176     local failed=0
177     local start_date
178     local stop_date
179
180     if [ ${#SUITE_FILES[@]} -gt 0 ]; then
181
182         start_date=$(date '+%Y-%m-%d %H:%M:%S')
183         for suite in ${SUITE_FILES[*]}; do
184
185             echo "---------------------------"
186             echo "Running test suite: $suite"
187             echo "---------------------------"
188             if ! yardstick task start --suite $suite; then
189                  echo "test suite $suite FAILED";
190
191                 # Mark the test suite failed but continue
192                 # running the remaining test suites.
193                 (( ++failed ))
194             fi
195             if [ ${DISPATCHER_TYPE} = file ]; then
196                 echo "---------------------------"
197                 echo "Dump test suite $suite result"
198                 echo "---------------------------"
199                 if [ -f ${DISPATCHER_FILE_NAME} ]; then
200                     cat ${DISPATCHER_FILE_NAME}
201                 else
202                     echo "Test result file ${DISPATCHER_FILE_NAME} is not exist"
203                 fi
204             fi
205         done
206         stop_date=$(date '+%Y-%m-%d %H:%M:%S')
207
208
209
210         local scenario_status="SUCCESS"
211
212         if [ $failed -gt 0 ]; then
213             scenario_status="FAILED"
214         fi
215
216         report "${scenario_status}" "${start_date}" "${stop_date}"
217
218         if [ $failed -gt 0 ]; then
219             echo "---------------------------"
220             echo "$failed out of ${SUITE_FILES[*]} test suites FAILED"
221             echo "---------------------------"
222             exit 1
223         fi
224
225     else
226
227         echo "---------------------------"
228         echo "Running samples/ping.yaml  "
229         echo "---------------------------"
230
231         if ! yardstick task start samples/ping.yaml; then
232             echo "Yardstick test FAILED"
233             exit 1
234         fi
235
236         if [ ${DISPATCHER_TYPE} = file ]; then
237             echo "---------------------------"
238             echo "Dump samples/ping.yaml test result"
239             echo "---------------------------"
240             if [ -f ${DISPATCHER_FILE_NAME} ]; then
241                 cat ${DISPATCHER_FILE_NAME}
242             else
243                 echo "Test result file ${DISPATCHER_FILE_NAME} is not exist"
244             fi
245         fi
246
247     fi
248
249 }
250
251 main()
252 {
253     GITROOT=$(cd $(dirname $0) && git rev-parse --show-toplevel)
254
255     cd $GITROOT
256
257     export YARDSTICK_VERSION=$(git rev-parse HEAD)
258
259     SUITE_FILES=()
260
261     # find the test suite files
262     for suite in $TEST_SUITES; do
263         if [ -f $suite ]; then
264             SUITE_FILES+=($suite)
265         else
266             tsdir=$GITROOT/tests/opnfv/test_suites
267             if [ ! -f $tsdir/$suite ]; then
268                 echo "Test suite \"$suite\" does not exist"
269                 exit 1
270             fi
271             SUITE_FILES+=($tsdir/$suite)
272         fi
273     done
274
275     echo
276     echo "========== Running Yardstick CI with following parameters =========="
277     echo "Script options: ${SCRIPT} $SCRIPT_ARGS"
278     echo "Dispatcher: ${DISPATCHER_TYPE} ${DISPATCHER_FILE_NAME}"
279     echo "YARDSTICK_VERSION: ${YARDSTICK_VERSION}"
280     echo "Number of test suites: ${#SUITE_FILES[@]}"
281     for suite in ${SUITE_FILES[*]}; do
282         echo "     $suite"
283     done
284     echo
285
286     # check if some necessary variables is set
287     if [ -z "$OS_AUTH_URL" ]; then
288         echo "OS_AUTH_URL is unset or empty"
289         exit 1
290     fi
291
292     echo "OS_AUTH_URL is $OS_AUTH_URL"
293     echo
294
295     # check OpenStack services
296     if [[ $OS_INSECURE ]] && [[ "$(echo $OS_INSECURE | tr '[:upper:]' '[:lower:]')" = "true" ]]; then
297         SECURE="--insecure"
298     else
299         SECURE=""
300     fi
301     echo "Checking OpenStack services:"
302     for cmd in "openstack ${SECURE} image list" "openstack ${SECURE} server list" "openstack ${SECURE} stack list"; do
303         echo "  checking ${cmd} ..."
304         if ! $cmd >/dev/null; then
305             echo "error: command \"$cmd\" failed"
306             exit 1
307         fi
308     done
309
310     echo
311     echo "Checking for External network:"
312     for net in $(openstack network list --external -c Name -f value); do
313         echo "  external network: $net"
314     done
315
316     source $YARDSTICK_REPO_DIR/tests/ci/clean_images.sh
317
318     trap "error_exit" EXIT SIGTERM
319
320     source $YARDSTICK_REPO_DIR/tests/ci/load_images.sh
321     install_storperf
322     run_test
323     remove_storperf
324 }
325
326 main