Browse code

Updated CI test script Debo~ Dutta@Cisco, Dave Lapsley@Nicira * original at https://review.openstack.org/#change,3682 * Allow this exercise to be skipped if quantum is not enabled

Change-Id: I8463f654fb85394d78dd01c93c7f7b2706511030

debo authored on 2012/02/29 10:47:26
Showing 1 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,393 @@
0
+#!/usr/bin/env bash
1
+#
2
+
3
+# **quantum.sh**
4
+
5
+# We will use this test to perform integration testing of nova and
6
+# other components with Quantum.
7
+
8
+echo "*********************************************************************"
9
+echo "Begin DevStack Exercise: $0"
10
+echo "*********************************************************************"
11
+
12
+# This script exits on an error so that errors don't compound and you see
13
+# only the first error that occured.
14
+set -o errexit
15
+
16
+# Print the commands being run so that we can see the command that triggers
17
+# an error.  It is also useful for following allowing as the install occurs.
18
+set -o xtrace
19
+
20
+#------------------------------------------------------------------------------
21
+# Quantum config check
22
+#------------------------------------------------------------------------------
23
+# Warn if quantum is not enabled
24
+if [[ ! "$ENABLED_SERVICES" =~ "q-svc" ]]; then
25
+    echo "WARNING: Running quantum test without enabling quantum"
26
+fi
27
+
28
+#------------------------------------------------------------------------------
29
+# Environment
30
+#------------------------------------------------------------------------------
31
+
32
+# Keep track of the current directory
33
+EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
34
+TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
35
+
36
+# Import common functions
37
+source $TOP_DIR/functions
38
+
39
+# Import configuration
40
+source $TOP_DIR/openrc
41
+
42
+# Import exercise configuration
43
+source $TOP_DIR/exerciserc
44
+
45
+# If quantum is not enabled we exit with exitcode 55 which mean
46
+# exercise is skipped.
47
+is_service_enabled quantum || exit 55
48
+
49
+#------------------------------------------------------------------------------
50
+# Various default parameters.
51
+#------------------------------------------------------------------------------
52
+
53
+# Max time to wait while vm goes from build to active state
54
+ACTIVE_TIMEOUT=${ACTIVE_TIMEOUT:-30}
55
+
56
+# Max time till the vm is bootable
57
+BOOT_TIMEOUT=${BOOT_TIMEOUT:-60}
58
+
59
+# Max time to wait for proper association and dis-association.
60
+ASSOCIATE_TIMEOUT=${ASSOCIATE_TIMEOUT:-15}
61
+
62
+# Max time to wait before delete VMs and delete Networks
63
+VM_NET_DELETE_TIMEOUT=${VM_NET_TIMEOUT:-10}
64
+
65
+# Instance type to create
66
+DEFAULT_INSTANCE_TYPE=${DEFAULT_INSTANCE_TYPE:-m1.tiny}
67
+
68
+# Boot this image, use first AMi image if unset
69
+DEFAULT_IMAGE_NAME=${DEFAULT_IMAGE_NAME:-ami}
70
+
71
+# OVS Hosts
72
+OVS_HOSTS=${DEFAULT_OVS_HOSTS:-"localhost"}
73
+
74
+#------------------------------------------------------------------------------
75
+# Nova settings.
76
+#------------------------------------------------------------------------------
77
+NOVA_MANAGE=/opt/stack/nova/bin/nova-manage
78
+NOVA=/usr/local/bin/nova
79
+NOVA_CONF=/etc/nova/nova.conf
80
+
81
+#------------------------------------------------------------------------------
82
+# Mysql settings.
83
+#------------------------------------------------------------------------------
84
+MYSQL="/usr/bin/mysql --skip-column-name --host=$MYSQL_HOST"
85
+
86
+#------------------------------------------------------------------------------
87
+# Keystone settings.
88
+#------------------------------------------------------------------------------
89
+KEYSTONE="keystone"
90
+
91
+#------------------------------------------------------------------------------
92
+# Get a token for clients that don't support service catalog
93
+#------------------------------------------------------------------------------
94
+
95
+# manually create a token by querying keystone (sending JSON data).  Keystone
96
+# returns a token and catalog of endpoints.  We use python to parse the token
97
+# and save it.
98
+
99
+TOKEN=`keystone token-get | grep ' id ' | awk '{print $4}'`
100
+
101
+#------------------------------------------------------------------------------
102
+# Various functions.
103
+#------------------------------------------------------------------------------
104
+function get_image_id {
105
+    local IMAGE_ID=`glance -f -A $TOKEN index | egrep $DEFAULT_IMAGE_NAME | head -1 | cut -d" " -f1`
106
+    echo "$IMAGE_ID"
107
+}
108
+
109
+function get_tenant_id {
110
+    local TENANT_NAME=$1
111
+    local TENANT_ID=`keystone tenant-list | grep $TENANT_NAME | awk '{print $2}'`
112
+    echo "$TENANT_ID"
113
+}
114
+
115
+function get_user_id {
116
+    local USER_NAME=$1
117
+    local USER_ID=`keystone user-list | grep $USER_NAME | awk '{print $2}'`
118
+    echo "$USER_ID"
119
+}
120
+
121
+function get_role_id {
122
+    local ROLE_NAME=$1
123
+    local ROLE_ID=`keystone role-list | grep $ROLE_NAME | awk '{print $2}'`
124
+    echo "$ROLE_ID"
125
+}
126
+
127
+# TODO: (Debo) Change Quantum client CLI and then remove the MYSQL stuff.
128
+function get_network_id {
129
+    local NETWORK_NAME=$1
130
+    local QUERY="select uuid from networks where label='$NETWORK_NAME'"
131
+    local NETWORK_ID=`echo $QUERY | $MYSQL -u root -p$MYSQL_PASSWORD nova`
132
+    echo "$NETWORK_ID"
133
+}
134
+
135
+function get_flavor_id {
136
+    local INSTANCE_TYPE=$1
137
+    local FLAVOR_ID=`nova flavor-list | grep $INSTANCE_TYPE | awk '{print $2}'`
138
+    echo "$FLAVOR_ID"
139
+}
140
+
141
+function add_tenant {
142
+    local TENANT=$1
143
+    local USER=$3
144
+    local PASSWORD=$2
145
+
146
+    $KEYSTONE tenant-create --name=$TENANT
147
+    $KEYSTONE user-create --name=$USER --pass=${PASSWORD}
148
+
149
+    local USER_ID=$(get_user_id $USER)
150
+    local TENANT_ID=$(get_tenant_id $TENANT)
151
+
152
+    $KEYSTONE user-role-add --user $USER_ID --role $(get_role_id Member) --tenant_id $TENANT_ID
153
+    $KEYSTONE user-role-add --user $USER_ID --role $(get_role_id admin) --tenant_id $TENANT_ID
154
+    $KEYSTONE user-role-add --user $USER_ID --role $(get_role_id anotherrole) --tenant_id $TENANT_ID
155
+    #$KEYSTONE user-role-add --user $USER_ID --role $(get_role_id sysadmin) --tenant_id $TENANT_ID
156
+    #$KEYSTONE user-role-add --user $USER_ID --role $(get_role_id netadmin) --tenant_id $TENANT_ID
157
+}
158
+
159
+function remove_tenant {
160
+    local TENANT=$1
161
+    local TENANT_ID=$(get_tenant_id $TENANT)
162
+
163
+    $KEYSTONE tenant-delete $TENANT_ID
164
+}
165
+
166
+function remove_user {
167
+    local USER=$1
168
+    local USER_ID=$(get_user_id $USER)
169
+
170
+    $KEYSTONE user-delete $USER_ID
171
+}
172
+
173
+
174
+#------------------------------------------------------------------------------
175
+# "Create" functions
176
+#------------------------------------------------------------------------------
177
+
178
+function create_tenants {
179
+    add_tenant demo1 nova demo1
180
+    add_tenant demo2 nova demo2
181
+}
182
+
183
+function delete_tenants_and_users {
184
+    remove_tenant demo1
185
+    remove_tenant demo2
186
+    remove_user demo1
187
+    remove_user demo2
188
+}
189
+
190
+function create_networks {
191
+    $NOVA_MANAGE --flagfile=$NOVA_CONF network create \
192
+        --label=public-net1 \
193
+        --fixed_range_v4=11.0.0.0/24
194
+
195
+    $NOVA_MANAGE --flagfile=$NOVA_CONF network create \
196
+        --label=demo1-net1 \
197
+        --fixed_range_v4=12.0.0.0/24 \
198
+        --project_id=$(get_tenant_id demo1) \
199
+        --priority=1
200
+
201
+    $NOVA_MANAGE --flagfile=$NOVA_CONF network create \
202
+        --label=demo2-net1 \
203
+        --fixed_range_v4=13.0.0.0/24 \
204
+        --project_id=$(get_tenant_id demo2) \
205
+        --priority=1
206
+}
207
+
208
+function create_vms {
209
+    PUBLIC_NET1_ID=$(get_network_id public-net1)
210
+    DEMO1_NET1_ID=$(get_network_id demo1-net1)
211
+    DEMO2_NET1_ID=$(get_network_id demo2-net1)
212
+
213
+    export OS_TENANT_NAME=demo1
214
+    export OS_USERNAME=demo1
215
+    export OS_PASSWORD=nova
216
+    VM_UUID1=`$NOVA boot --flavor $(get_flavor_id m1.tiny) \
217
+        --image $(get_image_id) \
218
+        --nic net-id=$PUBLIC_NET1_ID \
219
+        --nic net-id=$DEMO1_NET1_ID \
220
+        demo1-server1 | grep ' id ' | cut -d"|" -f3 | sed 's/ //g'`
221
+    die_if_not_set VM_UUID1 "Failure launching demo1-server1"
222
+
223
+    export OS_TENANT_NAME=demo2
224
+    export OS_USERNAME=demo2
225
+    export OS_PASSWORD=nova
226
+    VM_UUID2=`$NOVA boot --flavor $(get_flavor_id m1.tiny) \
227
+        --image $(get_image_id) \
228
+        --nic net-id=$PUBLIC_NET1_ID \
229
+        --nic net-id=$DEMO2_NET1_ID \
230
+        demo2-server1 | grep ' id ' | cut -d"|" -f3 | sed 's/ //g'`
231
+    die_if_not_set VM_UUID2 "Failure launching demo2-server1"
232
+
233
+    VM_UUID3=`$NOVA boot --flavor $(get_flavor_id m1.tiny) \
234
+        --image $(get_image_id) \
235
+        --nic net-id=$PUBLIC_NET1_ID \
236
+        --nic net-id=$DEMO2_NET1_ID \
237
+        demo2-server2 | grep ' id ' | cut -d"|" -f3 | sed 's/ //g'`
238
+    die_if_not_set VM_UUID3 "Failure launching demo2-server2"
239
+
240
+}
241
+
242
+function ping_vms {
243
+
244
+    echo "Sleeping a bit let the VMs come up"
245
+    sleep $ACTIVE_TIMEOUT
246
+
247
+    export OS_TENANT_NAME=demo1
248
+    export OS_USERNAME=demo1
249
+    export OS_PASSWORD=nova
250
+    # get the IP of the servers
251
+    PUBLIC_IP1=`nova show $VM_UUID1 | grep public-net1 | awk '{print $5}'`
252
+    export OS_TENANT_NAME=demo2
253
+    export OS_USERNAME=demo2
254
+    export OS_PASSWORD=nova
255
+    PUBLIC_IP2=`nova show $VM_UUID2 | grep public-net1 | awk '{print $5}'`
256
+
257
+    MULTI_HOST=${MULTI_HOST:-0}
258
+    if [ "$MULTI_HOST" = "0" ]; then
259
+        # sometimes the first ping fails (10 seconds isn't enough time for the VM's
260
+        # network to respond?), so let's ping for a default of 15 seconds with a
261
+        # timeout of a second for each ping.
262
+        if ! timeout $BOOT_TIMEOUT sh -c "while ! ping -c1 -w1 $PUBLIC_IP1; do sleep 1; done"; then
263
+            echo "Couldn't ping server"
264
+            exit 1
265
+        fi
266
+        if ! timeout $BOOT_TIMEOUT sh -c "while ! ping -c1 -w1 $PUBLIC_IP2; do sleep 1; done"; then
267
+            echo "Couldn't ping server"
268
+            exit 1
269
+        fi
270
+    else
271
+        # On a multi-host system, without vm net access, do a sleep to wait for the boot
272
+        sleep $BOOT_TIMEOUT
273
+    fi
274
+}
275
+
276
+function shutdown_vms {
277
+    export OS_TENANT_NAME=demo1
278
+    export OS_USERNAME=demo1
279
+    export OS_PASSWORD=nova
280
+    nova delete $VM_UUID1
281
+
282
+    export OS_TENANT_NAME=demo2
283
+    export OS_USERNAME=demo2
284
+    export OS_PASSWORD=nova
285
+    nova delete $VM_UUID2
286
+    nova delete $VM_UUID3
287
+
288
+}
289
+
290
+function delete_networks {
291
+    PUBLIC_NET1_ID=$(get_network_id public-net1)
292
+    DEMO1_NET1_ID=$(get_network_id demo1-net1)
293
+    DEMO2_NET1_ID=$(get_network_id demo2-net1)
294
+    nova-manage network delete --uuid=$PUBLIC_NET1_ID
295
+    nova-manage network delete --uuid=$DEMO1_NET1_ID
296
+    nova-manage network delete --uuid=$DEMO2_NET1_ID
297
+}
298
+
299
+function all {
300
+    create_tenants
301
+    create_networks
302
+    create_vms
303
+    ping_vms
304
+    shutdown_vms
305
+    delete_networks
306
+    delete_tenants_and_users
307
+}
308
+
309
+#------------------------------------------------------------------------------
310
+# Test functions.
311
+#------------------------------------------------------------------------------
312
+function test_functions {
313
+    IMAGE=$(get_image_id)
314
+    echo $IMAGE
315
+
316
+    TENANT_ID=$(get_tenant_id demo)
317
+    echo $TENANT_ID
318
+
319
+    FLAVOR_ID=$(get_flavor_id m1.tiny)
320
+    echo $FLAVOR_ID
321
+
322
+    NETWORK_ID=$(get_network_id private)
323
+    echo $NETWORK_ID
324
+}
325
+
326
+#------------------------------------------------------------------------------
327
+# Usage and main.
328
+#------------------------------------------------------------------------------
329
+usage() {
330
+    echo "$0: [-h]"
331
+    echo "  -h, --help     Display help message"
332
+    echo "  -n, --net      Create networks"
333
+    echo "  -v, --vm       Create vms"
334
+    echo "  -t, --tenant   Create tenants"
335
+    echo "  -T, --test     Test functions"
336
+}
337
+
338
+main() {
339
+    if [ $# -eq 0 ] ; then
340
+        usage
341
+        exit
342
+    fi
343
+
344
+    echo Description
345
+    echo
346
+    echo Copyright 2012, Cisco Systems
347
+    echo Copyright 2012, Nicira Networks, Inc.
348
+    echo
349
+    echo Please direct any questions to dedutta@cisco.com, dlapsley@nicira.com
350
+    echo
351
+
352
+    while [ "$1" != "" ]; do
353
+        case $1 in
354
+            -h | --help )   usage
355
+                            exit
356
+                            ;;
357
+            -n | --net )    create_networks
358
+                            exit
359
+                            ;;
360
+            -v | --vm )     create_vms
361
+                            exit
362
+                            ;;
363
+            -t | --tenant ) create_tenants
364
+                            exit
365
+                            ;;
366
+            -p | --ping )   ping_vms
367
+                            exit
368
+                            ;;
369
+            -T | --test )   test_functions
370
+                            exit
371
+                            ;;
372
+            -a | --all )    all
373
+                            exit
374
+                            ;;
375
+            * )             usage
376
+                            exit 1
377
+        esac
378
+        shift
379
+    done
380
+}
381
+
382
+
383
+#-------------------------------------------------------------------------------
384
+# Kick off script.
385
+#-------------------------------------------------------------------------------
386
+echo $*
387
+main -a
388
+
389
+set +o xtrace
390
+echo "*********************************************************************"
391
+echo "SUCCESS: End DevStack Exercise: $0"
392
+echo "*********************************************************************"