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 IP address for Result API.
36 Default is to store the results to file ($DISPATCHER_FILE_NAME)
37 if this option is not present.
43 DISPATCHER_FILE_NAME="/tmp/yardstick.out"
44 DISPATCHER_HTTP_TARGET=
46 while getopts "r:h" OPTION; do
54 DISPATCHER_HTTP_TARGET=http://${OPTARG}/results
57 echo "${OPTION} is not a valid argument"
69 echo "========== Cleanup =========="
71 if ! glance image-list; then
75 for image in $(glance image-list | grep -e cirros-0.3.3 -e yardstick-trusty-server | awk '{print $2}'); do
76 echo "Deleting image $image..."
77 glance image-delete $image || true
87 if [ -z "$exitcode" ]; then
88 # In case of recursive traps (!?)
94 echo "Exiting with RC=$exitcode"
105 echo "========== Installing yardstick =========="
107 if ! sudo python setup.py install; then
108 echo 'Yardstick installation failed!'
113 build_yardstick_image()
116 echo "========== Build yardstick cloud image =========="
118 sudo $(which yardstick-img-modify) $(pwd)/tools/ubuntu-server-cloudimg-modify.sh
119 if [ ! -f $QCOW_IMAGE ]; then
120 echo "Failed building QCOW image"
128 echo "========== Loading cirros cloud image =========="
130 local image_file=/home/opnfv/images/cirros-0.3.3-x86_64-disk.img
132 output=$(glance image-create \
133 --name cirros-0.3.3 \
134 --disk-format qcow2 \
135 --container-format bare \
139 CIRROS_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
140 if [ -z "$CIRROS_IMAGE_ID" ]; then
141 echo 'Failed uploading cirros image to cloud'.
145 echo "Cirros image id: $CIRROS_IMAGE_ID"
148 load_yardstick_image()
151 echo "========== Loading yardstick cloud image =========="
153 output=$(glance --os-image-api-version 1 image-create \
154 --name yardstick-trusty-server \
155 --is-public true --disk-format qcow2 \
156 --container-format bare \
160 GLANCE_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
162 if [ -z "$GLANCE_IMAGE_ID" ]; then
163 echo 'Failed uploading image to cloud'.
167 sudo rm -f $QCOW_IMAGE
169 echo "Glance image id: $GLANCE_IMAGE_ID"
175 echo "========== Running yardstick test suites =========="
177 mkdir -p /etc/yardstick
179 cat << EOF >> /etc/yardstick/yardstick.conf
182 dispatcher = ${DISPATCHER_TYPE}
185 file_name = ${DISPATCHER_FILE_NAME}
189 target = ${DISPATCHER_HTTP_TARGET}
194 if [ ${#SUITE_FILES[@]} -gt 0 ]; then
196 for suite in ${SUITE_FILES[*]}; do
198 echo "---------------------------"
199 echo "Running test suite: $suite"
200 echo "---------------------------"
202 if ! yardstick task start --suite $suite; then
203 echo "test suite $suite FAILED";
205 # Mark the test suite failed but continue
206 # running the remaining test suites.
212 if [ $failed -gt 0 ]; then
214 echo "---------------------------"
215 echo "$failed out of ${SUITE_FILES[*]} test suites FAILED"
216 echo "---------------------------"
222 echo "---------------------------"
223 echo "Running samples/ping.yaml "
224 echo "---------------------------"
226 if ! yardstick task start samples/ping.yaml; then
227 echo "Yardstick test FAILED"
237 GITROOT=$(cd $(dirname $0) && git rev-parse --show-toplevel)
241 export YARDSTICK_VERSION=$(git rev-parse HEAD)
245 # find the test suite files
246 for suite in $TEST_SUITES; do
247 if [ -f $suite ]; then
248 SUITE_FILES+=($suite)
250 tsdir=$GITROOT/tests/opnfv/test_suites
251 if [ ! -f $tsdir/$suite ]; then
252 echo "Test suite \"$suite\" does not exist"
255 SUITE_FILES+=($tsdir/$suite)
260 echo "========== Running Yardstick CI with following parameters =========="
261 echo "Script options: ${SCRIPT} $SCRIPT_ARGS"
262 echo "Result API: ${DISPATCHER_HTTP_TARGET:-$DISPATCHER_FILE_NAME}"
263 echo "YARDSTICK_VERSION: ${YARDSTICK_VERSION}"
264 echo "Number of test suites: ${#SUITE_FILES[@]}"
265 for suite in ${SUITE_FILES[*]}; do
272 # check if some necessary variables is set
273 if [ -z "$OS_AUTH_URL" ]; then
274 echo "OS_AUTH_URL is unset or empty"
278 # check if the api is up
279 echo "Checking if OS API is working..."
280 if ! glance image-list > /dev/null; then
281 echo "OS API is down"
287 trap "error_exit" EXIT SIGTERM
289 QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-trusty-server.img"
291 build_yardstick_image