summaryrefslogtreecommitdiffstats
path: root/tests/testexec.sh
blob: f773907f786a3ca076bc7e8b3be4a7004f6b86c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
##############################################################################
## Copyright (c) 2015 Intel Corp.
##
## All rights reserved. This program and the accompanying materials
## are made available under the terms of the Apache License, Version 2.0
## which accompanies this distribution, and is available at
## http://www.apache.org/licenses/LICENSE-2.0
###############################################################################

set -e
set -o errexit
set -o pipefail

: ${YARDSTICK_REPO:='https://gerrit.opnfv.org/gerrit/yardstick'}
: ${YARDSTICK_REPO_DIR:='/home/opnfv/repos/yardstick'}
: ${YARDSTICK_BRANCH:='master'} # branch, tag, sha1 or refspec

: ${INSTALLER_TYPE:='fuel'}
: ${INSTALLER_IP:='10.20.0.2'}

: ${POD_NAME:='opnfv-jump-2'}
: ${EXTERNAL_NET:='net04_ext'}

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 yardstick -> $YARDSTICK_BRANCH"
if [ ! -d $YARDSTICK_REPO_DIR ]; then
    git clone YARDSTICK_REPO $YARDSTICK_REPO_DIR
fi
cd $YARDSTICK_REPO_DIR


git checkout master && git pull
git_checkout $YARDSTICK_BRANCH $YARDSTICK_REPO

export EXTERNAL_NET INSTALLER_TYPE POD_NAME

# Verifiy

DISPATCHER_TYPE=file
DISPATCHER_FILE_NAME="/tmp/yardstick.out.$$"

exitcode=""

error_exit()
{
    local rc=$?

    if [ -z "$exitcode" ]; then
        # In case of recursive traps (!?)
        exitcode=$rc
    fi

    echo "Exiting with RC=$exitcode"

    exit $exitcode
}


install_yardstick()
{
    echo
    echo "========== Installing yardstick =========="

    if ! sudo -E python setup.py install; then
        echo 'Yardstick installation failed!'
        exit 1
    fi
}


run_test()
{
    echo
    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

    echo "----------------------------------------------"
    echo "Running samples/cyclictest-node-context.yaml  "
    echo "----------------------------------------------"

    if ! yardstick task start /opt/cyclictest-node-context.yaml; then
        echo "Yardstick test FAILED"
        exit 1
    fi
    echo "----------------------------------------------"
    echo "Dump test result:                             "
    cat ${DISPATCHER_FILE_NAME}
    echo "----------------------------------------------"
    rm -rf ${DISPATCHER_FILE_NAME}
}


verifiy()
{
    GITROOT=$YARDSTICK_REPO_DIR

    cd $GITROOT

    export YARDSTICK_VERSION=$(git rev-parse HEAD)

    # If any change needed for yardstick, applied here.
    if [ -e /opt/yardstick.patch ]
    then
        patch -p1 -i /opt/yardstick.patch
    fi
    # install yardstick
    install_yardstick

    trap "error_exit" EXIT SIGTERM

    run_test
}


verifiy