Add the yardstick invokation script
[kvmfornfv.git] / tests / testexec.sh
1 #!/bin/bash
2 ##############################################################################
3 ## Copyright (c) 2015 Intel Corp.
4 ##
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 ###############################################################################
10
11 set -e
12 set -o errexit
13 set -o pipefail
14
15 : ${YARDSTICK_REPO:='https://gerrit.opnfv.org/gerrit/yardstick'}
16 : ${YARDSTICK_REPO_DIR:='/home/opnfv/repos/yardstick'}
17 : ${YARDSTICK_BRANCH:='master'} # branch, tag, sha1 or refspec
18
19 : ${INSTALLER_TYPE:='fuel'}
20 : ${INSTALLER_IP:='10.20.0.2'}
21
22 : ${POD_NAME:='opnfv-jump-2'}
23 : ${EXTERNAL_NET:='net04_ext'}
24
25 git_checkout()
26 {
27     if git cat-file -e $1^{commit} 2>/dev/null; then
28         # branch, tag or sha1 object
29         git checkout $1
30     else
31         # refspec / changeset
32         git fetch --tags --progress $2 $1
33         git checkout FETCH_HEAD
34     fi
35 }
36
37 echo
38 echo "INFO: Updating yardstick -> $YARDSTICK_BRANCH"
39 if [ ! -d $YARDSTICK_REPO_DIR ]; then
40     git clone YARDSTICK_REPO $YARDSTICK_REPO_DIR
41 fi
42 cd $YARDSTICK_REPO_DIR
43
44
45 git checkout master && git pull
46 git_checkout $YARDSTICK_BRANCH $YARDSTICK_REPO
47
48 export EXTERNAL_NET INSTALLER_TYPE POD_NAME
49
50 # Verifiy
51
52 DISPATCHER_TYPE=file
53 DISPATCHER_FILE_NAME="/tmp/yardstick.out.$$"
54
55 exitcode=""
56
57 error_exit()
58 {
59     local rc=$?
60
61     if [ -z "$exitcode" ]; then
62         # In case of recursive traps (!?)
63         exitcode=$rc
64     fi
65
66     echo "Exiting with RC=$exitcode"
67
68     exit $exitcode
69 }
70
71
72 install_yardstick()
73 {
74     echo
75     echo "========== Installing yardstick =========="
76
77     if ! sudo -E python setup.py install; then
78         echo 'Yardstick installation failed!'
79         exit 1
80     fi
81 }
82
83
84 run_test()
85 {
86     echo
87     echo "========== Running yardstick test suites =========="
88
89     mkdir -p /etc/yardstick
90
91     cat << EOF >> /etc/yardstick/yardstick.conf
92 [DEFAULT]
93 debug = True
94 dispatcher = ${DISPATCHER_TYPE}
95
96 [dispatcher_file]
97 file_name = ${DISPATCHER_FILE_NAME}
98
99 [dispatcher_http]
100 timeout = 5
101 target = ${DISPATCHER_HTTP_TARGET}
102 EOF
103
104     local failed=0
105
106     echo "----------------------------------------------"
107     echo "Running samples/cyclictest-node-context.yaml  "
108     echo "----------------------------------------------"
109
110     if ! yardstick task start /opt/cyclictest-node-context.yaml; then
111         echo "Yardstick test FAILED"
112         exit 1
113     fi
114     echo "----------------------------------------------"
115     echo "Dump test result:                             "
116     cat ${DISPATCHER_FILE_NAME}
117     echo "----------------------------------------------"
118     rm -rf ${DISPATCHER_FILE_NAME}
119 }
120
121
122 verifiy()
123 {
124     GITROOT=$YARDSTICK_REPO_DIR
125
126     cd $GITROOT
127
128     export YARDSTICK_VERSION=$(git rev-parse HEAD)
129
130     # fetch patch
131     git fetch https://QiLiang@gerrit.opnfv.org/gerrit/yardstick refs/changes/33/3633/1 && git checkout FETCH_HEAD
132
133     # If any change needed for yardstick, applied here.
134     if [ -e /opt/yardstick.patch ]
135     then
136         patch -p1 -i /opt/yardstick.patch
137     fi
138     # install yardstick
139     install_yardstick
140
141     trap "error_exit" EXIT SIGTERM
142
143     run_test
144 }
145
146
147 verifiy
148