blob: 0c0d42f45811695deeef0e3f364d97106ee355cc [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
188function add_tenant {
189 local TENANT=$1
190 local USER=$2
191
192 $KEYSTONE tenant-create --name=$TENANT
193 $KEYSTONE user-create --name=$USER --pass=${ADMIN_PASSWORD}
194
195 local USER_ID=$(get_user_id $USER)
196 local TENANT_ID=$(get_tenant_id $TENANT)
197
198 $KEYSTONE user-role-add --user-id $USER_ID --role-id $(get_role_id Member) --tenant-id $TENANT_ID
199}
200
201function remove_tenant {
202 local TENANT=$1
203 local TENANT_ID=$(get_tenant_id $TENANT)
Dan Wendlandtea23e682012-08-22 05:53:17 -0700204 $KEYSTONE tenant-delete $TENANT_ID
205}
206
207function remove_user {
208 local USER=$1
209 local USER_ID=$(get_user_id $USER)
Dan Wendlandtea23e682012-08-22 05:53:17 -0700210 $KEYSTONE user-delete $USER_ID
211}
212
Dan Wendlandtea23e682012-08-22 05:53:17 -0700213function create_tenants {
214 source $TOP_DIR/openrc admin admin
215 add_tenant demo1 demo1 demo1
216 add_tenant demo2 demo2 demo2
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700217 source $TOP_DIR/openrc demo demo
Dan Wendlandtea23e682012-08-22 05:53:17 -0700218}
219
220function delete_tenants_and_users {
221 source $TOP_DIR/openrc admin admin
222 remove_user demo1
223 remove_tenant demo1
224 remove_user demo2
225 remove_tenant demo2
226 echo "removed all tenants"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700227 source $TOP_DIR/openrc demo demo
Dan Wendlandtea23e682012-08-22 05:53:17 -0700228}
229
230function create_network {
231 local TENANT=$1
232 local GATEWAY=$2
233 local CIDR=$3
234 local NUM=$4
235 local EXTRA=$5
236 local NET_NAME="${TENANT}-net$NUM"
237 local ROUTER_NAME="${TENANT}-router${NUM}"
238 source $TOP_DIR/openrc admin admin
239 local TENANT_ID=$(get_tenant_id $TENANT)
240 source $TOP_DIR/openrc $TENANT $TENANT
Dean Troyer526b79f2013-11-22 11:30:44 -0600241 local NET_ID=$(neutron net-create --tenant-id $TENANT_ID $NET_NAME $EXTRA| grep ' id ' | awk '{print $4}' )
DennyZhang23178a92013-10-22 17:07:32 -0500242 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $TENANT_ID $NET_NAME $EXTRA"
Dean Troyer526b79f2013-11-22 11:30:44 -0600243 neutron subnet-create --ip-version 4 --tenant-id $TENANT_ID --gateway $GATEWAY $NET_ID $CIDR
Mark McClainb05c8762013-07-06 23:29:39 -0400244 neutron-debug probe-create --device-owner compute $NET_ID
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700245 source $TOP_DIR/openrc demo demo
Dan Wendlandtea23e682012-08-22 05:53:17 -0700246}
247
248function create_networks {
249 foreach_tenant_net 'create_network ${%TENANT%_NAME} ${%TENANT%_NET%NUM%_GATEWAY} ${%TENANT%_NET%NUM%_CIDR} %NUM% ${%TENANT%_NET%NUM%_EXTRA}'
250 #TODO(nati) test security group function
251 # allow ICMP for both tenant's security groups
252 #source $TOP_DIR/openrc demo1 demo1
253 #$NOVA secgroup-add-rule default icmp -1 -1 0.0.0.0/0
254 #source $TOP_DIR/openrc demo2 demo2
255 #$NOVA secgroup-add-rule default icmp -1 -1 0.0.0.0/0
256}
257
258function create_vm {
259 local TENANT=$1
260 local NUM=$2
261 local NET_NAMES=$3
262 source $TOP_DIR/openrc $TENANT $TENANT
263 local NIC=""
264 for NET_NAME in ${NET_NAMES//,/ };do
265 NIC="$NIC --nic net-id="`get_network_id $NET_NAME`
266 done
267 #TODO (nati) Add multi-nic test
268 #TODO (nati) Add public-net test
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700269 local VM_UUID=`nova boot --flavor $(get_flavor_id m1.tiny) \
Dan Wendlandtea23e682012-08-22 05:53:17 -0700270 --image $(get_image_id) \
271 $NIC \
272 $TENANT-server$NUM | grep ' id ' | cut -d"|" -f3 | sed 's/ //g'`
Nachi Ueno07115eb2013-02-26 12:38:18 -0800273 die_if_not_set $LINENO VM_UUID "Failure launching $TENANT-server$NUM"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700274 confirm_server_active $VM_UUID
275}
276
277function create_vms {
278 foreach_tenant_vm 'create_vm ${%TENANT%_NAME} %NUM% ${%TENANT%_VM%NUM%_NET}'
279}
280
281function ping_ip {
Sean Dague922c8ae2013-10-22 10:06:06 -0400282 # Test agent connection. Assumes namespaces are disabled, and
283 # that DHCP is in use, but not L3
284 local VM_NAME=$1
285 local NET_NAME=$2
286 IP=$(get_instance_ip $VM_NAME $NET_NAME)
287 ping_check $NET_NAME $IP $BOOT_TIMEOUT
Dan Wendlandtea23e682012-08-22 05:53:17 -0700288}
289
290function check_vm {
291 local TENANT=$1
292 local NUM=$2
293 local VM_NAME="$TENANT-server$NUM"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700294 local NET_NAME=$3
Dan Wendlandtea23e682012-08-22 05:53:17 -0700295 source $TOP_DIR/openrc $TENANT $TENANT
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700296 ping_ip $VM_NAME $NET_NAME
Dan Wendlandtea23e682012-08-22 05:53:17 -0700297 # TODO (nati) test ssh connection
298 # TODO (nati) test inter connection between vm
Dan Wendlandtea23e682012-08-22 05:53:17 -0700299 # TODO (nati) test dhcp host routes
300 # TODO (nati) test multi-nic
Dan Wendlandtea23e682012-08-22 05:53:17 -0700301}
302
303function check_vms {
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700304 foreach_tenant_vm 'check_vm ${%TENANT%_NAME} %NUM% ${%TENANT%_VM%NUM%_NET}'
Dan Wendlandtea23e682012-08-22 05:53:17 -0700305}
306
307function shutdown_vm {
308 local TENANT=$1
309 local NUM=$2
310 source $TOP_DIR/openrc $TENANT $TENANT
311 VM_NAME=${TENANT}-server$NUM
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700312 nova delete $VM_NAME
Dan Wendlandtea23e682012-08-22 05:53:17 -0700313}
314
315function shutdown_vms {
316 foreach_tenant_vm 'shutdown_vm ${%TENANT%_NAME} %NUM%'
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700317 if ! timeout $TERMINATE_TIMEOUT sh -c "while nova list | grep -q ACTIVE; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800318 die $LINENO "Some VMs failed to shutdown"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700319 fi
320}
321
322function delete_network {
323 local TENANT=$1
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700324 local NUM=$2
325 local NET_NAME="${TENANT}-net$NUM"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700326 source $TOP_DIR/openrc admin admin
327 local TENANT_ID=$(get_tenant_id $TENANT)
328 #TODO(nati) comment out until l3-agent merged
329 #for res in port subnet net router;do
Mark McClainb05c8762013-07-06 23:29:39 -0400330 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 -0700331 delete_probe $net_id
Mark McClainb05c8762013-07-06 23:29:39 -0400332 neutron subnet-list | grep $net_id | awk '{print $2}' | xargs -I% neutron subnet-delete %
333 neutron net-delete $net_id
Dan Wendlandtea23e682012-08-22 05:53:17 -0700334 done
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700335 source $TOP_DIR/openrc demo demo
Dan Wendlandtea23e682012-08-22 05:53:17 -0700336}
337
338function delete_networks {
Sean Dague922c8ae2013-10-22 10:06:06 -0400339 foreach_tenant_net 'delete_network ${%TENANT%_NAME} %NUM%'
340 # TODO(nati) add secuirty group check after it is implemented
341 # source $TOP_DIR/openrc demo1 demo1
342 # nova secgroup-delete-rule default icmp -1 -1 0.0.0.0/0
343 # source $TOP_DIR/openrc demo2 demo2
344 # nova secgroup-delete-rule default icmp -1 -1 0.0.0.0/0
Dan Wendlandtea23e682012-08-22 05:53:17 -0700345}
346
347function create_all {
348 create_tenants
349 create_networks
350 create_vms
351}
352
353function delete_all {
354 shutdown_vms
355 delete_networks
356 delete_tenants_and_users
357}
358
359function all {
360 create_all
361 check_vms
362 delete_all
363}
364
Dean Troyer6d04fd72012-12-21 11:03:37 -0600365# Test functions
366# --------------
367
Dan Wendlandtea23e682012-08-22 05:53:17 -0700368function test_functions {
369 IMAGE=$(get_image_id)
370 echo $IMAGE
371
372 TENANT_ID=$(get_tenant_id demo)
373 echo $TENANT_ID
374
375 FLAVOR_ID=$(get_flavor_id m1.tiny)
376 echo $FLAVOR_ID
377
378 NETWORK_ID=$(get_network_id admin)
379 echo $NETWORK_ID
380}
381
Dean Troyer6d04fd72012-12-21 11:03:37 -0600382# Usage and main
383# --------------
384
Dan Wendlandtea23e682012-08-22 05:53:17 -0700385usage() {
386 echo "$0: [-h]"
387 echo " -h, --help Display help message"
388 echo " -t, --tenant Create tenants"
389 echo " -n, --net Create networks"
390 echo " -v, --vm Create vms"
391 echo " -c, --check Check connection"
392 echo " -x, --delete-tenants Delete tenants"
393 echo " -y, --delete-nets Delete networks"
394 echo " -z, --delete-vms Delete vms"
395 echo " -T, --test Test functions"
396}
397
398main() {
399
400 echo Description
401 echo
402 echo Copyright 2012, Cisco Systems
armando-migliaccio05952e32014-01-05 07:59:06 -0800403 echo Copyright 2012, VMware, Inc.
Dan Wendlandtea23e682012-08-22 05:53:17 -0700404 echo Copyright 2012, NTT MCL, Inc.
405 echo
armando-migliaccio05952e32014-01-05 07:59:06 -0800406 echo Please direct any questions to dedutta@cisco.com, dwendlandt@vmware.com, nachi@nttmcl.com
Dan Wendlandtea23e682012-08-22 05:53:17 -0700407 echo
408
409
410 if [ $# -eq 0 ] ; then
411 # if no args are provided, run all tests
412 all
413 else
414
415 while [ "$1" != "" ]; do
416 case $1 in
417 -h | --help ) usage
418 exit
419 ;;
420 -n | --net ) create_networks
421 exit
422 ;;
423 -v | --vm ) create_vms
424 exit
425 ;;
426 -t | --tenant ) create_tenants
427 exit
428 ;;
429 -c | --check ) check_vms
430 exit
431 ;;
432 -T | --test ) test_functions
433 exit
434 ;;
435 -x | --delete-tenants ) delete_tenants_and_users
436 exit
437 ;;
438 -y | --delete-nets ) delete_networks
439 exit
440 ;;
441 -z | --delete-vms ) shutdown_vms
442 exit
443 ;;
444 -a | --all ) all
445 exit
446 ;;
447 * ) usage
448 exit 1
449 esac
450 shift
451 done
452 fi
453}
454
Dean Troyer6d04fd72012-12-21 11:03:37 -0600455# Kick off script
456# ---------------
Dan Wendlandtea23e682012-08-22 05:53:17 -0700457
Dan Wendlandtea23e682012-08-22 05:53:17 -0700458echo $*
459main $*
460
461set +o xtrace
462echo "*********************************************************************"
463echo "SUCCESS: End DevStack Exercise: $0"
464echo "*********************************************************************"