blob: a3128a8d71179988e9ee8ac0b95aa8f288220dac [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
Sean Dague7580a0c2016-02-17 06:23:36 -050051PROJECTS="DEMO1"
Dan Wendlandtea23e682012-08-22 05:53:17 -070052# TODO (nati)_Test public network
Sean Dague7580a0c2016-02-17 06:23:36 -050053#PROJECTS="DEMO1,DEMO2"
Dan Wendlandtea23e682012-08-22 05:53:17 -070054
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
Sean Dague7580a0c2016-02-17 06:23:36 -050094function foreach_project {
Dan Wendlandtea23e682012-08-22 05:53:17 -070095 COMMAND=$1
Sean Dague7580a0c2016-02-17 06:23:36 -050096 for PROJECT in ${PROJECTS//,/ };do
97 eval ${COMMAND//%PROJECT%/$PROJECT}
Dan Wendlandtea23e682012-08-22 05:53:17 -070098 done
99}
100
Sean Dague7580a0c2016-02-17 06:23:36 -0500101function foreach_project_resource {
Dan Wendlandtea23e682012-08-22 05:53:17 -0700102 COMMAND=$1
103 RESOURCE=$2
Sean Dague7580a0c2016-02-17 06:23:36 -0500104 for PROJECT in ${PROJECTS//,/ };do
105 eval 'NUM=$'"${PROJECT}_NUM_$RESOURCE"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700106 for i in `seq $NUM`;do
Sean Dague7580a0c2016-02-17 06:23:36 -0500107 local COMMAND_LOCAL=${COMMAND//%PROJECT%/$PROJECT}
Dan Wendlandtea23e682012-08-22 05:53:17 -0700108 COMMAND_LOCAL=${COMMAND_LOCAL//%NUM%/$i}
109 eval $COMMAND_LOCAL
110 done
111 done
112}
113
Sean Dague7580a0c2016-02-17 06:23:36 -0500114function foreach_project_vm {
Dan Wendlandtea23e682012-08-22 05:53:17 -0700115 COMMAND=$1
Sean Dague7580a0c2016-02-17 06:23:36 -0500116 foreach_project_resource "$COMMAND" 'VM'
Dan Wendlandtea23e682012-08-22 05:53:17 -0700117}
118
Sean Dague7580a0c2016-02-17 06:23:36 -0500119function foreach_project_net {
Dan Wendlandtea23e682012-08-22 05:53:17 -0700120 COMMAND=$1
Sean Dague7580a0c2016-02-17 06:23:36 -0500121 foreach_project_resource "$COMMAND" 'NET'
Dan Wendlandtea23e682012-08-22 05:53:17 -0700122}
123
124function get_image_id {
Ian Wienandada886d2015-10-07 14:06:26 +1100125 local IMAGE_ID
126 IMAGE_ID=$(openstack image list | egrep " $DEFAULT_IMAGE_NAME " | get_field 1)
DennyZhang23178a92013-10-22 17:07:32 -0500127 die_if_not_set $LINENO IMAGE_ID "Failure retrieving IMAGE_ID"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700128 echo "$IMAGE_ID"
129}
130
Sean Dague7580a0c2016-02-17 06:23:36 -0500131function get_project_id {
132 local PROJECT_NAME=$1
133 local PROJECT_ID
134 PROJECT_ID=`openstack project list | grep " $PROJECT_NAME " | head -n 1 | get_field 1`
135 die_if_not_set $LINENO PROJECT_ID "Failure retrieving PROJECT_ID for $PROJECT_NAME"
136 echo "$PROJECT_ID"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700137}
138
139function get_user_id {
140 local USER_NAME=$1
Ian Wienandada886d2015-10-07 14:06:26 +1100141 local USER_ID
142 USER_ID=`openstack user list | grep $USER_NAME | awk '{print $2}'`
DennyZhang23178a92013-10-22 17:07:32 -0500143 die_if_not_set $LINENO USER_ID "Failure retrieving USER_ID for $USER_NAME"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700144 echo "$USER_ID"
145}
146
147function get_role_id {
148 local ROLE_NAME=$1
Ian Wienandada886d2015-10-07 14:06:26 +1100149 local ROLE_ID
150 ROLE_ID=`openstack role list | grep $ROLE_NAME | awk '{print $2}'`
DennyZhang23178a92013-10-22 17:07:32 -0500151 die_if_not_set $LINENO ROLE_ID "Failure retrieving ROLE_ID for $ROLE_NAME"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700152 echo "$ROLE_ID"
153}
154
155function get_network_id {
156 local NETWORK_NAME="$1"
Ian Wienandada886d2015-10-07 14:06:26 +1100157 local NETWORK_ID
158 NETWORK_ID=`neutron net-list -F id -- --name=$NETWORK_NAME | awk "NR==4" | awk '{print $2}'`
Dan Wendlandtea23e682012-08-22 05:53:17 -0700159 echo $NETWORK_ID
160}
161
162function get_flavor_id {
163 local INSTANCE_TYPE=$1
Ian Wienandada886d2015-10-07 14:06:26 +1100164 local FLAVOR_ID
165 FLAVOR_ID=`nova flavor-list | grep $INSTANCE_TYPE | awk '{print $2}'`
DennyZhang23178a92013-10-22 17:07:32 -0500166 die_if_not_set $LINENO FLAVOR_ID "Failure retrieving FLAVOR_ID for $INSTANCE_TYPE"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700167 echo "$FLAVOR_ID"
168}
169
170function confirm_server_active {
171 local VM_UUID=$1
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700172 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 -0600173 echo "server '$VM_UUID' did not become active!"
174 false
175 fi
Dan Wendlandtea23e682012-08-22 05:53:17 -0700176}
177
Jakub Libosvar52a7b6e2014-01-14 18:52:51 +0100178function neutron_debug_admin {
179 local os_username=$OS_USERNAME
Sean Dague7580a0c2016-02-17 06:23:36 -0500180 local os_project_id=$OS_PROJECT_ID
Jakub Libosvar52a7b6e2014-01-14 18:52:51 +0100181 source $TOP_DIR/openrc admin admin
182 neutron-debug $@
Sean Dague7580a0c2016-02-17 06:23:36 -0500183 source $TOP_DIR/openrc $os_username $os_project_id
Jakub Libosvar52a7b6e2014-01-14 18:52:51 +0100184}
185
Sean Dague7580a0c2016-02-17 06:23:36 -0500186function add_project {
Steve Martinelli2a09d0c2014-03-14 00:33:58 -0500187 openstack project create $1
188 openstack user create $2 --password ${ADMIN_PASSWORD} --project $1
189 openstack role add Member --project $1 --user $2
Dan Wendlandtea23e682012-08-22 05:53:17 -0700190}
191
Sean Dague7580a0c2016-02-17 06:23:36 -0500192function remove_project {
193 local PROJECT=$1
194 local PROJECT_ID
195 PROJECT_ID=$(get_project_id $PROJECT)
196 openstack project delete $PROJECT_ID
Dan Wendlandtea23e682012-08-22 05:53:17 -0700197}
198
199function remove_user {
200 local USER=$1
Ian Wienandada886d2015-10-07 14:06:26 +1100201 local USER_ID
202 USER_ID=$(get_user_id $USER)
Steve Martinelli2a09d0c2014-03-14 00:33:58 -0500203 openstack user delete $USER_ID
Dan Wendlandtea23e682012-08-22 05:53:17 -0700204}
205
Sean Dague7580a0c2016-02-17 06:23:36 -0500206function create_projects {
Dan Wendlandtea23e682012-08-22 05:53:17 -0700207 source $TOP_DIR/openrc admin admin
Sean Dague7580a0c2016-02-17 06:23:36 -0500208 add_project demo1 demo1 demo1
209 add_project demo2 demo2 demo2
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700210 source $TOP_DIR/openrc demo demo
Dan Wendlandtea23e682012-08-22 05:53:17 -0700211}
212
Sean Dague7580a0c2016-02-17 06:23:36 -0500213function delete_projects_and_users {
Dan Wendlandtea23e682012-08-22 05:53:17 -0700214 source $TOP_DIR/openrc admin admin
215 remove_user demo1
Sean Dague7580a0c2016-02-17 06:23:36 -0500216 remove_project demo1
Dan Wendlandtea23e682012-08-22 05:53:17 -0700217 remove_user demo2
Sean Dague7580a0c2016-02-17 06:23:36 -0500218 remove_project demo2
219 echo "removed all projects"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700220 source $TOP_DIR/openrc demo demo
Dan Wendlandtea23e682012-08-22 05:53:17 -0700221}
222
223function create_network {
Sean Dague7580a0c2016-02-17 06:23:36 -0500224 local PROJECT=$1
Dan Wendlandtea23e682012-08-22 05:53:17 -0700225 local GATEWAY=$2
226 local CIDR=$3
227 local NUM=$4
228 local EXTRA=$5
Sean Dague7580a0c2016-02-17 06:23:36 -0500229 local NET_NAME="${PROJECT}-net$NUM"
230 local ROUTER_NAME="${PROJECT}-router${NUM}"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700231 source $TOP_DIR/openrc admin admin
Sean Dague7580a0c2016-02-17 06:23:36 -0500232 local PROJECT_ID
233 PROJECT_ID=$(get_project_id $PROJECT)
234 source $TOP_DIR/openrc $PROJECT $PROJECT
Ian Wienandada886d2015-10-07 14:06:26 +1100235 local NET_ID
Sean Dague7580a0c2016-02-17 06:23:36 -0500236 NET_ID=$(neutron net-create --project-id $PROJECT_ID $NET_NAME $EXTRA| grep ' id ' | awk '{print $4}' )
237 die_if_not_set $LINENO NET_ID "Failure creating NET_ID for $PROJECT_ID $NET_NAME $EXTRA"
238 neutron subnet-create --ip-version 4 --project-id $PROJECT_ID --gateway $GATEWAY --subnetpool None $NET_ID $CIDR
Jakub Libosvar52a7b6e2014-01-14 18:52:51 +0100239 neutron_debug_admin probe-create --device-owner compute $NET_ID
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700240 source $TOP_DIR/openrc demo demo
Dan Wendlandtea23e682012-08-22 05:53:17 -0700241}
242
243function create_networks {
Sean Dague7580a0c2016-02-17 06:23:36 -0500244 foreach_project_net 'create_network ${%PROJECT%_NAME} ${%PROJECT%_NET%NUM%_GATEWAY} ${%PROJECT%_NET%NUM%_CIDR} %NUM% ${%PROJECT%_NET%NUM%_EXTRA}'
Dan Wendlandtea23e682012-08-22 05:53:17 -0700245 #TODO(nati) test security group function
Sean Dague7580a0c2016-02-17 06:23:36 -0500246 # allow ICMP for both project's security groups
Dan Wendlandtea23e682012-08-22 05:53:17 -0700247 #source $TOP_DIR/openrc demo1 demo1
248 #$NOVA secgroup-add-rule default icmp -1 -1 0.0.0.0/0
249 #source $TOP_DIR/openrc demo2 demo2
250 #$NOVA secgroup-add-rule default icmp -1 -1 0.0.0.0/0
251}
252
253function create_vm {
Sean Dague7580a0c2016-02-17 06:23:36 -0500254 local PROJECT=$1
Dan Wendlandtea23e682012-08-22 05:53:17 -0700255 local NUM=$2
256 local NET_NAMES=$3
Sean Dague7580a0c2016-02-17 06:23:36 -0500257 source $TOP_DIR/openrc $PROJECT $PROJECT
Dan Wendlandtea23e682012-08-22 05:53:17 -0700258 local NIC=""
259 for NET_NAME in ${NET_NAMES//,/ };do
260 NIC="$NIC --nic net-id="`get_network_id $NET_NAME`
261 done
262 #TODO (nati) Add multi-nic test
263 #TODO (nati) Add public-net test
Ian Wienandada886d2015-10-07 14:06:26 +1100264 local VM_UUID
265 VM_UUID=`nova boot --flavor $(get_flavor_id m1.tiny) \
Dan Wendlandtea23e682012-08-22 05:53:17 -0700266 --image $(get_image_id) \
267 $NIC \
Sean Dague7580a0c2016-02-17 06:23:36 -0500268 $PROJECT-server$NUM | grep ' id ' | cut -d"|" -f3 | sed 's/ //g'`
269 die_if_not_set $LINENO VM_UUID "Failure launching $PROJECT-server$NUM"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700270 confirm_server_active $VM_UUID
271}
272
273function create_vms {
Sean Dague7580a0c2016-02-17 06:23:36 -0500274 foreach_project_vm 'create_vm ${%PROJECT%_NAME} %NUM% ${%PROJECT%_VM%NUM%_NET}'
Dan Wendlandtea23e682012-08-22 05:53:17 -0700275}
276
277function ping_ip {
Sean Dague922c8ae2013-10-22 10:06:06 -0400278 # Test agent connection. Assumes namespaces are disabled, and
279 # that DHCP is in use, but not L3
280 local VM_NAME=$1
281 local NET_NAME=$2
282 IP=$(get_instance_ip $VM_NAME $NET_NAME)
Sean Dagueaf9bf862015-04-16 08:58:32 -0400283 ping_check $IP $BOOT_TIMEOUT $NET_NAME
Dan Wendlandtea23e682012-08-22 05:53:17 -0700284}
285
286function check_vm {
Sean Dague7580a0c2016-02-17 06:23:36 -0500287 local PROJECT=$1
Dan Wendlandtea23e682012-08-22 05:53:17 -0700288 local NUM=$2
Sean Dague7580a0c2016-02-17 06:23:36 -0500289 local VM_NAME="$PROJECT-server$NUM"
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700290 local NET_NAME=$3
Sean Dague7580a0c2016-02-17 06:23:36 -0500291 source $TOP_DIR/openrc $PROJECT $PROJECT
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700292 ping_ip $VM_NAME $NET_NAME
Dan Wendlandtea23e682012-08-22 05:53:17 -0700293 # TODO (nati) test ssh connection
294 # TODO (nati) test inter connection between vm
Dan Wendlandtea23e682012-08-22 05:53:17 -0700295 # TODO (nati) test dhcp host routes
296 # TODO (nati) test multi-nic
Dan Wendlandtea23e682012-08-22 05:53:17 -0700297}
298
299function check_vms {
Sean Dague7580a0c2016-02-17 06:23:36 -0500300 foreach_project_vm 'check_vm ${%PROJECT%_NAME} %NUM% ${%PROJECT%_VM%NUM%_NET}'
Dan Wendlandtea23e682012-08-22 05:53:17 -0700301}
302
303function shutdown_vm {
Sean Dague7580a0c2016-02-17 06:23:36 -0500304 local PROJECT=$1
Dan Wendlandtea23e682012-08-22 05:53:17 -0700305 local NUM=$2
Sean Dague7580a0c2016-02-17 06:23:36 -0500306 source $TOP_DIR/openrc $PROJECT $PROJECT
307 VM_NAME=${PROJECT}-server$NUM
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700308 nova delete $VM_NAME
Dan Wendlandtea23e682012-08-22 05:53:17 -0700309}
310
311function shutdown_vms {
Sean Dague7580a0c2016-02-17 06:23:36 -0500312 foreach_project_vm 'shutdown_vm ${%PROJECT%_NAME} %NUM%'
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700313 if ! timeout $TERMINATE_TIMEOUT sh -c "while nova list | grep -q ACTIVE; do sleep 1; done"; then
Nachi Ueno07115eb2013-02-26 12:38:18 -0800314 die $LINENO "Some VMs failed to shutdown"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700315 fi
316}
317
318function delete_network {
Sean Dague7580a0c2016-02-17 06:23:36 -0500319 local PROJECT=$1
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700320 local NUM=$2
Sean Dague7580a0c2016-02-17 06:23:36 -0500321 local NET_NAME="${PROJECT}-net$NUM"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700322 source $TOP_DIR/openrc admin admin
Sean Dague7580a0c2016-02-17 06:23:36 -0500323 local PROJECT_ID
324 PROJECT_ID=$(get_project_id $PROJECT)
Dan Wendlandtea23e682012-08-22 05:53:17 -0700325 #TODO(nati) comment out until l3-agent merged
326 #for res in port subnet net router;do
Mark McClainb05c8762013-07-06 23:29:39 -0400327 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 -0700328 delete_probe $net_id
Mark McClainb05c8762013-07-06 23:29:39 -0400329 neutron subnet-list | grep $net_id | awk '{print $2}' | xargs -I% neutron subnet-delete %
330 neutron net-delete $net_id
Dan Wendlandtea23e682012-08-22 05:53:17 -0700331 done
Nachi Ueno5db5bfa2012-10-29 11:25:29 -0700332 source $TOP_DIR/openrc demo demo
Dan Wendlandtea23e682012-08-22 05:53:17 -0700333}
334
335function delete_networks {
Sean Dague7580a0c2016-02-17 06:23:36 -0500336 foreach_project_net 'delete_network ${%PROJECT%_NAME} %NUM%'
Sean Dague922c8ae2013-10-22 10:06:06 -0400337 # TODO(nati) add secuirty group check after it is implemented
338 # source $TOP_DIR/openrc demo1 demo1
339 # nova secgroup-delete-rule default icmp -1 -1 0.0.0.0/0
340 # source $TOP_DIR/openrc demo2 demo2
341 # nova secgroup-delete-rule default icmp -1 -1 0.0.0.0/0
Dan Wendlandtea23e682012-08-22 05:53:17 -0700342}
343
344function create_all {
Sean Dague7580a0c2016-02-17 06:23:36 -0500345 create_projects
Dan Wendlandtea23e682012-08-22 05:53:17 -0700346 create_networks
347 create_vms
348}
349
350function delete_all {
351 shutdown_vms
352 delete_networks
Sean Dague7580a0c2016-02-17 06:23:36 -0500353 delete_projects_and_users
Dan Wendlandtea23e682012-08-22 05:53:17 -0700354}
355
356function all {
357 create_all
358 check_vms
359 delete_all
360}
361
Dean Troyer6d04fd72012-12-21 11:03:37 -0600362# Test functions
363# --------------
364
Dan Wendlandtea23e682012-08-22 05:53:17 -0700365function test_functions {
366 IMAGE=$(get_image_id)
367 echo $IMAGE
368
Sean Dague7580a0c2016-02-17 06:23:36 -0500369 PROJECT_ID=$(get_project_id demo)
370 echo $PROJECT_ID
Dan Wendlandtea23e682012-08-22 05:53:17 -0700371
372 FLAVOR_ID=$(get_flavor_id m1.tiny)
373 echo $FLAVOR_ID
374
375 NETWORK_ID=$(get_network_id admin)
376 echo $NETWORK_ID
377}
378
Dean Troyer6d04fd72012-12-21 11:03:37 -0600379# Usage and main
380# --------------
381
Ian Wienandaee18c72014-02-21 15:35:08 +1100382function usage {
Dan Wendlandtea23e682012-08-22 05:53:17 -0700383 echo "$0: [-h]"
384 echo " -h, --help Display help message"
Sean Dague7580a0c2016-02-17 06:23:36 -0500385 echo " -t, --project Create projects"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700386 echo " -n, --net Create networks"
387 echo " -v, --vm Create vms"
388 echo " -c, --check Check connection"
Sean Dague7580a0c2016-02-17 06:23:36 -0500389 echo " -x, --delete-projects Delete projects"
Dan Wendlandtea23e682012-08-22 05:53:17 -0700390 echo " -y, --delete-nets Delete networks"
391 echo " -z, --delete-vms Delete vms"
392 echo " -T, --test Test functions"
393}
394
Ian Wienandaee18c72014-02-21 15:35:08 +1100395function main {
Dan Wendlandtea23e682012-08-22 05:53:17 -0700396
397 echo Description
Dan Wendlandtea23e682012-08-22 05:53:17 -0700398
399 if [ $# -eq 0 ] ; then
400 # if no args are provided, run all tests
401 all
402 else
403
404 while [ "$1" != "" ]; do
405 case $1 in
406 -h | --help ) usage
407 exit
408 ;;
409 -n | --net ) create_networks
410 exit
411 ;;
412 -v | --vm ) create_vms
413 exit
414 ;;
Sean Dague7580a0c2016-02-17 06:23:36 -0500415 -t | --project ) create_projects
Dan Wendlandtea23e682012-08-22 05:53:17 -0700416 exit
417 ;;
418 -c | --check ) check_vms
419 exit
420 ;;
421 -T | --test ) test_functions
422 exit
423 ;;
Sean Dague7580a0c2016-02-17 06:23:36 -0500424 -x | --delete-projects ) delete_projects_and_users
Dan Wendlandtea23e682012-08-22 05:53:17 -0700425 exit
426 ;;
427 -y | --delete-nets ) delete_networks
428 exit
429 ;;
430 -z | --delete-vms ) shutdown_vms
431 exit
432 ;;
433 -a | --all ) all
434 exit
435 ;;
436 * ) usage
437 exit 1
438 esac
439 shift
440 done
441 fi
442}
443
Ian Wienand04c0f0b2015-06-30 13:47:51 +1000444trap failed ERR
445function failed {
446 local r=$?
447 set +o errtrace
448 set +o xtrace
449 echo "Failed to execute"
450 echo "Starting cleanup..."
451 delete_all
452 echo "Finished cleanup"
453 exit $r
454}
455
Dean Troyer6d04fd72012-12-21 11:03:37 -0600456# Kick off script
457# ---------------
Dan Wendlandtea23e682012-08-22 05:53:17 -0700458
Dan Wendlandtea23e682012-08-22 05:53:17 -0700459echo $*
460main $*
461
462set +o xtrace
463echo "*********************************************************************"
464echo "SUCCESS: End DevStack Exercise: $0"
465echo "*********************************************************************"