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
147 # DPDK-enabled OVS requires guest memory to be backed by large pages
148 if [[ "$DEPLOY_SCENARIO" == *"-ovs-"* ]]; then
149 nova flavor-key yardstick-flavor set hw:mem_page_size=large
157 echo "========== Loading cirros cloud image =========="
159 local image_file=/home/opnfv/images/cirros-0.3.3-x86_64-disk.img
161 output=$(glance image-create \
162 --name cirros-0.3.3 \
163 --disk-format qcow2 \
164 --container-format bare \
168 CIRROS_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
169 if [ -z "$CIRROS_IMAGE_ID" ]; then
170 echo 'Failed uploading cirros image to cloud'.
174 echo "Cirros image id: $CIRROS_IMAGE_ID"
177 load_yardstick_image()
180 echo "========== Loading yardstick cloud image =========="
182 output=$(glance --os-image-api-version 1 image-create \
183 --name yardstick-trusty-server \
184 --is-public true --disk-format qcow2 \
185 --container-format bare \
189 GLANCE_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
191 if [ -z "$GLANCE_IMAGE_ID" ]; then
192 echo 'Failed uploading image to cloud'.
196 sudo rm -f $QCOW_IMAGE
198 echo "Glance image id: $GLANCE_IMAGE_ID"
204 echo "========== Running yardstick test suites =========="
206 mkdir -p /etc/yardstick
208 cat << EOF >> /etc/yardstick/yardstick.conf
211 dispatcher = ${DISPATCHER_TYPE}
214 file_name = ${DISPATCHER_FILE_NAME}
218 target = ${DISPATCHER_HTTP_TARGET}
220 [dispatcher_influxdb]
222 target = ${DISPATCHER_INFLUXDB_TARGET}
230 if [ ${#SUITE_FILES[@]} -gt 0 ]; then
232 for suite in ${SUITE_FILES[*]}; do
234 echo "---------------------------"
235 echo "Running test suite: $suite"
236 echo "---------------------------"
238 if ! yardstick task start --suite $suite; then
239 echo "test suite $suite FAILED";
241 # Mark the test suite failed but continue
242 # running the remaining test suites.
245 if [ ${DISPATCHER_TYPE} = file ]; then
246 echo "---------------------------"
247 echo "Dump test suite $suite result"
248 echo "---------------------------"
249 if [ -f ${DISPATCHER_FILE_NAME} ]; then
250 cat ${DISPATCHER_FILE_NAME}
252 echo "Test result file ${DISPATCHER_FILE_NAME} is not exist"
258 if [ $failed -gt 0 ]; then
260 echo "---------------------------"
261 echo "$failed out of ${SUITE_FILES[*]} test suites FAILED"
262 echo "---------------------------"
268 echo "---------------------------"
269 echo "Running samples/ping.yaml "
270 echo "---------------------------"
272 if ! yardstick task start samples/ping.yaml; then
273 echo "Yardstick test FAILED"
277 if [ ${DISPATCHER_TYPE} = file ]; then
278 echo "---------------------------"
279 echo "Dump samples/ping.yaml test result"
280 echo "---------------------------"
281 if [ -f ${DISPATCHER_FILE_NAME} ]; then
282 cat ${DISPATCHER_FILE_NAME}
284 echo "Test result file ${DISPATCHER_FILE_NAME} is not exist"
294 GITROOT=$(cd $(dirname $0) && git rev-parse --show-toplevel)
298 export YARDSTICK_VERSION=$(git rev-parse HEAD)
302 # find the test suite files
303 for suite in $TEST_SUITES; do
304 if [ -f $suite ]; then
305 SUITE_FILES+=($suite)
307 tsdir=$GITROOT/tests/opnfv/test_suites
308 if [ ! -f $tsdir/$suite ]; then
309 echo "Test suite \"$suite\" does not exist"
312 SUITE_FILES+=($tsdir/$suite)
317 echo "========== Running Yardstick CI with following parameters =========="
318 echo "Script options: ${SCRIPT} $SCRIPT_ARGS"
319 echo "Dispatcher: ${DISPATCHER_TYPE} ${DISPATCHER_FILE_NAME}"
320 echo "YARDSTICK_VERSION: ${YARDSTICK_VERSION}"
321 echo "Number of test suites: ${#SUITE_FILES[@]}"
322 for suite in ${SUITE_FILES[*]}; do
327 # check if some necessary variables is set
328 if [ -z "$OS_AUTH_URL" ]; then
329 echo "OS_AUTH_URL is unset or empty"
333 echo "OS_AUTH_URL is $OS_AUTH_URL"
336 # check OpenStack services
337 echo "Checking OpenStack services:"
338 for cmd in "glance image-list" "nova list" "heat stack-list"; do
339 echo " checking ${cmd/%\ */} ..."
340 if ! $cmd >/dev/null; then
341 echo "error: command \"$cmd\" failed"
347 echo "Checking for External network:"
348 for net in $(neutron net-list --router:external True -c name -f value); do
349 echo " external network: $net"
357 trap "error_exit" EXIT SIGTERM
359 QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-trusty-server.img"
361 build_yardstick_image