Skip to content

Commit 8ad0351

Browse files
dduttasleepsonthefloor
authored andcommitted
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
1 parent dac6e76 commit 8ad0351

File tree

1 file changed

+393
-0
lines changed

1 file changed

+393
-0
lines changed

exercises/quantum.sh

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

0 commit comments

Comments
 (0)