Merge "improve logging, clear using print"
[yardstick.git] / tests / ci / yardstick-verify
index 1a6682f..f3e7a49 100755 (executable)
@@ -34,6 +34,7 @@ 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)
+   -m      Reporting target (example: -m 213.77.62.197/results)
 
            Default target is dump to file ($DISPATCHER_FILE_NAME)
 
@@ -44,8 +45,9 @@ DISPATCHER_TYPE=file
 DISPATCHER_FILE_NAME="/tmp/yardstick.out"
 DISPATCHER_HTTP_TARGET="http://testresults.opnfv.org/test/api/v1/results"
 DISPATCHER_INFLUXDB_TARGET=
+REPORTING_TARGET="${DISPATCHER_HTTP_TARGET}"
 
-while getopts "r:i:h" OPTION; do
+while getopts "r:i:m:h" OPTION; do
     case $OPTION in
         h)
             usage
@@ -61,6 +63,9 @@ while getopts "r:i:h" OPTION; do
             DISPATCHER_INFLUXDB_TARGET=http://${OPTARG}
             DISPATCHER_FILE_NAME=
             ;;
+        m)
+            REPORTING_TARGET=http://${OPTARG}
+            ;;
         *)
             echo "${OPTION} is not a valid argument"
             exit 1
@@ -82,7 +87,9 @@ error_exit()
         exitcode=$rc
     fi
 
-    cleanup
+    if [[ "${DEPLOY_SCENARIO:0:2}" == 'os' ]];then
+        source "${YARDSTICK_REPO_DIR}/tests/ci/clean_images.sh"
+    fi
 
     echo "Exiting with RC=$exitcode"
 
@@ -92,22 +99,10 @@ error_exit()
 set -o errexit
 set -o pipefail
 
-install_yardstick()
-{
-    echo
-    echo "========== Installing yardstick =========="
-
-    # uninstall previous version
-    pip uninstall -y yardstick || true
-
-    # Install yardstick
-    pip install .
-}
-
 install_storperf()
 {
-    # Install Storper on huawei-pod1
-    if [ "$NODE_NAME" == "huawei-pod1" ]; then
+    # Install Storper on huawei-pod1 and huawei-pod2
+    if [ "$NODE_NAME" == "huawei-pod1" -o "$NODE_NAME" == "huawei-pod2" ]; then
         echo
         echo "========== Installing storperf =========="
 
@@ -121,8 +116,8 @@ install_storperf()
 
 remove_storperf()
 {
-    # remove Storper from huawei-pod1
-    if [ "$NODE_NAME" == "huawei-pod1" ]; then
+    # remove Storper from huawei-pod1 and huawei-pod2
+    if [ "$NODE_NAME" == "huawei-pod1" -o "$NODE_NAME" == "huawei-pod2" ]; then
         echo
         echo "========== Removing storperf =========="
 
@@ -146,11 +141,11 @@ report(){
           \"version\":\"$(basename ${YARDSTICK_BRANCH})\",
           \"scenario\":\"${DEPLOY_SCENARIO}\",
           \"description\": \"yardstick ci scenario status\",
-          \"criteria\":\"$1\",
-          \"start_date\":\"$2\",
-          \"stop_date\":\"$3\",
+          \"criteria\":\"${1}\",
+          \"start_date\":\"${2}\",
+          \"stop_date\":\"${3}\",
           \"details\":\"\"}" \
-          ${DISPATCHER_HTTP_TARGET}
+          "${REPORTING_TARGET}"
 }
 
 run_test()
@@ -162,7 +157,7 @@ run_test()
 
     cat << EOF > /etc/yardstick/yardstick.conf
 [DEFAULT]
-debug = True
+debug = False
 dispatcher = ${DISPATCHER_TYPE}
 
 [dispatcher_file]
@@ -220,7 +215,7 @@ EOF
             scenario_status="FAILED"
         fi
 
-        report $scenario_status $start_date $stop_date
+        report "${scenario_status}" "${start_date}" "${stop_date}"
 
         if [ $failed -gt 0 ]; then
             echo "---------------------------"
@@ -255,6 +250,38 @@ EOF
 
 }
 
+check_openstack(){
+    # check if some necessary variables is set
+    if [ -z "$OS_AUTH_URL" ]; then
+        echo "OS_AUTH_URL is unset or empty"
+        exit 1
+    fi
+
+    echo "OS_AUTH_URL is $OS_AUTH_URL"
+    echo
+
+    # check OpenStack services
+    if [[ $OS_INSECURE ]] && [[ "$(echo $OS_INSECURE | tr '[:upper:]' '[:lower:]')" = "true" ]]; then
+        SECURE="--insecure"
+    else
+        SECURE=""
+    fi
+    echo "Checking OpenStack services:"
+    for cmd in "openstack ${SECURE} image list" "openstack ${SECURE} server list" "openstack ${SECURE} 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 $(openstack network list --external -c Name -f value); do
+        echo "  external network: $net"
+    done
+}
+
 main()
 {
     GITROOT=$(cd $(dirname $0) && git rev-parse --show-toplevel)
@@ -290,41 +317,15 @@ main()
     done
     echo
 
-    # check if some necessary variables is set
-    if [ -z "$OS_AUTH_URL" ]; then
-        echo "OS_AUTH_URL is unset or empty"
-        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
-
-    source $YARDSTICK_REPO_DIR/tests/ci/clean_images.sh
+    trap "error_exit" EXIT SIGTERM
 
-    cleanup
+    if [[ "${DEPLOY_SCENARIO:0:2}" == "os" ]];then
+        check_openstack
 
-    trap "error_exit" EXIT SIGTERM
+        source $YARDSTICK_REPO_DIR/tests/ci/clean_images.sh
+        source $YARDSTICK_REPO_DIR/tests/ci/load_images.sh
+    fi
 
-    source $YARDSTICK_REPO_DIR/tests/ci/load_images.sh
     install_storperf
     run_test
     remove_storperf