blob: a0de4ccd37c9a3a3c669205a6cc79eacda18e260 [file] [log] [blame]
Dan Wendlandtea23e682012-08-22 05:53:17 -07001#!/usr/bin/env bash
2#
Anita Kuno0d4bd7e2014-02-02 14:59:39 -06003# Copyright 2012, Cisco Systems
4# Copyright 2012, VMware, Inc.
5# Copyright 2012, NTT MCL, Inc.
6#
7# Please direct any questions to dedutta@cisco.com, dwendlandt@vmware.com, nachi@nttmcl.com
8#
Mark McClainb05c8762013-07-06 23:29:39 -04009# **neutron-adv-test.sh**
Dan Wendlandtea23e682012-08-22 05:53:17 -070010
Mark McClainb05c8762013-07-06 23:29:39 -040011# Perform integration testing of Nova and other components with Neutron.
Dan Wendlandtea23e682012-08-22 05:53:17 -070012
13echo "*********************************************************************"
14echo "Begin DevStack Exercise: $0"
15echo "*********************************************************************"
16
17# This script exits on an error so that errors don't compound and you see
Joe Gordon46400262013-06-30 04:32:27 -070018# only the first error that occurred.
Dan Wendlandtea23e682012-08-22 05:53:17 -070019
20set -o errtrace
Dean Troyer6d04fd72012-12-21 11:03:37 -060021
Dan Wendlandtea23e682012-08-22 05:53:17 -070022# Print the commands being run so that we can see the command that triggers
23# an error. It is also useful for following allowing as the install occurs.
24set -o xtrace
25
Dan Wendlandtea23e682012-08-22 05:53:17 -070026# Environment
Dean Troyer6d04fd72012-12-21 11:03:37 -060027# -----------
Dan Wendlandtea23e682012-08-22 05:53:17 -070028
29# Keep track of the current directory
30EXERCISE_DIR=$(cd $(dirname "$0") && pwd)
31TOP_DIR=$(cd $EXERCISE_DIR/..; pwd)
32
33# Import common functions
34source $TOP_DIR/functions
35
36# Import configuration
37source $TOP_DIR/openrc
38
Mark McClainb05c8762013-07-06 23:29:39 -040039# Import neutron functions
Dean Troyer5a9739a2015-03-25 11:33:51 -050040source $TOP_DIR/lib/neutron-legacy
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070041
Mark McClainb05c8762013-07-06 23:29:39 -040042# If neutron is not enabled we exit with exitcode 55, which means exercise is skipped.
43neutron_plugin_check_adv_test_requirements || exit 55
armando-migliaccio7c025fe2013-05-08 11:33:07 -070044
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070045# Import exercise configuration
46source $TOP_DIR/exerciserc
47
Mark McClainb05c8762013-07-06 23:29:39 -040048# Neutron Settings
Dean Troyer6d04fd72012-12-21 11:03:37 -060049# ----------------
Dan Wendlandtea23e682012-08-22 05:53:17 -070050
51TENANTS="DEMO1"
52# TODO (nati)_Test public network
53#TENANTS="DEMO1,DEMO2"
54
55PUBLIC_NAME="admin"
56DEMO1_NAME="demo1"
57DEMO2_NAME="demo2"
58
59PUBLIC_NUM_NET=1
60DEMO1_NUM_NET=1
61DEMO2_NUM_NET=2
62
63PUBLIC_NET1_CIDR="200.0.0.0/24"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070064DEMO1_NET1_CIDR="10.10.0.0/24"
65DEMO2_NET1_CIDR="10.20.0.0/24"
66DEMO2_NET2_CIDR="10.20.1.0/24"
Dan Wendlandtea23e682012-08-22 05:53:17 -070067
68PUBLIC_NET1_GATEWAY="200.0.0.1"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -070069DEMO1_NET1_GATEWAY="10.10.0.1"
70DEMO2_NET1_GATEWAY="10.20.0.1"
71DEMO2_NET2_GATEWAY="10.20.1.1"
Dan Wendlandtea23e682012-08-22 05:53:17 -070072
73PUBLIC_NUM_VM=1
74DEMO1_NUM_VM=1
75DEMO2_NUM_VM=2
76
77PUBLIC_VM1_NET='admin-net1'
78DEMO1_VM1_NET='demo1-net1'
79# Multinic settings. But this is fail without nic setting in OS image
80DEMO2_VM1_NET='demo2-net1'
81DEMO2_VM2_NET='demo2-net2'
82
83PUBLIC_NUM_ROUTER=1
84DEMO1_NUM_ROUTER=1
85DEMO2_NUM_ROUTER=1
86
87PUBLIC_ROUTER1_NET="admin-net1"
88DEMO1_ROUTER1_NET="demo1-net1"
89DEMO2_ROUTER1_NET="demo2-net1"
90
Dean Troyer6d04fd72012-12-21 11:03:37 -060091# Various functions
92# -----------------
93
Dan Wendlandtea23e682012-08-22 05:53:17 -070094function foreach_tenant {
95 COMMAND=$1
96 for TENANT in ${TENANTS//,/ };do
97 eval ${COMMAND//%TENANT%/$TENANT}
98 done
99}
100
101function foreach_tenant_resource {
102 COMMAND=$1
103 RESOURCE=$2
104 for TENANT in ${TENANTS//,/ };do
105 eval 'NUM=$'"${TENANT}_NUM_$RESOURCE"
106 for i in `seq $NUM`;do
107 local COMMAND_LOCAL=${COMMAND//%TENANT%/$TENANT}
108 COMMAND_LOCAL=${COMMAND_LOCAL//%NUM%/$i}
109 eval $COMMAND_LOCAL
110 done
111 done
112}
113
114function foreach_tenant_vm {
115 COMMAND=$1
116 foreach_tenant_resource "$COMMAND" 'VM'
117}
118
119function foreach_tenant_net {
120 COMMAND=$1
121 foreach_tenant_resource "$COMMAND" 'NET'
122}
123
124function get_image_id {
Steve Martinelli5c206c22014-08-02 20:32:31 -0400125 local IMAGE_ID=$(openstack image list | egrep " $DEFAULT_IMAGE_NAME " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -0500126 die_if_not_set $LINENO IMAGE_ID "Failure retrieving IMAGE_ID"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700127 echo "$IMAGE_ID"
128}
129
130function get_tenant_id {
131 local TENANT_NAME=$1
Steve Martinelli2a09d0c2014-03-14 00:33:58 -0500132 local TENANT_ID=`openstack project list | grep " $TENANT_NAME " | head -n 1 | get_field 1`
DennyZhang23178a92013-10-22 17:07:32 -0500133 die_if_not_set $LINENO TENANT_ID "Failure retrieving TENANT_ID for $TENANT_NAME"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700134 echo "$TENANT_ID"
135}
136
137function get_user_id {
138 local USER_NAME=$1
Steve Martinelli2a09d0c2014-03-14 00:33:58 -0500139 local USER_ID=`openstack user list | grep $USER_NAME | awk '{print $2}'`
DennyZhang23178a92013-10-22 17:07:32 -0500140 die_if_not_set $LINENO USER_ID "Failure retrieving USER_ID for $USER_NAME"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700141 echo "$USER_ID"
142}
143
144function get_role_id {
145 local ROLE_NAME=$1
Steve Martinelli2a09d0c2014-03-14 00:33:58 -0500146 local ROLE_ID=`openstack role list | grep $ROLE_NAME | awk '{print $2}'`
DennyZhang23178a92013-10-22 17:07:32 -0500147 die_if_not_set $LINENO ROLE_ID "Failure retrieving ROLE_ID for $ROLE_NAME"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700148 echo "$ROLE_ID"
149}
150
151function get_network_id {
152 local NETWORK_NAME="$1"
Mark McClainb05c8762013-07-06 23:29:39 -0400153 local NETWORK_ID=`neutron net-list -F id -- --name=$NETWORK_NAME | awk "NR==4" | awk '{print $2}'`
Dan Wendlandtea23e682012-08-22 05:53:17 -0700154 echo $NETWORK_ID
155}
156
157function get_flavor_id {
158 local INSTANCE_TYPE=$1
159 local FLAVOR_ID=`nova flavor-list | grep $INSTANCE_TYPE | awk '{print $2}'`
DennyZhang23178a92013-10-22 17:07:32 -0500160 die_if_not_set $LINENO FLAVOR_ID "Failure retrieving FLAVOR_ID for $INSTANCE_TYPE"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700161 echo "$FLAVOR_ID"
162}
163
164function confirm_server_active {
165 local VM_UUID=$1
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700166 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 -0600167 echo "server '$VM_UUID' did not become active!"
168 false
169 fi
Dan Wendlandtea23e682012-08-22 05:53:17 -0700170}
171
Jakub Libosvar52a7b6e2014-01-14 18:52:51 +0100172function neutron_debug_admin {
173 local os_username=$OS_USERNAME
174 local os_tenant_id=$OS_TENANT_ID
175 source $TOP_DIR/openrc admin admin
176 neutron-debug $@
177 source $TOP_DIR/openrc $os_username $os_tenant_id
178}
179
Dan Wendlandtea23e682012-08-22 05:53:17 -0700180function add_tenant {
Steve Martinelli2a09d0c2014-03-14 00:33:58 -0500181 openstack project create $1
182 openstack user create $2 --password ${ADMIN_PASSWORD} --project $1
183 openstack role add Member --project $1 --user $2
Dan Wendlandtea23e682012-08-22 05:53:17 -0700184}
185
186function remove_tenant {
187 local TENANT=$1
188 local TENANT_ID=$(get_tenant_id $TENANT)
Steve Martinelli2a09d0c2014-03-14 00:33:58 -0500189 openstack project delete $TENANT_ID
Dan Wendlandtea23e682012-08-22 05:53:17 -0700190}
191
192function remove_user {
193 local USER=$1
194 local USER_ID=$(get_user_id $USER)
Steve Martinelli2a09d0c2014-03-14 00:33:58 -0500195 openstack user delete $USER_ID
Dan Wendlandtea23e682012-08-22 05:53:17 -0700196}
197
Dan Wendlandtea23e682012-08-22 05:53:17 -0700198function create_tenants {
199 source $TOP_DIR/openrc admin admin
200 add_tenant demo1 demo1 demo1
201 add_tenant demo2 demo2 demo2
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700202 source $TOP_DIR/openrc demo demo
Dan Wendlandtea23e682012-08-22 05:53:17 -0700203}
204
205function delete_tenants_and_users {
206 source $TOP_DIR/openrc admin admin
207 remove_user demo1
208 remove_tenant demo1
209 remove_user demo2
210 remove_tenant demo2
211 echo "removed all tenants"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700212 source $TOP_DIR/openrc demo demo
Dan Wendlandtea23e682012-08-22 05:53:17 -0700213}
214
215function create_network {
216 local TENANT=$1
217 local GATEWAY=$2
218 local CIDR=$3
219 local NUM=$4
220 local EXTRA=$5
221 local NET_NAME="${TENANT}-net$NUM"
222 local ROUTER_NAME="${TENANT}-router${NUM}"
223 source $TOP_DIR/openrc admin admin
224 local TENANT_ID=$(get_tenant_id $TENANT)
225 source $TOP_DIR/openrc $TENANT $TENANT
Dean Troyer526b79f2013-11-22 11:30:44 -0600226 local NET_ID=$(neutron net-create --tenant-id $TENANT_ID $NET_NAME $EXTRA| grep ' id ' | awk '{print $4}' )
DennyZhang23178a92013-10-22 17:07:32 -0500227 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $TENANT_ID $NET_NAME $EXTRA"
Dean Troyer526b79f2013-11-22 11:30:44 -0600228 neutron subnet-create --ip-version 4 --tenant-id $TENANT_ID --gateway $GATEWAY $NET_ID $CIDR
Jakub Libosvar52a7b6e2014-01-14 18:52:51 +0100229 neutron_debug_admin probe-create --device-owner compute $NET_ID
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700230 source $TOP_DIR/openrc demo demo
Dan Wendlandtea23e682012-08-22 05:53:17 -0700231}
232
233function create_networks {
234 foreach_tenant_net 'create_network ${%TENANT%_NAME} ${%TENANT%_NET%NUM%_GATEWAY} ${%TENANT%_NET%NUM%_CIDR} %NUM% ${%TENANT%_NET%NUM%_EXTRA}'
235 #TODO(nati) test security group function
236 # allow ICMP for both tenant's security groups
237 #source $TOP_DIR/openrc demo1 demo1
238 #$NOVA secgroup-add-rule default icmp -1 -1 0.0.0.0/0
239 #source $TOP_DIR/openrc demo2 demo2
240 #$NOVA secgroup-add-rule default icmp -1 -1 0.0.0.0/0
241}
242
243function create_vm {
244 local TENANT=$1
245 local NUM=$2
246 local NET_NAMES=$3
247 source $TOP_DIR/openrc $TENANT $TENANT
248 local NIC=""
249 for NET_NAME in ${NET_NAMES//,/ };do
250 NIC="$NIC --nic net-id="`get_network_id $NET_NAME`
251 done
252 #TODO (nati) Add multi-nic test
253 #TODO (nati) Add public-net test
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700254 local VM_UUID=`nova boot --flavor $(get_flavor_id m1.tiny) \
Dan Wendlandtea23e682012-08-22 05:53:17 -0700255 --image $(get_image_id) \
256 $NIC \
257 $TENANT-server$NUM | grep ' id ' | cut -d"|" -f3 | sed 's/ //g'`
Nachi Ueno07115eb2013-02-26 12:38:18 -0800258 die_if_not_set $LINENO VM_UUID "Failure launching $TENANT-server$NUM"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700259 confirm_server_active $VM_UUID
260}
261
262function create_vms {
263 foreach_tenant_vm 'create_vm ${%TENANT%_NAME} %NUM% ${%TENANT%_VM%NUM%_NET}'
264}
265
266function ping_ip {
Sean Dague922c8ae2013-10-22 10:06:06 -0400267 # Test agent connection. Assumes namespaces are disabled, and
268 # that DHCP is in use, but not L3
269 local VM_NAME=$1
270 local NET_NAME=$2
271 IP=$(get_instance_ip $VM_NAME $NET_NAME)
Sean Dagueaf9bf862015-04-16 08:58:32 -0400272 ping_check $IP $BOOT_TIMEOUT $NET_NAME
Dan Wendlandtea23e682012-08-22 05:53:17 -0700273}
274
275function check_vm {
276 local TENANT=$1
277 local NUM=$2
278 local VM_NAME="$TENANT-server$NUM"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700279 local NET_NAME=$3
Dan Wendlandtea23e682012-08-22 05:53:17 -0700280 source $TOP_DIR/openrc $TENANT $TENANT
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700281 ping_ip $VM_NAME $NET_NAME
Dan Wendlandtea23e682012-08-22 05:53:17 -0700282 # TODO (nati) test ssh connection
283 # TODO (nati) test inter connection between vm
Dan Wendlandtea23e682012-08-22 05:53:17 -0700284 # TODO (nati) test dhcp host routes
285 # TODO (nati) test multi-nic
Dan Wendlandtea23e682012-08-22 05:53:17 -0700286}
287
288function check_vms {
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700289 foreach_tenant_vm 'check_vm ${%TENANT%_NAME} %NUM% ${%TENANT%_VM%NUM%_NET}'
Dan Wendlandtea23e682012-08-22 05:53:17 -0700290}
291
292function shutdown_vm {
293 local TENANT=$1
294 local NUM=$2
295 source $TOP_DIR/openrc $TENANT $TENANT
296 VM_NAME=${TENANT}-server$NUM
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700297 nova delete $VM_NAME
Dan Wendlandtea23e682012-08-22 05:53:17 -0700298}
299
300function shutdown_vms {
301 foreach_tenant_vm 'shutdown_vm ${%TENANT%_NAME} %NUM%'
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700302 if ! timeout $TERMINATE_TIMEOUT sh -c "while nova list | grep -q ACTIVE; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800303 die $LINENO "Some VMs failed to shutdown"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700304 fi
305}
306
307function delete_network {
308 local TENANT=$1
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700309 local NUM=$2
310 local NET_NAME="${TENANT}-net$NUM"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700311 source $TOP_DIR/openrc admin admin
312 local TENANT_ID=$(get_tenant_id $TENANT)
313 #TODO(nati) comment out until l3-agent merged
314 #for res in port subnet net router;do
Mark McClainb05c8762013-07-06 23:29:39 -0400315 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 -0700316 delete_probe $net_id
Mark McClainb05c8762013-07-06 23:29:39 -0400317 neutron subnet-list | grep $net_id | awk '{print $2}' | xargs -I% neutron subnet-delete %
318 neutron net-delete $net_id
Dan Wendlandtea23e682012-08-22 05:53:17 -0700319 done
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700320 source $TOP_DIR/openrc demo demo
Dan Wendlandtea23e682012-08-22 05:53:17 -0700321}
322
323function delete_networks {
Sean Dague922c8ae2013-10-22 10:06:06 -0400324 foreach_tenant_net 'delete_network ${%TENANT%_NAME} %NUM%'
325 # TODO(nati) add secuirty group check after it is implemented
326 # source $TOP_DIR/openrc demo1 demo1
327 # nova secgroup-delete-rule default icmp -1 -1 0.0.0.0/0
328 # source $TOP_DIR/openrc demo2 demo2
329 # nova secgroup-delete-rule default icmp -1 -1 0.0.0.0/0
Dan Wendlandtea23e682012-08-22 05:53:17 -0700330}
331
332function create_all {
333 create_tenants
334 create_networks
335 create_vms
336}
337
338function delete_all {
339 shutdown_vms
340 delete_networks
341 delete_tenants_and_users
342}
343
344function all {
345 create_all
346 check_vms
347 delete_all
348}
349
Dean Troyer6d04fd72012-12-21 11:03:37 -0600350# Test functions
351# --------------
352
Dan Wendlandtea23e682012-08-22 05:53:17 -0700353function test_functions {
354 IMAGE=$(get_image_id)
355 echo $IMAGE
356
357 TENANT_ID=$(get_tenant_id demo)
358 echo $TENANT_ID
359
360 FLAVOR_ID=$(get_flavor_id m1.tiny)
361 echo $FLAVOR_ID
362
363 NETWORK_ID=$(get_network_id admin)
364 echo $NETWORK_ID
365}
366
Dean Troyer6d04fd72012-12-21 11:03:37 -0600367# Usage and main
368# --------------
369
Ian Wienandaee18c72014-02-21 15:35:08 +1100370function usage {
Dan Wendlandtea23e682012-08-22 05:53:17 -0700371 echo "$0: [-h]"
372 echo " -h, --help Display help message"
373 echo " -t, --tenant Create tenants"
374 echo " -n, --net Create networks"
375 echo " -v, --vm Create vms"
376 echo " -c, --check Check connection"
377 echo " -x, --delete-tenants Delete tenants"
378 echo " -y, --delete-nets Delete networks"
379 echo " -z, --delete-vms Delete vms"
380 echo " -T, --test Test functions"
381}
382
Ian Wienandaee18c72014-02-21 15:35:08 +1100383function main {
Dan Wendlandtea23e682012-08-22 05:53:17 -0700384
385 echo Description
Dan Wendlandtea23e682012-08-22 05:53:17 -0700386
387 if [ $# -eq 0 ] ; then
388 # if no args are provided, run all tests
389 all
390 else
391
392 while [ "$1" != "" ]; do
393 case $1 in
394 -h | --help ) usage
395 exit
396 ;;
397 -n | --net ) create_networks
398 exit
399 ;;
400 -v | --vm ) create_vms
401 exit
402 ;;
403 -t | --tenant ) create_tenants
404 exit
405 ;;
406 -c | --check ) check_vms
407 exit
408 ;;
409 -T | --test ) test_functions
410 exit
411 ;;
412 -x | --delete-tenants ) delete_tenants_and_users
413 exit
414 ;;
415 -y | --delete-nets ) delete_networks
416 exit
417 ;;
418 -z | --delete-vms ) shutdown_vms
419 exit
420 ;;
421 -a | --all ) all
422 exit
423 ;;
424 * ) usage
425 exit 1
426 esac
427 shift
428 done
429 fi
430}
431
Ian Wienand04c0f0b2015-06-30 13:47:51 +1000432trap failed ERR
433function failed {
434 local r=$?
435 set +o errtrace
436 set +o xtrace
437 echo "Failed to execute"
438 echo "Starting cleanup..."
439 delete_all
440 echo "Finished cleanup"
441 exit $r
442}
443
Dean Troyer6d04fd72012-12-21 11:03:37 -0600444# Kick off script
445# ---------------
Dan Wendlandtea23e682012-08-22 05:53:17 -0700446
Dan Wendlandtea23e682012-08-22 05:53:17 -0700447echo $*
448main $*
449
450set +o xtrace
451echo "*********************************************************************"
452echo "SUCCESS: End DevStack Exercise: $0"
453echo "*********************************************************************"