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}
60 DISPATCHER_TYPE=influxdb
61 DISPATCHER_INFLUXDB_TARGET=http://${OPTARG}
65 echo "${OPTION} is not a valid argument"
77 echo "========== Cleanup =========="
79 if ! glance image-list; then
83 for image in $(glance image-list | grep -e cirros-0.3.3 -e yardstick-trusty-server | awk '{print $2}'); do
84 echo "Deleting image $image..."
85 glance image-delete $image || true
88 nova flavor-delete yardstick-flavor &> /dev/null || true
97 if [ -z "$exitcode" ]; then
98 # In case of recursive traps (!?)
104 echo "Exiting with RC=$exitcode"
115 echo "========== Installing yardstick =========="
117 # uninstall previous version
118 pip uninstall -y yardstick || true
124 build_yardstick_image()
127 echo "========== Build yardstick cloud image =========="
129 local cmd="sudo $(which yardstick-img-modify) $(pwd)/tools/ubuntu-server-cloudimg-modify.sh"
131 # Build the image. Retry once if the build fails.
134 if [ ! -f $QCOW_IMAGE ]; then
135 echo "Failed building QCOW image"
142 if ! nova flavor-list | grep -q yardstick-flavor; then
144 echo "========== Create nova flavor =========="
145 # Create the nova flavor used by some sample test cases
146 nova flavor-create yardstick-flavor 100 512 3 1
153 echo "========== Loading cirros cloud image =========="
155 local image_file=/home/opnfv/images/cirros-0.3.3-x86_64-disk.img
157 output=$(glance image-create \
158 --name cirros-0.3.3 \
159 --disk-format qcow2 \
160 --container-format bare \
164 CIRROS_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
165 if [ -z "$CIRROS_IMAGE_ID" ]; then
166 echo 'Failed uploading cirros image to cloud'.
170 echo "Cirros image id: $CIRROS_IMAGE_ID"
173 load_yardstick_image()
176 echo "========== Loading yardstick cloud image =========="
178 output=$(glance --os-image-api-version 1 image-create \
179 --name yardstick-trusty-server \
180 --is-public true --disk-format qcow2 \
181 --container-format bare \
185 GLANCE_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
187 if [ -z "$GLANCE_IMAGE_ID" ]; then
188 echo 'Failed uploading image to cloud'.
192 sudo rm -f $QCOW_IMAGE
194 echo "Glance image id: $GLANCE_IMAGE_ID"
200 echo "========== Running yardstick test suites =========="
202 mkdir -p /etc/yardstick
204 cat << EOF >> /etc/yardstick/yardstick.conf
207 dispatcher = ${DISPATCHER_TYPE}
210 file_name = ${DISPATCHER_FILE_NAME}
214 target = ${DISPATCHER_HTTP_TARGET}
216 [dispatcher_influxdb]
218 target = ${DISPATCHER_INFLUXDB_TARGET}
226 if [ ${#SUITE_FILES[@]} -gt 0 ]; then
228 for suite in ${SUITE_FILES[*]}; do
230 echo "---------------------------"
231 echo "Running test suite: $suite"
232 echo "---------------------------"
234 if ! yardstick task start --suite $suite; then
235 echo "test suite $suite FAILED";
237 # Mark the test suite failed but continue
238 # running the remaining test suites.
241 if [ ${DISPATCHER_TYPE} = file ]; then
242 echo "---------------------------"
243 echo "Dump test suite $suite result"
244 echo "---------------------------"
245 if [ -f ${DISPATCHER_FILE_NAME} ]; then
246 cat ${DISPATCHER_FILE_NAME}
248 echo "Test result file ${DISPATCHER_FILE_NAME} is not exist"
254 if [ $failed -gt 0 ]; then
256 echo "---------------------------"
257 echo "$failed out of ${SUITE_FILES[*]} test suites FAILED"
258 echo "---------------------------"
264 echo "---------------------------"
265 echo "Running samples/ping.yaml "
266 echo "---------------------------"
268 if ! yardstick task start samples/ping.yaml; then
269 echo "Yardstick test FAILED"
273 if [ ${DISPATCHER_TYPE} = file ]; then
274 echo "---------------------------"
275 echo "Dump samples/ping.yaml test result"
276 echo "---------------------------"
277 if [ -f ${DISPATCHER_FILE_NAME} ]; then
278 cat ${DISPATCHER_FILE_NAME}
280 echo "Test result file ${DISPATCHER_FILE_NAME} is not exist"
290 GITROOT=$(cd $(dirname $0) && git rev-parse --show-toplevel)
294 export YARDSTICK_VERSION=$(git rev-parse HEAD)
298 # find the test suite files
299 for suite in $TEST_SUITES; do
300 if [ -f $suite ]; then
301 SUITE_FILES+=($suite)
303 tsdir=$GITROOT/tests/opnfv/test_suites
304 if [ ! -f $tsdir/$suite ]; then
305 echo "Test suite \"$suite\" does not exist"
308 SUITE_FILES+=($tsdir/$suite)
313 echo "========== Running Yardstick CI with following parameters =========="
314 echo "Script options: ${SCRIPT} $SCRIPT_ARGS"
315 echo "Dispatcher: ${DISPATCHER_TYPE} ${DISPATCHER_FILE_NAME}"
316 echo "YARDSTICK_VERSION: ${YARDSTICK_VERSION}"
317 echo "Number of test suites: ${#SUITE_FILES[@]}"
318 for suite in ${SUITE_FILES[*]}; do
323 # check if some necessary variables is set
324 if [ -z "$OS_AUTH_URL" ]; then
325 echo "OS_AUTH_URL is unset or empty"
329 echo "OS_AUTH_URL is $OS_AUTH_URL"
332 # check OpenStack services
333 echo "Checking OpenStack services:"
334 for cmd in "glance image-list" "nova list" "heat stack-list"; do
335 echo " checking ${cmd/%\ */} ..."
336 if ! $cmd >/dev/null; then
337 echo "error: command \"$cmd\" failed"
343 echo "Checking for External network:"
344 for net in $(neutron net-list --router:external -c name -f value); do
345 echo " external network: $net"
353 trap "error_exit" EXIT SIGTERM
355 QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-trusty-server.img"
357 build_yardstick_image