2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB and others.
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 ##############################################################################
12 # Set up the environment and run yardstick test suites.
14 # Example invocation: yardstick-verify -r 10.4.4.4 suite1.yaml suite2.yaml
16 # Openstack credentials must be set and the script must be run from its
17 # original location in the yardstick repo.
19 # This script is intended to be used by the CI pipeline but it may also
20 # be invoked manually.
29 usage: $0 options [TEST_SUITE ...]
31 If no test suites are given ping.yaml is run.
35 -r Http target (example: -r 213.77.62.197/results)
36 -i Influxdb target (example: -i 127.0.0.1:8086)
38 Default target is dump to file ($DISPATCHER_FILE_NAME)
44 DISPATCHER_FILE_NAME="/tmp/yardstick.out"
45 DISPATCHER_HTTP_TARGET=
46 DISPATCHER_INFLUXDB_TARGET=
48 while getopts "r:i:h" OPTION; do
56 DISPATCHER_HTTP_TARGET=http://${OPTARG}
59 DISPATCHER_TYPE=influxdb
60 DISPATCHER_INFLUXDB_TARGET=http://${OPTARG}
63 echo "${OPTION} is not a valid argument"
75 echo "========== Cleanup =========="
77 if ! glance image-list; then
81 for image in $(glance image-list | grep -e cirros-0.3.3 -e yardstick-trusty-server | awk '{print $2}'); do
82 echo "Deleting image $image..."
83 glance image-delete $image || true
86 nova flavor-delete yardstick-flavor &> /dev/null || true
95 if [ -z "$exitcode" ]; then
96 # In case of recursive traps (!?)
102 echo "Exiting with RC=$exitcode"
113 echo "========== Installing yardstick =========="
115 if ! sudo python setup.py install; then
116 echo 'Yardstick installation failed!'
121 build_yardstick_image()
124 echo "========== Build yardstick cloud image =========="
126 sudo $(which yardstick-img-modify) $(pwd)/tools/ubuntu-server-cloudimg-modify.sh
127 if [ ! -f $QCOW_IMAGE ]; then
128 echo "Failed building QCOW image"
135 if ! nova flavor-list | grep -q yardstick-flavor; then
137 echo "========== Create nova flavor =========="
138 # Create the nova flavor used by some sample test cases
139 nova flavor-create yardstick-flavor 100 512 3 1
146 echo "========== Loading cirros cloud image =========="
148 local image_file=/home/opnfv/images/cirros-0.3.3-x86_64-disk.img
150 output=$(glance image-create \
151 --name cirros-0.3.3 \
152 --disk-format qcow2 \
153 --container-format bare \
157 CIRROS_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
158 if [ -z "$CIRROS_IMAGE_ID" ]; then
159 echo 'Failed uploading cirros image to cloud'.
163 echo "Cirros image id: $CIRROS_IMAGE_ID"
166 load_yardstick_image()
169 echo "========== Loading yardstick cloud image =========="
171 output=$(glance --os-image-api-version 1 image-create \
172 --name yardstick-trusty-server \
173 --is-public true --disk-format qcow2 \
174 --container-format bare \
178 GLANCE_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
180 if [ -z "$GLANCE_IMAGE_ID" ]; then
181 echo 'Failed uploading image to cloud'.
185 sudo rm -f $QCOW_IMAGE
187 echo "Glance image id: $GLANCE_IMAGE_ID"
193 echo "========== Running yardstick test suites =========="
195 mkdir -p /etc/yardstick
197 cat << EOF >> /etc/yardstick/yardstick.conf
200 dispatcher = ${DISPATCHER_TYPE}
203 file_name = ${DISPATCHER_FILE_NAME}
207 target = ${DISPATCHER_HTTP_TARGET}
209 [dispatcher_influxdb]
211 target = ${DISPATCHER_INFLUXDB_TARGET}
217 if [ ${#SUITE_FILES[@]} -gt 0 ]; then
219 for suite in ${SUITE_FILES[*]}; do
221 echo "---------------------------"
222 echo "Running test suite: $suite"
223 echo "---------------------------"
225 if ! yardstick task start --suite $suite; then
226 echo "test suite $suite FAILED";
228 # Mark the test suite failed but continue
229 # running the remaining test suites.
232 if [ ${DISPATCHER_TYPE} = file ]; then
233 echo "---------------------------"
234 echo "Dump test suite $suite result"
235 echo "---------------------------"
236 if [ -f ${DISPATCHER_FILE_NAME} ]; then
237 cat ${DISPATCHER_FILE_NAME}
239 echo "Test result file ${DISPATCHER_FILE_NAME} is not exist"
245 if [ $failed -gt 0 ]; then
247 echo "---------------------------"
248 echo "$failed out of ${SUITE_FILES[*]} test suites FAILED"
249 echo "---------------------------"
255 echo "---------------------------"
256 echo "Running samples/ping.yaml "
257 echo "---------------------------"
259 if ! yardstick task start samples/ping.yaml; then
260 echo "Yardstick test FAILED"
264 if [ ${DISPATCHER_TYPE} = file ]; then
265 echo "---------------------------"
266 echo "Dump samples/ping.yaml test result"
267 echo "---------------------------"
268 if [ -f ${DISPATCHER_FILE_NAME} ]; then
269 cat ${DISPATCHER_FILE_NAME}
271 echo "Test result file ${DISPATCHER_FILE_NAME} is not exist"
281 GITROOT=$(cd $(dirname $0) && git rev-parse --show-toplevel)
285 export YARDSTICK_VERSION=$(git rev-parse HEAD)
289 # find the test suite files
290 for suite in $TEST_SUITES; do
291 if [ -f $suite ]; then
292 SUITE_FILES+=($suite)
294 tsdir=$GITROOT/tests/opnfv/test_suites
295 if [ ! -f $tsdir/$suite ]; then
296 echo "Test suite \"$suite\" does not exist"
299 SUITE_FILES+=($tsdir/$suite)
304 echo "========== Running Yardstick CI with following parameters =========="
305 echo "Script options: ${SCRIPT} $SCRIPT_ARGS"
306 echo "Result API: ${DISPATCHER_HTTP_TARGET:-$DISPATCHER_FILE_NAME}"
307 echo "YARDSTICK_VERSION: ${YARDSTICK_VERSION}"
308 echo "Number of test suites: ${#SUITE_FILES[@]}"
309 for suite in ${SUITE_FILES[*]}; do
316 # check if some necessary variables is set
317 if [ -z "$OS_AUTH_URL" ]; then
318 echo "OS_AUTH_URL is unset or empty"
322 # check if the api is up
323 echo "Checking if OS API is working..."
324 if ! glance image-list > /dev/null; then
325 echo "OS API is down"
331 trap "error_exit" EXIT SIGTERM
333 QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-trusty-server.img"
335 build_yardstick_image