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=
47 UCA_HOST="cloud-images.ubuntu.com"
48 if [ $YARD_IMG_ARCH = "arm64" ]; then
49 export VIVID_IMG_URL="http://${UCA_HOST}/vivid/current/vivid-server-cloudimg-arm64.tar.gz"
50 if ! grep -q "Defaults env_keep += \"VIVID_IMG_URL\"" "/etc/sudoers"; then
51 sudo echo "Defaults env_keep += \"VIVID_IMG_URL\"" >> /etc/sudoers
54 while getopts "r:i:h" OPTION; do
62 DISPATCHER_HTTP_TARGET=http://${OPTARG}
66 DISPATCHER_TYPE=influxdb
67 DISPATCHER_INFLUXDB_TARGET=http://${OPTARG}
71 echo "${OPTION} is not a valid argument"
83 echo "========== Cleanup =========="
85 if ! glance image-list; then
89 for image in $(glance image-list | grep -e cirros-0.3.3 -e yardstick-trusty-server -e Ubuntu-14.04 \
90 -e yardstick-vivid-kernel | awk '{print $2}'); do
91 echo "Deleting image $image..."
92 glance image-delete $image || true
95 nova flavor-delete yardstick-flavor &> /dev/null || true
104 if [ -z "$exitcode" ]; then
105 # In case of recursive traps (!?)
111 echo "Exiting with RC=$exitcode"
122 echo "========== Installing yardstick =========="
124 # uninstall previous version
125 pip uninstall -y yardstick || true
133 # Install Storper on huawei-pod1
134 if [ "$NODE_NAME" == "huawei-pod1" ]; then
136 echo "========== Installing storperf =========="
138 if ! yardstick -d plugin install plugin/CI/storperf.yaml; then
139 echo "Install storperf plugin FAILED";
148 # remove Storper from huawei-pod1
149 if [ "$NODE_NAME" == "huawei-pod1" ]; then
151 echo "========== Removing storperf =========="
153 if ! yardstick -d plugin remove plugin/CI/storperf.yaml; then
154 echo "Remove storperf plugin FAILED";
161 build_yardstick_image()
164 echo "========== Build yardstick cloud image =========="
166 local cmd="sudo $(which yardstick-img-modify) $(pwd)/tools/ubuntu-server-cloudimg-modify.sh"
168 # Build the image. Retry once if the build fails.
171 if [ ! -f $QCOW_IMAGE ]; then
172 echo "Failed building QCOW image"
179 if ! nova flavor-list | grep -q yardstick-flavor; then
181 echo "========== Create nova flavor =========="
182 # Create the nova flavor used by some sample test cases
183 nova flavor-create yardstick-flavor 100 512 3 1
184 # DPDK-enabled OVS requires guest memory to be backed by large pages
185 if [[ "$DEPLOY_SCENARIO" == *"-ovs-"* ]]; then
186 nova flavor-key yardstick-flavor set hw:mem_page_size=large
194 echo "========== Loading cirros cloud image =========="
196 local image_file=/home/opnfv/images/cirros-0.3.3-x86_64-disk.img
198 output=$(glance image-create \
199 --name cirros-0.3.3 \
200 --disk-format $DISK_FORMAT \
201 --container-format bare \
205 CIRROS_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
206 if [ -z "$CIRROS_IMAGE_ID" ]; then
207 echo 'Failed uploading cirros image to cloud'.
211 echo "Cirros image id: $CIRROS_IMAGE_ID"
217 echo "========== Loading ubuntu cloud image =========="
219 local ubuntu_image_file=/home/opnfv/images/trusty-server-cloudimg-amd64-disk1.img
221 output=$(glance image-create \
222 --name Ubuntu-14.04 \
223 --disk-format qcow2 \
224 --container-format bare \
225 --file $ubuntu_image_file)
228 UBUNTU_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
230 if [ -z "$UBUNTU_IMAGE_ID" ]; then
231 echo 'Failed uploading UBUNTU image to cloud'.
235 echo "Ubuntu image id: $UBUNTU_IMAGE_ID"
238 load_yardstick_image()
241 echo "========== Loading yardstick cloud image =========="
243 if [ $YARD_IMG_ARCH = "arm64" ]; then
244 VIVID_IMAGE="/tmp/vivid-server-cloudimg-arm64.tar.gz"
245 VIVID_KERNEL="/tmp/vivid-server-cloudimg-arm64-vmlinuz-generic"
247 if [ ! -f $VIVID_IMAGE ]; then
250 if [ ! -f $VIVID_KERNEL ]; then
251 tar zxf $VIVID_IMAGE $(basename $VIVID_KERNEL)
253 create_vivid_kernel=$(glance --os-image-api-version 1 image-create \
254 --name yardstick-vivid-kernel \
255 --is-public true --disk-format qcow2 \
256 --container-format bare \
257 --file $VIVID_KERNEL)
259 GLANCE_KERNEL_ID=$(echo "$create_vivid_kernel" | grep " id " | awk '{print $(NF-1)}')
260 if [ -z "$GLANCE_KERNEL_ID" ]; then
261 echo 'Failed uploading kernel to cloud'.
265 command_line="root=/dev/vdb1 console=tty0 console=ttyS0 console=ttyAMA0 rw"
267 EXTRA_PARAMS="--property kernel_id=$GLANCE_KERNEL_ID --property os_command_line=\"$command_line\""
269 rm -f $VIVID_KERNEL $VIVID_IMAGE
270 cd $YARDSTICK_REPO_DIR
273 output=$(eval glance --os-image-api-version 1 image-create \
274 --name yardstick-trusty-server \
275 --is-public true --disk-format $DISK_FORMAT \
276 --container-format bare \
282 GLANCE_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
284 if [ -z "$GLANCE_IMAGE_ID" ]; then
285 echo 'Failed uploading image to cloud'.
289 sudo rm -f $QCOW_IMAGE
291 echo "Glance image id: $GLANCE_IMAGE_ID"
297 echo "========== Reporting Status =========="
298 curl -i -H 'content-type: application/json' -X POST -d \
299 "{\"project_name\": \"yardstick\",
300 \"case_name\": \"scenario_status\",
301 \"pod_name\":\"${NODE_NAME}\",
302 \"installer\":\"${INSTALLER_TYPE}\",
303 \"version\":\"$(basename ${YARDSTICK_BRANCH})\",
304 \"scenario\":\"${DEPLOY_SCENARIO}\",
305 \"description\": \"yardstick ci scenario status\",
307 \"start_date\":\"$2\",
308 \"stop_date\":\"$3\",
310 ${DISPATCHER_HTTP_TARGET}
316 echo "========== Running yardstick test suites =========="
318 mkdir -p /etc/yardstick
320 cat << EOF >> /etc/yardstick/yardstick.conf
323 dispatcher = ${DISPATCHER_TYPE}
326 file_name = ${DISPATCHER_FILE_NAME}
330 target = ${DISPATCHER_HTTP_TARGET}
332 [dispatcher_influxdb]
334 target = ${DISPATCHER_INFLUXDB_TARGET}
344 if [ ${#SUITE_FILES[@]} -gt 0 ]; then
346 start_date=$(date '+%Y-%m-%d %H:%M:%S')
347 for suite in ${SUITE_FILES[*]}; do
349 echo "---------------------------"
350 echo "Running test suite: $suite"
351 echo "---------------------------"
352 if ! yardstick task start --suite $suite; then
353 echo "test suite $suite FAILED";
355 # Mark the test suite failed but continue
356 # running the remaining test suites.
359 if [ ${DISPATCHER_TYPE} = file ]; then
360 echo "---------------------------"
361 echo "Dump test suite $suite result"
362 echo "---------------------------"
363 if [ -f ${DISPATCHER_FILE_NAME} ]; then
364 cat ${DISPATCHER_FILE_NAME}
366 echo "Test result file ${DISPATCHER_FILE_NAME} is not exist"
370 stop_date=$(date '+%Y-%m-%d %H:%M:%S')
374 local scenario_status="SUCCESS"
376 if [ $failed -gt 0 ]; then
377 scenario_status="FAILED"
380 report $scenario_status $start_date $stop_date
382 if [ $failed -gt 0 ]; then
383 echo "---------------------------"
384 echo "$failed out of ${SUITE_FILES[*]} test suites FAILED"
385 echo "---------------------------"
391 echo "---------------------------"
392 echo "Running samples/ping.yaml "
393 echo "---------------------------"
395 if ! yardstick task start samples/ping.yaml; then
396 echo "Yardstick test FAILED"
400 if [ ${DISPATCHER_TYPE} = file ]; then
401 echo "---------------------------"
402 echo "Dump samples/ping.yaml test result"
403 echo "---------------------------"
404 if [ -f ${DISPATCHER_FILE_NAME} ]; then
405 cat ${DISPATCHER_FILE_NAME}
407 echo "Test result file ${DISPATCHER_FILE_NAME} is not exist"
417 GITROOT=$(cd $(dirname $0) && git rev-parse --show-toplevel)
421 export YARDSTICK_VERSION=$(git rev-parse HEAD)
425 # find the test suite files
426 for suite in $TEST_SUITES; do
427 if [ -f $suite ]; then
428 SUITE_FILES+=($suite)
430 tsdir=$GITROOT/tests/opnfv/test_suites
431 if [ ! -f $tsdir/$suite ]; then
432 echo "Test suite \"$suite\" does not exist"
435 SUITE_FILES+=($tsdir/$suite)
440 echo "========== Running Yardstick CI with following parameters =========="
441 echo "Script options: ${SCRIPT} $SCRIPT_ARGS"
442 echo "Dispatcher: ${DISPATCHER_TYPE} ${DISPATCHER_FILE_NAME}"
443 echo "YARDSTICK_VERSION: ${YARDSTICK_VERSION}"
444 echo "Number of test suites: ${#SUITE_FILES[@]}"
445 for suite in ${SUITE_FILES[*]}; do
450 # check if some necessary variables is set
451 if [ -z "$OS_AUTH_URL" ]; then
452 echo "OS_AUTH_URL is unset or empty"
456 echo "OS_AUTH_URL is $OS_AUTH_URL"
459 # check OpenStack services
460 echo "Checking OpenStack services:"
461 for cmd in "glance image-list" "nova list" "heat stack-list"; do
462 echo " checking ${cmd/%\ */} ..."
463 if ! $cmd >/dev/null; then
464 echo "error: command \"$cmd\" failed"
470 echo "Checking for External network:"
471 for net in $(neutron net-list --router:external True -c name -f value); do
472 echo " external network: $net"
480 trap "error_exit" EXIT SIGTERM
482 QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-trusty-server.img"
484 if [ "$DEPLOY_SCENARIO" == "os-nosdn-lxd-ha" -o "$DEPLOY_SCENARIO" == "os-nosdn-lxd-noha" ]; then
490 build_yardstick_image
492 if [ $YARD_IMG_ARCH = "arm64" ]; then
493 sed -i 's/image: cirros-0.3.3/image: TestVM/g' tests/opnfv/test_cases/opnfv_yardstick_tc002.yaml \
495 #We have overlapping IP with the real network
496 for filename in tests/opnfv/test_cases/*; do
497 sed -i "s/cidr: '10.0.1.0\/24'/cidr: '10.3.1.0\/24'/g" $filename