Update info file
[yardstick.git] / ci / yardstick-verify
index 15ea022..c7b1cef 100755 (executable)
@@ -8,10 +8,68 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 
-YARDSTICK_IMAGE_ID=
-CIRROS_IMAGE_ID=
+#
+# Set up the environment and run yardstick test suites.
+#
+# Example invocation: yardstick-verify -r 10.4.4.4 suite1.yaml suite2.yaml
+#
+# Openstack credentials must be set and the script must be run from its
+# original location in the yardstick repo.
+#
+# This script is intended to be used by the CI pipeline but it may also
+# be invoked manually.
+#
+
+SCRIPT=$0
+SCRIPT_ARGS=$@
 
-QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-trusty-server.img"
+usage()
+{
+    cat << EOF
+usage: $0 options [TEST_SUITE ...]
+
+If no test suites are given ping.yaml is run.
+
+OPTIONS:
+   -h      Show this message
+   -r      Http target (example: -r 213.77.62.197/results)
+   -i      Influxdb target (example: -i 127.0.0.1:8086)
+
+           Default target is dump to file ($DISPATCHER_FILE_NAME)
+
+EOF
+}
+
+DISPATCHER_TYPE=file
+DISPATCHER_FILE_NAME="/tmp/yardstick.out"
+DISPATCHER_HTTP_TARGET=
+DISPATCHER_INFLUXDB_TARGET=
+
+while getopts "r:i:h" OPTION; do
+    case $OPTION in
+        h)
+            usage
+            exit 0
+            ;;
+        r)
+            DISPATCHER_TYPE=http
+            DISPATCHER_HTTP_TARGET=http://${OPTARG}
+            DISPATCHER_FILE_NAME=
+            ;;
+        i)
+            DISPATCHER_TYPE=influxdb
+            DISPATCHER_INFLUXDB_TARGET=http://${OPTARG}
+            DISPATCHER_FILE_NAME=
+            ;;
+        *)
+            echo "${OPTION} is not a valid argument"
+            exit 1
+            ;;
+    esac
+done
+
+shift $[OPTIND - 1]
+TEST_SUITES=$@
 
 cleanup()
 {
@@ -26,6 +84,8 @@ cleanup()
         echo "Deleting image $image..."
         glance image-delete $image || true
     done
+
+    nova flavor-delete yardstick-flavor &> /dev/null || true
 }
 
 exitcode=""
@@ -54,10 +114,11 @@ install_yardstick()
     echo
     echo "========== Installing yardstick =========="
 
-    if ! sudo python setup.py install; then
-        echo 'Yardstick installation failed!'
-        exit 1
-    fi
+    # uninstall previous version
+    pip uninstall -y yardstick || true
+
+    # Install yardstick
+    pip install .
 }
 
 build_yardstick_image()
@@ -65,27 +126,39 @@ build_yardstick_image()
     echo
     echo "========== Build yardstick cloud image =========="
 
-    sudo $(which yardstick-img-modify) $(pwd)/tools/ubuntu-server-cloudimg-modify.sh
+    local cmd="sudo $(which yardstick-img-modify) $(pwd)/tools/ubuntu-server-cloudimg-modify.sh"
+
+    # Build the image. Retry once if the build fails.
+    $cmd || $cmd
+
     if [ ! -f $QCOW_IMAGE ]; then
         echo "Failed building QCOW image"
         exit 1
     fi
 }
 
+create_nova_flavor()
+{
+    if ! nova flavor-list | grep -q yardstick-flavor; then
+        echo
+        echo "========== Create nova flavor =========="
+        # Create the nova flavor used by some sample test cases
+        nova flavor-create yardstick-flavor 100 512 3 1
+    fi
+}
+
 load_cirros_image()
 {
     echo
     echo "========== Loading cirros cloud image =========="
 
-    local image_file=
-
-    wget http://download.cirros-cloud.net/0.3.3/cirros-0.3.3-x86_64-disk.img -O /tmp/cirros.img
+    local image_file=/home/opnfv/images/cirros-0.3.3-x86_64-disk.img
 
     output=$(glance image-create \
         --name  cirros-0.3.3 \
         --disk-format qcow2 \
         --container-format bare \
-        --file /tmp/cirros.img)
+        --file $image_file)
     echo "$output"
 
     CIRROS_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
