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
80 nova flavor-delete yardstick-flavor &> /dev/null || true
89 if [ -z "$exitcode" ]; then
90 # In case of recursive traps (!?)
96 echo "Exiting with RC=$exitcode"
107 echo "========== Installing yardstick =========="
109 if ! sudo python setup.py install; then
110 echo 'Yardstick installation failed!'
115 build_yardstick_image()
118 echo "========== Build yardstick cloud image =========="
120 sudo $(which yardstick-img-modify) $(pwd)/tools/ubuntu-server-cloudimg-modify.sh
121 if [ ! -f $QCOW_IMAGE ]; then
122 echo "Failed building QCOW image"
129 if ! nova flavor-list | grep -q yardstick-flavor; then
131 echo "========== Create nova flavor =========="
132 # Create the nova flavor used by some sample test cases
133 nova flavor-create yardstick-flavor 100 512 3 1
140 echo "========== Loading cirros cloud image =========="
142 local image_file=/home/opnfv/images/cirros-0.3.3-x86_64-disk.img
144 output=$(glance image-create \
145 --name cirros-0.3.3 \
146 --disk-format qcow2 \
147 --container-format bare \
151 CIRROS_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
152 if [ -z "$CIRROS_IMAGE_ID" ]; then
153 echo 'Failed uploading cirros image to cloud'.
157 echo "Cirros image id: $CIRROS_IMAGE_ID"
160 load_yardstick_image()
163 echo "========== Loading yardstick cloud image =========="
165 output=$(glance --os-image-api-version 1 image-create \
166 --name yardstick-trusty-server \
167 --is-public true --disk-format qcow2 \
168 --container-format bare \
172 GLANCE_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
174 if [ -z "$GLANCE_IMAGE_ID" ]; then
175 echo 'Failed uploading image to cloud'.
179 sudo rm -f $QCOW_IMAGE
181 echo "Glance image id: $GLANCE_IMAGE_ID"
187 echo "========== Running yardstick test suites =========="
189 mkdir -p /etc/yardstick
191 cat << EOF >> /etc/yardstick/yardstick.conf
194 dispatcher = ${DISPATCHER_TYPE}
197 file_name = ${DISPATCHER_FILE_NAME}
201 target = ${DISPATCHER_HTTP_TARGET}
206 if [ ${#SUITE_FILES[@]} -gt 0 ]; then
208 for suite in ${SUITE_FILES[*]}; do
210 echo "---------------------------"
211 echo "Running test suite: $suite"
212 echo "---------------------------"
214 if ! yardstick task start --suite $suite; then
215 echo "test suite $suite FAILED";
217 # Mark the test suite failed but continue
218 # running the remaining test suites.
224 if [ $failed -gt 0 ]; then
226 echo "---------------------------"
227 echo "$failed out of ${SUITE_FILES[*]} test suites FAILED"
228 echo "---------------------------"
234 echo "---------------------------"
235 echo "Running samples/ping.yaml "
236 echo "---------------------------"
238 if ! yardstick task start samples/ping.yaml; then
239 echo "Yardstick test FAILED"
249 GITROOT=$(cd $(dirname $0) && git rev-parse --show-toplevel)
253 export YARDSTICK_VERSION=$(git rev-parse HEAD)
257 # find the test suite files
258 for suite in $TEST_SUITES; do
259 if [ -f $suite ]; then
260 SUITE_FILES+=($suite)
262 tsdir=$GITROOT/tests/opnfv/test_suites
263 if [ ! -f $tsdir/$suite ]; then
264 echo "Test suite \"$suite\" does not exist"
267 SUITE_FILES+=($tsdir/$suite)
272 echo "========== Running Yardstick CI with following parameters =========="
273 echo "Script options: ${SCRIPT} $SCRIPT_ARGS"
274 echo "Result API: ${DISPATCHER_HTTP_TARGET:-$DISPATCHER_FILE_NAME}"
275 echo "YARDSTICK_VERSION: ${YARDSTICK_VERSION}"
276 echo "Number of test suites: ${#SUITE_FILES[@]}"
277 for suite in ${SUITE_FILES[*]}; do
284 # check if some necessary variables is set
285 if [ -z "$OS_AUTH_URL" ]; then
286 echo "OS_AUTH_URL is unset or empty"
290 # check if the api is up
291 echo "Checking if OS API is working..."
292 if ! glance image-list > /dev/null; then
293 echo "OS API is down"
299 trap "error_exit" EXIT SIGTERM
301 QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-trusty-server.img"
303 build_yardstick_image