blob: 1343f115535cfbf9fa83c7528cdd375cbc647188 [file] [log] [blame]
Dan Wendlandtea23e682012-08-22 05:53:17 -07001#!/usr/bin/env bash
2#
3
Mark McClainb05c8762013-07-06 23:29:39 -04004# **neutron-adv-test.sh**
Dan Wendlandtea23e682012-08-22 05:53:17 -07005
Mark McClainb05c8762013-07-06 23:29:39 -04006# Perform integration testing of Nova and other components with Neutron.
Dan Wendlandtea23e682012-08-22 05:53:17 -07007
8echo "*********************************************************************"
9echo "Begin DevStack Exercise: $0"
10echo "*********************************************************************"
11
12# This script exits on an error so that errors don't compound and you see
Joe Gordon46400262013-06-30 04:32:27 -070013# only the first error that occurred.
Dan Wendlandtea23e682012-08-22 05:53:17 -070014
15set -o errtrace
Dean Troyer6d04fd72012-12-21 11:03:37 -060016
Dan Wendlandtea23e682012-08-22 05:53:17 -070017trap failed ERR
18failed() {
19 local r=$?
20 set +o errtrace
21 set +o xtrace
22 echo "Failed to execute"
23 echo "Starting cleanup..."
24 delete_all
25 echo "Finished cleanup"
26 exit $r
27}
28
29# Print the commands being run so that we can see the command that triggers
30# an error. It is also useful for following allowing as the install occurs.
31set -o xtrace
32
Dan Wendlandtea23e682012-08-22 05:53:17 -070033# Environment
Dean Troyer6d04fd72012-12-21 11:03:37 -060034# -----------
Dan Wendlandtea23e682012-08-22 05:53:17 -070035
36# Keep track of the current directory
37EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
38TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
39
40# Import common functions
41source $TOP_DIR/functions
42
43# Import configuration
44source $TOP_DIR/openrc
45
Mark McClainb05c8762013-07-06 23:29:39 -040046# Import neutron functions
47source $TOP_DIR/lib/neutron
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070048
Mark McClainb05c8762013-07-06 23:29:39 -040049# If neutron is not enabled we exit with exitcode 55, which means exercise is skipped.
50neutron_plugin_check_adv_test_requirements || exit 55
armando-migliaccio7c025fe2013-05-08 11:33:07 -070051
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070052# Import exercise configuration
53source $TOP_DIR/exerciserc
54
Mark McClainb05c8762013-07-06 23:29:39 -040055# Neutron Settings
Dean Troyer6d04fd72012-12-21 11:03:37 -060056# ----------------
Dan Wendlandtea23e682012-08-22 05:53:17 -070057
58TENANTS="DEMO1"
59# TODO (nati)_Test public network
60#TENANTS="DEMO1,DEMO2"
61
62PUBLIC_NAME="admin"
63DEMO1_NAME="demo1"
64DEMO2_NAME="demo2"
65
66PUBLIC_NUM_NET=1
67DEMO1_NUM_NET=1
68DEMO2_NUM_NET=2
69
70PUBLIC_NET1_CIDR="200.0.0.0/24"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070071DEMO1_NET1_CIDR="10.10.0.0/24"
72DEMO2_NET1_CIDR="10.20.0.0/24"
73DEMO2_NET2_CIDR="10.20.1.0/24"
Dan Wendlandtea23e682012-08-22 05:53:17 -070074
75PUBLIC_NET1_GATEWAY="200.0.0.1"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070076DEMO1_NET1_GATEWAY="10.10.0.1"
77DEMO2_NET1_GATEWAY="10.20.0.1"
78DEMO2_NET2_GATEWAY="10.20.1.1"
Dan Wendlandtea23e682012-08-22 05:53:17 -070079
80PUBLIC_NUM_VM=1
81DEMO1_NUM_VM=1
82DEMO2_NUM_VM=2
83
84PUBLIC_VM1_NET='admin-net1'
85DEMO1_VM1_NET='demo1-net1'
86# Multinic settings. But this is fail without nic setting in OS image
87DEMO2_VM1_NET='demo2-net1'
88DEMO2_VM2_NET='demo2-net2'
89
90PUBLIC_NUM_ROUTER=1
91DEMO1_NUM_ROUTER=1
92DEMO2_NUM_ROUTER=1
93
94PUBLIC_ROUTER1_NET="admin-net1"
95DEMO1_ROUTER1_NET="demo1-net1"
96DEMO2_ROUTER1_NET="demo2-net1"
97
Dan Wendlandtea23e682012-08-22 05:53:17 -070098KEYSTONE="keystone"
99
Dean Troyer6d04fd72012-12-21 11:03:37 -0600100# Manually create a token by querying keystone (sending JSON data). Keystone
Dan Wendlandtea23e682012-08-22 05:53:17 -0700101# returns a token and catalog of endpoints. We use python to parse the token
102# and save it.
103
104TOKEN=`keystone token-get | grep ' id ' | awk '{print $4}'`
DennyZhangacb52e52013-10-11 00:08:29 -0500105die_if_not_set $LINENO TOKEN "Keystone fail to get token"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700106
Dean Troyer6d04fd72012-12-21 11:03:37 -0600107# Various functions
108# -----------------
109
Dan Wendlandtea23e682012-08-22 05:53:17 -0700110function foreach_tenant {
111 COMMAND=$1
112 for TENANT in ${TENANTS//,/ };do
113 eval ${COMMAND//%TENANT%/$TENANT}
114 done
115}
116
117function foreach_tenant_resource {
118 COMMAND=$1
119 RESOURCE=$2
120 for TENANT in ${TENANTS//,/ };do
121 eval 'NUM=$'"${TENANT}_NUM_$RESOURCE"
122 for i in `seq $NUM`;do
123 local COMMAND_LOCAL=${COMMAND//%TENANT%/$TENANT}
124 COMMAND_LOCAL=${COMMAND_LOCAL//%NUM%/$i}
125 eval $COMMAND_LOCAL
126 done
127 done
128}
129
130function foreach_tenant_vm {
131 COMMAND=$1
132 foreach_tenant_resource "$COMMAND" 'VM'
133}
134
135function foreach_tenant_net {
136 COMMAND=$1
137 foreach_tenant_resource "$COMMAND" 'NET'
138}
139
140function get_image_id {
141 local IMAGE_ID=$(glance image-list | egrep " $DEFAULT_IMAGE_NAME " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -0500142 die_if_not_set $LINENO IMAGE_ID "Failure retrieving IMAGE_ID"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700143 echo "$IMAGE_ID"
144}
145
146function get_tenant_id {
147 local TENANT_NAME=$1
148 local TENANT_ID=`keystone tenant-list | grep " $TENANT_NAME " | head -n 1 | get_field 1`
DennyZhang23178a92013-10-22 17:07:32 -0500149 die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for $TENANT_NAME"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700150 echo "$TENANT_ID"
151}
152
153function get_user_id {
154 local USER_NAME=$1
155 local USER_ID=`keystone user-list | grep $USER_NAME | awk '{print $2}'`
DennyZhang23178a92013-10-22 17:07:32 -0500156 die_if_not_set $LINENO USER_ID "Failure retrieving USER_ID for $USER_NAME"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700157 echo "$USER_ID"
158}
159
160function get_role_id {
161 local ROLE_NAME=$1
162 local ROLE_ID=`keystone role-list | grep $ROLE_NAME | awk '{print $2}'`
DennyZhang23178a92013-10-22 17:07:32 -0500163 die_if_not_set $LINENO ROLE_ID "Failure retrieving ROLE_ID for $ROLE_NAME"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700164 echo "$ROLE_ID"
165}
166
167function get_network_id {
168 local NETWORK_NAME="$1"
Mark McClainb05c8762013-07-06 23:29:39 -0400169 local NETWORK_ID=`neutron net-list -F id -- --name=$NETWORK_NAME | awk "NR==4" | awk '{print $2}'`
Dan Wendlandtea23e682012-08-22 05:53:17 -0700170 echo $NETWORK_ID
171}
172
173function get_flavor_id {
174 local INSTANCE_TYPE=$1
175 local FLAVOR_ID=`nova flavor-list | grep $INSTANCE_TYPE | awk '{print $2}'`
DennyZhang23178a92013-10-22 17:07:32 -0500176 die_if_not_set $LINENO FLAVOR_ID "Failure retrieving FLAVOR_ID for $INSTANCE_TYPE"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700177 echo "$FLAVOR_ID"
178}
179
180function confirm_server_active {
181 local VM_UUID=$1
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700182 if ! timeout $ACTIVE_TIMEOUT sh -c "while ! nova show $VM_UUID | grep status | grep -q ACTIVE; do sleep 1; done"; then
Dean Troyer6d04fd72012-12-21 11:03:37 -0600183 echo "server '$VM_UUID' did not become active!"
184 false
185 fi
Dan Wendlandtea23e682012-08-22 05:53:17 -0700186}
187
Jakub Libosvar52a7b6e2014-01-14 18:52:51 +0100188function neutron_debug_admin {
189 local os_username=$OS_USERNAME
190 local os_tenant_id=$OS_TENANT_ID
191 source $TOP_DIR/openrc admin admin
192 neutron-debug $@
193 source $TOP_DIR/openrc $os_username $os_tenant_id
194}
195
Dan Wendlandtea23e682012-08-22 05:53:17 -0700196function add_tenant {
197 local TENANT=$1
198 local USER=$2
199
200 $KEYSTONE tenant-create --name=$TENANT
201 $KEYSTONE user-create --name=$USER --pass=${ADMIN_PASSWORD}
202
203 local USER_ID=$(get_user_id $USER)
204 local TENANT_ID=$(get_tenant_id $TENANT)
205
206 $KEYSTONE user-role-add --user-id $USER_ID --role-id $(get_role_id Member) --tenant-id $TENANT_ID
207}
208
209function remove_tenant {
210 local TENANT=$1
211 local TENANT_ID=$(get_tenant_id $TENANT)
Dan Wendlandtea23e682012-08-22 05:53:17 -0700212 $KEYSTONE tenant-delete $TENANT_ID
213}
214
215function remove_user {
216 local USER=$1
217 local USER_ID=$(get_user_id $USER)
Dan Wendlandtea23e682012-08-22 05:53:17 -0700218 $KEYSTONE user-delete $USER_ID
219}
220
Dan Wendlandtea23e682012-08-22 05:53:17 -0700221function create_tenants {
222 source $TOP_DIR/openrc admin admin
223 add_tenant demo1 demo1 demo1
224 add_tenant demo2 demo2 demo2
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700225 source $TOP_DIR/openrc demo demo
Dan Wendlandtea23e682012-08-22 05:53:17 -0700226}
227
228function delete_tenants_and_users {
229 source $TOP_DIR/openrc admin admin
230 remove_user demo1
231 remove_tenant demo1
232 remove_user demo2
233 remove_tenant demo2
234 echo "removed all tenants"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700235 source $TOP_DIR/openrc demo demo
Dan Wendlandtea23e682012-08-22 05:53:17 -0700236}
237
238function create_network {
239 local TENANT=$1
240 local GATEWAY=$2
241 local CIDR=$3
242 local NUM=$4
243 local EXTRA=$5
244 local NET_NAME="${TENANT}-net$NUM"
245 local ROUTER_NAME="${TENANT}-router${NUM}"
246 source $TOP_DIR/openrc admin admin
247 local TENANT_ID=$(get_tenant_id $TENANT)
248 source $TOP_DIR/openrc $TENANT $TENANT
Dean Troyer526b79f2013-11-22 11:30:44 -0600249 local NET_ID=$(neutron net-create --tenant-id $TENANT_ID $NET_NAME $EXTRA| grep ' id ' | awk '{print $4}' )
DennyZhang23178a92013-10-22 17:07:32 -0500250 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $TENANT_ID $NET_NAME $EXTRA"
Dean Troyer526b79f2013-11-22 11:30:44 -0600251 neutron subnet-create --ip-version 4 --tenant-id $TENANT_ID --gateway $GATEWAY $NET_ID $CIDR
Jakub Libosvar52a7b6e2014-01-14 18:52:51 +0100252 neutron_debug_admin probe-create --device-owner compute $NET_ID
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700253 source $TOP_DIR/openrc demo demo
Dan Wendlandtea23e682012-08-22 05:53:17 -0700254}
255
256function create_networks {
257 foreach_tenant_net 'create_network ${%TENANT%_NAME} ${%TENANT%_NET%NUM%_GATEWAY} ${%TENANT%_NET%NUM%_CIDR} %NUM% ${%TENANT%_NET%NUM%_EXTRA}'
258 #TODO(nati) test security group function
259 # allow ICMP for both tenant's security groups
260 #source $TOP_DIR/openrc demo1 demo1
261 #$NOVA secgroup-add-rule default icmp -1 -1 0.0.0.0/0
262 #source $TOP_DIR/openrc demo2 demo2
263 #$NOVA secgroup-add-rule default icmp -1 -1 0.0.0.0/0
264}
265
266function create_vm {
267 local TENANT=$1
268 local NUM=$2
269 local NET_NAMES=$3
270 source $TOP_DIR/openrc $TENANT $TENANT
271 local NIC=""
272 for NET_NAME in ${NET_NAMES//,/ };do
273 NIC="$NIC --nic net-id="`get_network_id $NET_NAME`
274 done
275 #TODO (nati) Add multi-nic test
276 #TODO (nati) Add public-net test
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700277 local VM_UUID=`nova boot --flavor $(get_flavor_id m1.tiny) \
Dan Wendlandtea23e682012-08-22 05:53:17 -0700278 --image $(get_image_id) \
279 $NIC \
280 $TENANT-server$NUM | grep ' id ' | cut -d"|" -f3 | sed 's/ //g'`
Nachi Ueno07115eb2013-02-26 12:38:18 -0800281 die_if_not_set $LINENO VM_UUID "Failure launching $TENANT-server$NUM"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700282 confirm_server_active $VM_UUID
283}
284
285function create_vms {
286 foreach_tenant_vm 'create_vm ${%TENANT%_NAME} %NUM% ${%TENANT%_VM%NUM%_NET}'
287}
288
289function ping_ip {
Sean Dague922c8ae2013-10-22 10:06:06 -0400290 # Test agent connection. Assumes namespaces are disabled, and
291 # that DHCP is in use, but not L3
292 local VM_NAME=$1
293 local NET_NAME=$2
294 IP=$(get_instance_ip $VM_NAME $NET_NAME)
295 ping_check $NET_NAME $IP $BOOT_TIMEOUT
Dan Wendlandtea23e682012-08-22 05:53:17 -0700296}
297
298function check_vm {
299 local TENANT=$1
300 local NUM=$2
301 local VM_NAME="$TENANT-server$NUM"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700302 local NET_NAME=$3
Dan Wendlandtea23e682012-08-22 05:53:17 -0700303 source $TOP_DIR/openrc $TENANT $TENANT
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700304 ping_ip $VM_NAME $NET_NAME
Dan Wendlandtea23e682012-08-22 05:53:17 -0700305 # TODO (nati) test ssh connection
306 # TODO (nati) test inter connection between vm
Dan Wendlandtea23e682012-08-22 05:53:17 -0700307 # TODO (nati) test dhcp host routes
308 # TODO (nati) test multi-nic
Dan Wendlandtea23e682012-08-22 05:53:17 -0700309}
310
311function check_vms {
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700312 foreach_tenant_vm 'check_vm ${%TENANT%_NAME} %NUM% ${%TENANT%_VM%NUM%_NET}'
Dan Wendlandtea23e682012-08-22 05:53:17 -0700313}
314
315function shutdown_vm {
316 local TENANT=$1
317 local NUM=$2
318 source $TOP_DIR/openrc $TENANT $TENANT
319 VM_NAME=${TENANT}-server$NUM
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700320 nova delete $VM_NAME
Dan Wendlandtea23e682012-08-22 05:53:17 -0700321}
322
323function shutdown_vms {
324 foreach_tenant_vm 'shutdown_vm ${%TENANT%_NAME} %NUM%'
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700325 if ! timeout $TERMINATE_TIMEOUT sh -c "while nova list | grep -q ACTIVE; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800326 die $LINENO "Some VMs failed to shutdown"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700327 fi
328}
329
330function delete_network {
331 local TENANT=$1
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700332 local NUM=$2
333 local NET_NAME="${TENANT}-net$NUM"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700334 source $TOP_DIR/openrc admin admin
335 local TENANT_ID=$(get_tenant_id $TENANT)
336 #TODO(nati) comment out until l3-agent merged
337 #for res in port subnet net router;do
Mark McClainb05c8762013-07-06 23:29:39 -0400338 for net_id in `neutron net-list -c id -c name | grep $NET_NAME | awk '{print $2}'`;do
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700339 delete_probe $net_id
Mark McClainb05c8762013-07-06 23:29:39 -0400340 neutron subnet-list | grep $net_id | awk '{print $2}' | xargs -I% neutron subnet-delete %
341 neutron net-delete $net_id
Dan Wendlandtea23e682012-08-22 05:53:17 -0700342 done
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700343 source $TOP_DIR/openrc demo demo
Dan Wendlandtea23e682012-08-22 05:53:17 -0700344}
345
346function delete_networks {
Sean Dague922c8ae2013-10-22 10:06:06 -0400347 foreach_tenant_net 'delete_network ${%TENANT%_NAME} %NUM%'
348 # TODO(nati) add secuirty group check after it is implemented
349 # source $TOP_DIR/openrc demo1 demo1
350 # nova secgroup-delete-rule default icmp -1 -1 0.0.0.0/0
351 # source $TOP_DIR/openrc demo2 demo2
352 # nova secgroup-delete-rule default icmp -1 -1 0.0.0.0/0
Dan Wendlandtea23e682012-08-22 05:53:17 -0700353}
354
355function create_all {
356 create_tenants
357 create_networks
358 create_vms
359}
360
361function delete_all {
362 shutdown_vms
363 delete_networks
364 delete_tenants_and_users
365}
366
367function all {
368 create_all
369 check_vms
370 delete_all
371}
372
Dean Troyer6d04fd72012-12-21 11:03:37 -0600373# Test functions
374# --------------
375
Dan Wendlandtea23e682012-08-22 05:53:17 -0700376function test_functions {
377 IMAGE=$(get_image_id)
378 echo $IMAGE
379
380 TENANT_ID=$(get_tenant_id demo)
381 echo $TENANT_ID
382
383 FLAVOR_ID=$(get_flavor_id m1.tiny)
384 echo $FLAVOR_ID
385
386 NETWORK_ID=$(get_network_id admin)
387 echo $NETWORK_ID
388}
389
Dean Troyer6d04fd72012-12-21 11:03:37 -0600390# Usage and main
391# --------------
392
Dan Wendlandtea23e682012-08-22 05:53:17 -0700393usage() {
394 echo "$0: [-h]"
395 echo " -h, --help Display help message"
396 echo " -t, --tenant Create tenants"
397 echo " -n, --net Create networks"
398 echo " -v, --vm Create vms"
399 echo " -c, --check Check connection"
400 echo " -x, --delete-tenants Delete tenants"
401 echo " -y, --delete-nets Delete networks"
402 echo " -z, --delete-vms Delete vms"
403 echo " -T, --test Test functions"
404}
405
406main() {
407
408 echo Description
409 echo
410 echo Copyright 2012, Cisco Systems
armando-migliaccio05952e32014-01-05 07:59:06 -0800411 echo Copyright 2012, VMware, Inc.
Dan Wendlandtea23e682012-08-22 05:53:17 -0700412 echo Copyright 2012, NTT MCL, Inc.
413 echo
armando-migliaccio05952e32014-01-05 07:59:06 -0800414 echo Please direct any questions to dedutta@cisco.com, dwendlandt@vmware.com, nachi@nttmcl.com
Dan Wendlandtea23e682012-08-22 05:53:17 -0700415 echo
416
417
418 if [ $# -eq 0 ] ; then
419 # if no args are provided, run all tests
420 all
421 else
422
423 while [ "$1" != "" ]; do
424 case $1 in
425 -h | --help ) usage
426 exit
427 ;;
428 -n | --net ) create_networks
429 exit
430 ;;
431 -v | --vm ) create_vms
432 exit
433 ;;
434 -t | --tenant ) create_tenants
435 exit
436 ;;
437 -c | --check ) check_vms
438 exit
439 ;;
440 -T | --test ) test_functions
441 exit
442 ;;
443 -x | --delete-tenants ) delete_tenants_and_users
444 exit
445 ;;
446 -y | --delete-nets ) delete_networks
447 exit
448 ;;
449 -z | --delete-vms ) shutdown_vms
450 exit
451 ;;
452 -a | --all ) all
453 exit
454 ;;
455 * ) usage
456 exit 1
457 esac
458 shift
459 done
460 fi
461}
462
Dean Troyer6d04fd72012-12-21 11:03:37 -0600463# Kick off script
464# ---------------
Dan Wendlandtea23e682012-08-22 05:53:17 -0700465
Dan Wendlandtea23e682012-08-22 05:53:17 -0700466echo $*
467main $*
468
469set +o xtrace
470echo "*********************************************************************"
471echo "SUCCESS: End DevStack Exercise: $0"
472echo "*********************************************************************"