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="http://testresults.opnfv.org/test/api/v1/results"
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 -e Ubuntu-14.04 | 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
126 # Install Storper on huawei-pod1
127 if [ "$NODE_NAME" == "huawei-pod1" ]; then
129 echo "========== Installing storperf =========="
131 if ! yardstick -d plugin install plugin/CI/storperf.yaml; then
132 echo "Install storperf plugin FAILED";
141 # remove Storper from huawei-pod1
142 if [ "$NODE_NAME" == "huawei-pod1" ]; then
144 echo "========== Removing storperf =========="
146 if ! yardstick -d plugin remove plugin/CI/storperf.yaml; then
147 echo "Remove storperf plugin FAILED";
154 build_yardstick_image()
157 echo "========== Build yardstick cloud image =========="
159 local cmd="sudo $(which yardstick-img-modify) $(pwd)/tools/ubuntu-server-cloudimg-modify.sh"
161 # Build the image. Retry once if the build fails.
164 if [ ! -f $QCOW_IMAGE ]; then
165 echo "Failed building QCOW image"
172 if ! nova flavor-list | grep -q yardstick-flavor; then
174 echo "========== Create nova flavor =========="
175 # Create the nova flavor used by some sample test cases
176 nova flavor-create yardstick-flavor 100 512 3 1
177 # DPDK-enabled OVS requires guest memory to be backed by large pages
178 if [[ "$DEPLOY_SCENARIO" == *"-ovs-"* ]]; then
179 nova flavor-key yardstick-flavor set hw:mem_page_size=large
187 echo "========== Loading cirros cloud image =========="
189 local image_file=/home/opnfv/images/cirros-0.3.3-x86_64-disk.img
191 output=$(glance image-create \
192 --name cirros-0.3.3 \
193 --disk-format qcow2 \
194 --container-format bare \
198 CIRROS_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
199 if [ -z "$CIRROS_IMAGE_ID" ]; then
200 echo 'Failed uploading cirros image to cloud'.
204 echo "Cirros image id: $CIRROS_IMAGE_ID"
210 echo "========== Loading ubuntu cloud image =========="
212 local ubuntu_image_file=/home/opnfv/images/trusty-server-cloudimg-amd64-disk1.img
214 output=$(glance image-create \
215 --name Ubuntu-14.04 \
216 --disk-format qcow2 \
217 --container-format bare \
218 --file $ubuntu_image_file)
221 UBUNTU_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
223 if [ -z "$UBUNTU_IMAGE_ID" ]; then
224 echo 'Failed uploading UBUNTU image to cloud'.
228 echo "Ubuntu image id: $UBUNTU_IMAGE_ID"
231 load_yardstick_image()
234 echo "========== Loading yardstick cloud image =========="
236 output=$(glance --os-image-api-version 1 image-create \
237 --name yardstick-trusty-server \
238 --is-public true --disk-format qcow2 \
239 --container-format bare \
243 GLANCE_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
245 if [ -z "$GLANCE_IMAGE_ID" ]; then
246 echo 'Failed uploading image to cloud'.
250 sudo rm -f $QCOW_IMAGE
252 echo "Glance image id: $GLANCE_IMAGE_ID"
258 echo "========== Reporting Status =========="
260 curl -i -H 'content-type: application/json' -X POST -d \
261 "{\"project_name\": \"yardstick\",
262 \"case_name\": \"scenario_status\",
263 \"pod_name\":\"${NODE_NAME}\",
264 \"installer\":\"${INSTALLER_TYPE}\",
265 \"version\":\"${YARDSTICK_BRANCH}\",
266 \"scenario\":\"${DEPLOY_SCENARIO}\",
267 \"description\": \"yardstick ci scenario status\",
268 \"start_date\":\"$2\",
270 \"stop_date\":\"$3\",
272 ${DISPATCHER_HTTP_TARGET}
278 echo "========== Running yardstick test suites =========="
280 mkdir -p /etc/yardstick
282 cat << EOF >> /etc/yardstick/yardstick.conf
285 dispatcher = ${DISPATCHER_TYPE}
288 file_name = ${DISPATCHER_FILE_NAME}
292 target = ${DISPATCHER_HTTP_TARGET}
294 [dispatcher_influxdb]
296 target = ${DISPATCHER_INFLUXDB_TARGET}
306 if [ ${#SUITE_FILES[@]} -gt 0 ]; then
308 start_date=$(date '+%Y-%m-%d %H:%M:%S')
309 for suite in ${SUITE_FILES[*]}; do
311 echo "---------------------------"
312 echo "Running test suite: $suite"
313 echo "---------------------------"
314 if ! yardstick task start --suite $suite; then
315 echo "test suite $suite FAILED";
317 # Mark the test suite failed but continue
318 # running the remaining test suites.
321 if [ ${DISPATCHER_TYPE} = file ]; then
322 echo "---------------------------"
323 echo "Dump test suite $suite result"
324 echo "---------------------------"
325 if [ -f ${DISPATCHER_FILE_NAME} ]; then
326 cat ${DISPATCHER_FILE_NAME}
328 echo "Test result file ${DISPATCHER_FILE_NAME} is not exist"
332 stop_date=$(date '+%Y-%m-%d %H:%M:%S')
336 local scenario_status="SUCCESS"
338 if [ $failed -gt 0 ]; then
339 scenario_status="FAILED"
342 report $scenario_status $start_date $stop_date
344 if [ $failed -gt 0 ]; then
345 echo "---------------------------"
346 echo "$failed out of ${SUITE_FILES[*]} test suites FAILED"
347 echo "---------------------------"
353 echo "---------------------------"
354 echo "Running samples/ping.yaml "
355 echo "---------------------------"
357 if ! yardstick task start samples/ping.yaml; then
358 echo "Yardstick test FAILED"
362 if [ ${DISPATCHER_TYPE} = file ]; then
363 echo "---------------------------"
364 echo "Dump samples/ping.yaml test result"
365 echo "---------------------------"
366 if [ -f ${DISPATCHER_FILE_NAME} ]; then
367 cat ${DISPATCHER_FILE_NAME}
369 echo "Test result file ${DISPATCHER_FILE_NAME} is not exist"
379 GITROOT=$(cd $(dirname $0) && git rev-parse --show-toplevel)
383 export YARDSTICK_VERSION=$(git rev-parse HEAD)
387 # find the test suite files
388 for suite in $TEST_SUITES; do
389 if [ -f $suite ]; then
390 SUITE_FILES+=($suite)
392 tsdir=$GITROOT/tests/opnfv/test_suites
393 if [ ! -f $tsdir/$suite ]; then
394 echo "Test suite \"$suite\" does not exist"
397 SUITE_FILES+=($tsdir/$suite)
402 echo "========== Running Yardstick CI with following parameters =========="
403 echo "Script options: ${SCRIPT} $SCRIPT_ARGS"
404 echo "Dispatcher: ${DISPATCHER_TYPE} ${DISPATCHER_FILE_NAME}"
405 echo "YARDSTICK_VERSION: ${YARDSTICK_VERSION}"
406 echo "Number of test suites: ${#SUITE_FILES[@]}"
407 for suite in ${SUITE_FILES[*]}; do
412 # check if some necessary variables is set
413 if [ -z "$OS_AUTH_URL" ]; then
414 echo "OS_AUTH_URL is unset or empty"
418 echo "OS_AUTH_URL is $OS_AUTH_URL"
421 # check OpenStack services
422 echo "Checking OpenStack services:"
423 for cmd in "glance image-list" "nova list" "heat stack-list"; do
424 echo " checking ${cmd/%\ */} ..."
425 if ! $cmd >/dev/null; then
426 echo "error: command \"$cmd\" failed"
432 echo "Checking for External network:"
433 for net in $(neutron net-list --router:external True -c name -f value); do
434 echo " external network: $net"
442 trap "error_exit" EXIT SIGTERM
444 QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-trusty-server.img"
446 build_yardstick_image