Docker container for Yardstick CI
[yardstick.git] / ci / yardstick-verify
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2015 Ericsson AB and others.
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 YARDSTICK_IMAGE_ID=
12 CIRROS_IMAGE_ID=
13
14 QCOW_IMAGE="/tmp/workspace/yardstick/yardstick-trusty-server.img"
15
16 cleanup()
17 {
18     echo
19     echo "========== Cleanup =========="
20
21     if ! glance image-list; then
22         return
23     fi
24
25     for image in $(glance image-list | grep -e cirros-0.3.3 -e yardstick-trusty-server | awk '{print $2}'); do
26         echo "Deleting image $image..."
27         glance image-delete $image || true
28     done
29 }
30
31 exitcode=""
32
33 error_exit()
34 {
35     local rc=$?
36
37     if [ -z "$exitcode" ]; then
38         # In case of recursive traps (!?)
39         exitcode=$rc
40     fi
41
42     cleanup
43
44     echo "Exiting with RC=$exitcode"
45
46     exit $exitcode
47 }
48
49 set -o errexit
50 set -o pipefail
51
52 install_yardstick()
53 {
54     echo
55     echo "========== Installing yardstick =========="
56
57     if ! sudo python setup.py install; then
58         echo 'Yardstick installation failed!'
59         exit 1
60     fi
61 }
62
63 build_yardstick_image()
64 {
65     echo
66     echo "========== Build yardstick cloud image =========="
67
68     sudo $(which yardstick-img-modify) $(pwd)/tools/ubuntu-server-cloudimg-modify.sh
69     if [ ! -f $QCOW_IMAGE ]; then
70         echo "Failed building QCOW image"
71         exit 1
72     fi
73 }
74
75 load_cirros_image()
76 {
77     echo
78     echo "========== Loading cirros cloud image =========="
79
80     local image_file=
81
82     wget http://download.cirros-cloud.net/0.3.3/cirros-0.3.3-x86_64-disk.img -O /tmp/cirros.img
83
84     output=$(glance image-create \
85         --name  cirros-0.3.3 \
86         --disk-format qcow2 \
87         --container-format bare \
88         --file /tmp/cirros.img)
89     echo "$output"
90
91     CIRROS_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
92     if [ -z "$CIRROS_IMAGE_ID" ]; then
93         echo 'Failed uploading cirros image to cloud'.
94         exit 1
95     fi
96
97     echo "Cirros image id: $CIRROS_IMAGE_ID"
98 }
99
100 load_yardstick_image()
101 {
102     echo
103     echo "========== Loading yardstick cloud image =========="
104
105     output=$(glance --os-image-api-version 1 image-create \
106         --name yardstick-trusty-server \
107         --is-public true --disk-format qcow2 \
108         --container-format bare \
109         --file $QCOW_IMAGE)
110     echo "$output"
111
112     GLANCE_IMAGE_ID=$(echo "$output" | grep " id " | awk '{print $(NF-1)}')
113
114     if [ -z "$GLANCE_IMAGE_ID" ]; then
115         echo 'Failed uploading image to cloud'.
116         exit 1
117     fi
118
119     sudo rm -f $QCOW_IMAGE
120
121     echo "Glance image id: $GLANCE_IMAGE_ID"
122 }
123
124 run_test()
125 {
126     echo
127     echo "========== Running yardstick test suite =========="
128
129     # Just run sample ping for now.
130     if ! yardstick -d task start samples/ping.yaml; then
131         echo "Yardstick test FAILED"
132         exit 1
133     fi
134 }
135
136 main()
137 {
138     GITROOT=$(cd $(dirname $0) && git rev-parse --show-toplevel)
139
140     cd $GITROOT
141
142     # install yardstick
143     install_yardstick
144
145     # check if some necessary variables is set
146     if [ -z "$OS_AUTH_URL" ]; then
147         echo "OS_AUTH_URL is unset or empty"
148         exit 1
149     fi
150
151     # extract auth ip
152     ip=$(echo $OS_AUTH_URL | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+')
153
154     # check if the auth port is open
155     echo "Checking if tcp port $ip:5000 is open..."
156     nc -zv -w 10 $ip 5000; rc=$?;
157     if [ $rc -eq 0 ]; then
158         echo "$ip:5000 is open for tcp connections"
159     else
160         echo "$ip:5000 is closed"
161         exit 1
162     fi
163
164     # check if the api is up
165     echo "Checking if OS API is working..."
166     if ! glance image-list > /dev/null; then
167         echo "OS API is down"
168         exit 1
169     fi
170
171     cleanup
172
173     trap "error_exit" EXIT SIGTERM
174
175     build_yardstick_image
176     load_yardstick_image
177     load_cirros_image
178
179     run_test
180 }
181
182 main