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 =========="
132 wget http://download.cirros-cloud.net/0.3.3/cirros-0.3.3-x86_64-disk.img -O /tmp/cirros.img
134 output=$(glance image-create \
135 --name cirros-0.3.3 \
136 --disk-format qcow2 \
137 --container-format bare \
138 --file /tmp/cirros.img)
141 CIRROS_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
142 if [ -z "$CIRROS_IMAGE_ID" ]; then
143 echo 'Failed uploading cirros image to cloud'.
147 echo "Cirros image id: $CIRROS_IMAGE_ID"
150 load_yardstick_image()
153 echo "========== Loading yardstick cloud image =========="
155 output=$(glance --os-image-api-version 1 image-create \
156 --name yardstick-trusty-server \
157 --is-public true --disk-format qcow2 \
158 --container-format bare \
162 GLANCE_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
164 if [ -z "$GLANCE_IMAGE_ID" ]; then
165 echo 'Failed uploading image to cloud'.
169 sudo rm -f $QCOW_IMAGE
171 echo "Glance image id: $GLANCE_IMAGE_ID"
177 echo "========== Running yardstick test suites =========="
179 mkdir -p /etc/yardstick
181 cat << EOF >> /etc/yardstick/yardstick.conf
184 dispatcher = ${DISPATCHER_TYPE}
187 file_name = ${DISPATCHER_FILE_NAME}
191 target = ${DISPATCHER_HTTP_TARGET}
196 if [ ${#SUITE_FILES[@]} -gt 0 ]; then
198 for suite in ${SUITE_FILES[*]}; do
200 echo "---------------------------"
201 echo "Running test suite: $suite"
202 echo "---------------------------"
204 if ! yardstick task start --suite $suite; then
205 echo "test suite $suite FAILED";
207 # Mark the test suite failed but continue
208 # running the remaining test suites.
214 if [ $failed -gt 0 ]; then
216 echo "---------------------------"
217 echo "$failed out of ${SUITE_FILES[*]} test suites FAILED"
218 echo "---------------------------"
224 echo "---------------------------"
225 echo "Running samples/ping.yaml "
226 echo "---------------------------"
228 if ! yardstick task start samples/ping.yaml; then
229 echo "Yardstick test FAILED"
239 GITROOT=$(cd $(dirname $0) && git rev-parse --show-toplevel)
243 export YARDSTICK_VERSION=$(git rev-parse HEAD)
247 # find the test suite files
248 for suite in $TEST_SUITES; do
249 if [ -f $suite ]; then
250 SUITE_FILES+=($suite)
252 tsdir=$GITROOT/tests/opnfv/test_suites
253 if [ ! -f $tsdir/$suite ]; then
254 echo "Test suite \"$suite\" does not exist"
257 SUITE_FILES+=($tsdir/$suite)
262 echo "========== Running Yardstick CI with following parameters =========="
263 echo "Script options: ${SCRIPT} $SCRIPT_ARGS"
264 echo "Result API: ${DISPATCHER_HTTP_TARGET:-$DISPATCHER_FILE_NAME}"
265 echo "YARDSTICK_VERSION: ${YARDSTICK_VERSION}"
266 echo "Number of test suites: ${#SUITE_FILES[@]}"
267 for suite in ${SUITE_FILES[*]}; do
274 # check if some necessary variables is set
275 if [ -z "$OS_AUTH_URL" ]; then
276 echo "OS_AUTH_URL is unset or empty"
280 # check if the api is up
281 echo "Checking if OS API is working..."
282 if ! glance image-list > /dev/null; then
283 echo "OS API is down"
289 trap "error_exit" EXIT SIGTERM
291 QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-trusty-server.img"
293 build_yardstick_image