Docker container for Yardstick CI part 2 09/2909/7
authorJo¶rgen Karlsson <jorgen.w.karlsson@ericsson.com>
Thu, 29 Oct 2015 15:16:36 +0000 (16:16 +0100)
committerJörgen Karlsson <jorgen.w.karlsson@ericsson.com>
Wed, 4 Nov 2015 19:04:51 +0000 (19:04 +0000)
Added test suit selection and an option to use
the HTTP Result API.

Part 1: https://gerrit.opnfv.org/gerrit/#/c/2201/

Change-Id: I1c25d07e46cd44e25f448706ff2dfc3b31cd7208
JIRA:-
Signed-off-by: Jo¶rgen Karlsson <jorgen.w.karlsson@ericsson.com>
ci/docker/yardstick-ci/Dockerfile
ci/docker/yardstick-ci/run_benchmarks
ci/yardstick-verify
yardstick/dispatcher/http.py

index 15b0f62..9a1e832 100644 (file)
@@ -11,7 +11,11 @@ FROM ubuntu:14.04
 
 LABEL image=opnfv/yardstick-ci
 
-ENV YARDSTICK_REPO_DIR /home/yardstick
+# GIT repo directory
+ENV REPOS_DIR /home/opnfv/repos
+
+# Yardstick repo
+ENV YARDSTICK_REPO_DIR ${REPOS_DIR}/yardstick
 
 RUN apt-get update && apt-get install -y \
     wget \
@@ -29,6 +33,9 @@ RUN apt-get update && apt-get install -y \
 RUN apt-get -y autoremove && \
     apt-get clean
 
+RUN mkdir -p ${REPOS_DIR}
+
+RUN git config --global http.sslVerify false
 RUN git clone https://gerrit.opnfv.org/gerrit/yardstick ${YARDSTICK_REPO_DIR}
 
 COPY ./run_benchmarks /usr/local/bin/
index 391ee63..501b661 100755 (executable)
 set -e
 
 : ${YARDSTICK_REPO:='https://gerrit.opnfv.org/gerrit/yardstick'}
-: ${YARDSTICK_REPO_DIR:='/home/yardstick'}
-: ${YARDSTICK_BRANCH:='master'}
+: ${YARDSTICK_REPO_DIR:='/home/opnfv/yardstick'}
+: ${YARDSTICK_BRANCH:='master'} # branch, tag, sha1 or refspec
 
 : ${RELENG_REPO:='https://gerrit.opnfv.org/gerrit/releng'}
-: ${RELENG_REPO_DIR:='/home/releng'}
-: ${RELENG_BRANCH:='master'}
+: ${RELENG_REPO_DIR:='/home/opnfv/repos/releng'}
+: ${RELENG_BRANCH:='master'} # branch, tag, sha1 or refspec
 
 : ${INSTALLER_TYPE:='fuel'}
 : ${INSTALLER_IP:='10.20.0.2'}
 
-: ${EXTERNAL_NET_ID:='net04_ext'}
+: ${POD_NAME:='opnfv-jump-2'}
+: ${EXTERNAL_NET:='net04_ext'}
 
-# clone releng
+git_checkout()
+{
+    if git cat-file -e $1^{commit} 2>/dev/null; then
+        # branch, tag or sha1 object
+        git checkout $1
+    else
+        # refspec / changeset
+        git fetch --tags --progress $2 $1
+        git checkout FETCH_HEAD
+    fi
+}
+
+echo
+echo "INFO: Updating releng -> $RELENG_BRANCH"
 if [ ! -d $RELENG_REPO_DIR ]; then
     git clone $RELENG_REPO $RELENG_REPO_DIR
 fi
 cd $RELENG_REPO_DIR
-git fetch --tags --progress $RELENG_REPO $RELENG_BRANCH
-git checkout FETCH_HEAD
+git checkout master && git pull
+git_checkout $RELENG_BRANCH $RELENG_REPO
 
-# clone yardstick
+echo
+echo "INFO: Updating yardstick -> $YARDSTICK_BRANCH"
 if [ ! -d $YARDSTICK_REPO_DIR ]; then
     git clone YARDSTICK_REPO $YARDSTICK_REPO_DIR
 fi
 cd $YARDSTICK_REPO_DIR