@@ -124,13 +197,92 @@ load_yardstick_image()
 run_test()
 {
     echo
-    echo "========== Running yardstick test suite =========="
+    echo "========== Running yardstick test suites =========="
+
+    mkdir -p /etc/yardstick
+
+    cat << EOF >> /etc/yardstick/yardstick.conf
+[DEFAULT]
+debug = True
+dispatcher = ${DISPATCHER_TYPE}
+
+[dispatcher_file]
+file_name = ${DISPATCHER_FILE_NAME}
+
+[dispatcher_http]
+timeout = 5
+target = ${DISPATCHER_HTTP_TARGET}
+
+[dispatcher_influxdb]
+timeout = 5
+target = ${DISPATCHER_INFLUXDB_TARGET}
+db_name = yardstick
+username = opnfv
+password = 0pnfv2015
+EOF
+
+    local failed=0
+
+    if [ ${#SUITE_FILES[@]} -gt 0 ]; then
+
+        for suite in ${SUITE_FILES[*]}; do
+
+            echo "---------------------------"
+            echo "Running test suite: $suite"
+            echo "---------------------------"
+
+            if ! yardstick task start --suite $suite; then
+                 echo "test suite $suite FAILED";
+
+                # Mark the test suite failed but continue
+                # running the remaining test suites.
+                (( failed++ ))
+            fi
+            if [ ${DISPATCHER_TYPE} = file ]; then
+                echo "---------------------------"
+                echo "Dump test suite $suite result"
+                echo "---------------------------"
+                if [ -f ${DISPATCHER_FILE_NAME} ]; then
+                    cat ${DISPATCHER_FILE_NAME}
+                else
+                    echo "Test result file ${DISPATCHER_FILE_NAME} is not exist"
+                fi
+            fi
+
+        done
+
+        if [ $failed -gt 0 ]; then
+
+            echo "---------------------------"
+            echo "$failed out of ${SUITE_FILES[*]} test suites FAILED"
+            echo "---------------------------"
+            exit 1
+         fi
+
+    else
+
+        echo "---------------------------"
+        echo "Running samples/ping.yaml  "
+        echo "---------------------------"
+
+        if ! yardstick task start samples/ping.yaml; then
+            echo "Yardstick test FAILED"
+            exit 1
+        fi
+
+        if [ ${DISPATCHER_TYPE} = file ]; then
+            echo "---------------------------"
+            echo "Dump samples/ping.yaml test result"
+            echo "---------------------------"
+            if [ -f ${DISPATCHER_FILE_NAME} ]; then
+                cat ${DISPATCHER_FILE_NAME}
+            else
+                echo "Test result file ${DISPATCHER_FILE_NAME} is not exist"
+            fi
+        fi
 
-    # Just run sample ping for now.
-    if ! yardstick -d task start samples/ping.yaml; then
-        echo "Yardstick test FAILED"
-        exit 1
     fi
+
 }
 
 main()
@@ -139,8 +291,34 @@ main()
 
     cd $GITROOT
 
-    # install yardstick
-    install_yardstick
+    export YARDSTICK_VERSION=$(git rev-parse HEAD)
+
+    SUITE_FILES=()
+
+    # find the test suite files
+    for suite in $TEST_SUITES; do
+        if [ -f $suite ]; then
+            SUITE_FILES+=($suite)
+        else
+            tsdir=$GITROOT/tests/opnfv/test_suites
+            if [ ! -f $tsdir/$suite ]; then
+                echo "Test suite \"$suite\" does not exist"
+                exit 1
+            fi
+            SUITE_FILES+=($tsdir/$suite)
+        fi
+    done
+
+    echo
+    echo "========== Running Yardstick CI with following parameters =========="
+    echo "Script options: ${SCRIPT} $SCRIPT_ARGS"
+    echo "Dispatcher: ${DISPATCHER_TYPE} ${DISPATCHER_FILE_NAME}"
+    echo "YARDSTICK_VERSION: ${YARDSTICK_VERSION}"
+    echo "Number of test suites: ${#SUITE_FILES[@]}"
+    for suite in ${SUITE_FILES[*]}; do
+        echo "     $suite"
+    done
+    echo
 
     # check if some necessary variables is set
     if [ -z "$OS_AUTH_URL" ]; then
@@ -148,36 +326,38 @@ main()
         exit 1
     fi
 
-    # extract auth ip
-    ip=$(echo $OS_AUTH_URL | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
-
-    ## FIXME: temporarily disabling this because
-    ## of timeout errors on LF-POD2.
-    ## Maybe we need a longer timeout ??
-    # check if the auth port is open
-    # echo "Checking if tcp port $ip:5000 is open..."
-    # nc -zv -w 10 $ip 5000; rc=$?;
-    # if [ $rc -eq 0 ]; then
-    #     echo "$ip:5000 is open for tcp connections"
-    # else
-    #     echo "$ip:5000 is closed"
-    #     exit 1
-    # fi
-
-    # check if the api is up
-    echo "Checking if OS API is working..."
-    if ! glance image-list > /dev/null; then
-        echo "OS API is down"
-        exit 1
-    fi
+    echo "OS_AUTH_URL is $OS_AUTH_URL"
+    echo
+
+    # check OpenStack services
+    echo "Checking OpenStack services:"
+    for cmd in "glance image-list" "nova list" "heat stack-list"; do
+        echo "  checking ${cmd/%\ */} ..."
+        if ! $cmd >/dev/null; then
+            echo "error: command \"$cmd\" failed"
+            exit 1
+        fi
+    done
+
+    echo
+    echo "Checking for External network:"
+    for net in $(neutron net-list --router:external True -c name -f value); do
+        echo "  external network: $net"
+    done
+
+    # install yardstick
+    install_yardstick
 
     cleanup
 
     trap "error_exit" EXIT SIGTERM
 
+    QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-trusty-server.img"
+
     build_yardstick_image
     load_yardstick_image
     load_cirros_image
+    create_nova_flavor
 
     run_test
 }