-git fetch --tags --progress $YARDSTICK_REPO $YARDSTICK_BRANCH
-git checkout FETCH_HEAD
+git checkout master && git pull
+git_checkout $YARDSTICK_BRANCH $YARDSTICK_REPO
+
+echo
+echo "INFO: Creating openstack credentials .."
 
 # Create openstack credentials
 $RELENG_REPO_DIR/utils/fetch_os_creds.sh \
@@ -51,10 +69,11 @@ if [ "$INSTALLER_TYPE" == "fuel" ]; then
     ssh_opts="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
     if sshpass -p r00tme ssh 2>/dev/null $ssh_opts root@${INSTALLER_IP} \
         fuel environment --env 1 | grep opnfv-virt; then
+        echo "INFO: applying OPNFV playground hack"
         export OS_ENDPOINT_TYPE='publicURL'
     fi
 fi
 
-export EXTERNAL_NET_ID
+export EXTERNAL_NET INSTALLER_TYPE POD_NAME
 
-$YARDSTICK_REPO_DIR/ci/yardstick-verify
+$YARDSTICK_REPO_DIR/ci/yardstick-verify $@
index 15ea022..beb2170 100755 (executable)
@@ -8,10 +8,60 @@
 # 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.
+#
 
-QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-trusty-server.img"
+SCRIPT=$0
+SCRIPT_ARGS=$@
+
+usage()
+{
+    cat << EOF
+usage: $0 options [TEST_SUITE ...]
+
+If no test suites are given ping.yaml is run.
+
+OPTIONS:
+   -h      Show this message
+   -r      IP address for Result API.
+           Default is to store the results to file ($DISPATCHER_FILE_NAME)
+           if this option is not present.
+
+EOF
+}
+
+DISPATCHER_TYPE=file
+DISPATCHER_FILE_NAME="/tmp/yardstick.out"
+DISPATCHER_HTTP_TARGET=
+
+while getopts "r:h" OPTION; do
+    case $OPTION in
+        h)
+            usage
+            exit 0
+            ;;
+        r)
+            DISPATCHER_TYPE=http
+            DISPATCHER_HTTP_TARGET=http://${OPTARG}/results
+            ;;
+        *)
+            echo "${OPTION} is not a valid argument"
+            exit 1
+            ;;
+    esac
+done
+
+shift $[OPTIND - 1]
+TEST_SUITES=$@
 
 cleanup()
 {
@@ -124,13 +174,64 @@ 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}
+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
+
+         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
 
-    # Just run sample ping for now.
-    if ! yardstick -d task start samples/ping.yaml; then
-        echo "Yardstick test FAILED"
-        exit 1
     fi
+
 }
 
 main()
@@ -139,6 +240,34 @@ main()
 
     cd $GITROOT
 
+    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 "Result API: ${DISPATCHER_HTTP_TARGET:-$DISPATCHER_FILE_NAME}"
+    echo "YARDSTICK_VERSION: ${YARDSTICK_VERSION}"
+    echo "Number of test suites: ${#SUITE_FILES[@]}"
+    for suite in ${SUITE_FILES[*]}; do
+        echo "     $suite"
+    done
+
     # install yardstick
     install_yardstick
 
@@ -148,22 +277,6 @@ 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
@@ -175,6 +288,8 @@ main()
 
     trap "error_exit" EXIT SIGTERM
 
+    QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-trusty-server.img"
+
     build_yardstick_image
     load_yardstick_image
     load_cirros_image
index af9ace4..de29588 100644 (file)
@@ -7,6 +7,7 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 
+import os
 import json
 import logging
 import requests
@@ -45,13 +46,12 @@ class HttpDispatcher(DispatchBase):
         self.timeout = CONF.dispatcher_http.timeout
         self.target = CONF.dispatcher_http.target
         self.raw_result = []
-        # TODO set pod_name, installer, version based on pod info
         self.result = {
             "project_name": "yardstick",
             "description": "yardstick test cases result",
-            "pod_name": "opnfv-jump-2",
-            "installer": "compass",
-            "version": "Brahmaputra-dev"
+            "pod_name": os.environ.get('POD_NAME', 'unknown'),
+            "installer": os.environ.get('INSTALLER_TYPE', 'unknown'),
+            "version": os.environ.get('YARDSTICK_VERSION', 'unknown')
         }
 
     def record_result_data(self, data):