blob: af35e3a0d1d278be087e90c85d053e67ec8dd2dd [file] [log] [blame]
ChetanGaonker62b64042016-12-08 00:37:21 -08001#!/bin/bash
2set -x
3function die() {
4 local exitcode=$?
5 set +o xtrace
6 echo $@
7 cleanup
8 exit $exitcode
9}
10
11net_name=cord-vtn-net1
12subnet_name=cord-vtn-subnet1
13port_name=cord-vtn-port1
14function cleanup() {
15 echo Removing test port, subnet and net...
16 neutron port-delete $port_name
17 neutron subnet-delete $subnet_name
18 neutron net-delete $net_name
19}
20
21noauth_tenant_id=me
22if [ "$1" == "noauth" ]; then
23 NOAUTH="--tenant_id $noauth_tenant_id"
24else
25 NOAUTH=
26fi
27
28echo "NOTE: User should be admin in order to perform all operations."
29sleep 3
30
31# test the CRUD of network
32network=$net_name
33neutron net-create $NOAUTH $network || die "fail to create network $network"
34temp=`neutron net-list -- --name $network --fields id | wc -l`
35echo $temp
36if [ $temp -ne 5 ]; then
37 die "networks with name $network is not unique or found"
38fi
39network_id=`neutron net-list -- --name $network --fields id | tail -n 2 | head -n 1 | cut -d' ' -f 2`
40echo "ID of network with name $network is $network_id"
41
42neutron net-show $network || die "fail to show network $network"
43neutron net-show $network_id || die "fail to show network $network_id"
44
45neutron net-update $network --admin_state_up False || die "fail to update network $network"
46neutron net-update $network_id --admin_state_up True || die "fail to update network $network_id"
47
48neutron net-list -c id -- --id fakeid || die "fail to list networks with column selection on empty list"
49
50# test the CRUD of subnet
51subnet=$subnet_name
52cidr=10.0.1.0/24
53neutron subnet-create $NOAUTH $network $cidr --name $subnet || die "fail to create subnet $subnet"
54tempsubnet=`neutron subnet-list -- --name $subnet --fields id | wc -l`
55echo $tempsubnet
56if [ $tempsubnet -ne 5 ]; then
57 die "subnets with name $subnet is not unique or found"
58fi
59subnet_id=`neutron subnet-list -- --name $subnet --fields id | tail -n 2 | head -n 1 | cut -d' ' -f 2`
60echo "ID of subnet with name $subnet is $subnet_id"
61neutron subnet-show $subnet || die "fail to show subnet $subnet"
62neutron subnet-show $subnet_id || die "fail to show subnet $subnet_id"
63
64neutron subnet-update $subnet --dns_nameservers list=true 1.1.1.11 1.1.1.12 || die "fail to update subnet $subnet"
65neutron subnet-update $subnet_id --dns_nameservers list=true 2.2.2.21 2.2.2.22 || die "fail to update subnet $subnet_id"
66
67# test the crud of ports
68port=$port_name
69neutron port-create $NOAUTH $network --name $port || die "fail to create port $port"
70tempport=`neutron port-list -- --name $port --fields id | wc -l`
71echo $tempport
72if [ $tempport -ne 5 ]; then
73 die "ports with name $port is not unique or found"
74fi
75port_id=`neutron port-list -- --name $port --fields id | tail -n 2 | head -n 1 | cut -d' ' -f 2`
76echo "ID of port with name $port is $port_id"
77neutron port-show $port || die "fail to show port $port"
78neutron port-show $port_id || die "fail to show port $port_id"
79neutron port-update $port --device_id deviceid1 || die "fail to update port $port"
80neutron port-update $port_id --device_id deviceid2 || die "fail to update port $port_id"
81neutron port-update $port_id --allowed-address-pair ip_address=1.1.1.11,mac_address=10:00:00:00:00:00 --allowed-address-pair ip_address=1.1.1.12,mac_address=10:00:00:00:00:01 || die "fail to update port $port_id --allowed-address-pair"
82neutron port-show $port || die "fail to show port $port"
83neutron port-show $port_id || die "fail to show port $port_id"
84neutron port-update $port_id --no-allowed-address-pairs || die "fail to update port $port_id --no-allowed-address-pairs"
85neutron port-show $port || die "fail to show port $port"
86neutron port-show $port_id || die "fail to show port $port_id"
87neutron port-delete $port_id
88
89# test the create port with allowed-address-pairs
90port=$port_name
91neutron port-create $NOAUTH $network --name $port -- --allowed-address-pairs type=dict list=true ip_address=1.1.1.11,mac_address=10:00:00:00:00:00 ip_address=1.1.1.12,mac_address=10:00:00:00:00:01 || die "fail to create port $port"
92tempport=`neutron port-list -- --name $port --fields id | wc -l`
93echo $tempport
94if [ $tempport -ne 5 ]; then
95 die "ports with name $port is not unique or found"
96fi
97port_id=`neutron port-list -- --name $port --fields id | tail -n 2 | head -n 1 | cut -d' ' -f 2`
98echo "ID of port with name $port is $port_id"
99neutron port-show $port || die "fail to show port $port"
100neutron port-show $port_id || die "fail to show port $port_id"
101neutron port-update $port_id --no-allowed-address-pairs || die "fail to update port $port_id --no-allowed-address-pairs"
102neutron port-show $port_id
103
104# test quota commands RUD
105DEFAULT_NETWORKS=10
106DEFAULT_PORTS=50
107tenant_id=tenant_a
108tenant_id_b=tenant_b
109neutron quota-update --tenant_id $tenant_id --network 30 || die "fail to update quota for tenant $tenant_id"
110neutron quota-update --tenant_id $tenant_id_b --network 20 || die "fail to update quota for tenant $tenant_id"
111networks=`neutron quota-list -c network -c tenant_id | grep $tenant_id | awk '{print $2}'`
112if [ $networks -ne 30 ]; then
113 die "networks quota should be 30"
114fi
115networks=`neutron quota-list -c network -c tenant_id | grep $tenant_id_b | awk '{print $2}'`
116if [ $networks -ne 20 ]; then
117 die "networks quota should be 20"
118fi
119networks=`neutron quota-show --tenant_id $tenant_id | grep network | awk -F'|' '{print $3}'`
120if [ $networks -ne 30 ]; then
121 die "networks quota should be 30"
122fi
123neutron quota-delete --tenant_id $tenant_id || die "fail to delete quota for tenant $tenant_id"
124networks=`neutron quota-show --tenant_id $tenant_id | grep network | awk -F'|' '{print $3}'`
125if [ $networks -ne $DEFAULT_NETWORKS ]; then
126 die "networks quota should be $DEFAULT_NETWORKS"
127fi
128# update self
129if [ "t$NOAUTH" = "t" ]; then
130 # with auth
131 neutron quota-update --port 99 || die "fail to update quota for self"
132 ports=`neutron quota-show | grep port | awk -F'|' '{print $3}'`
133 if [ $ports -ne 99 ]; then
134 die "ports quota should be 99"
135 fi
136
137 ports=`neutron quota-list -c port | grep 99 | awk '{print $2}'`
138 if [ $ports -ne 99 ]; then
139 die "ports quota should be 99"
140 fi
141 neutron quota-delete || die "fail to delete quota for tenant self"
142 ports=`neutron quota-show | grep port | awk -F'|' '{print $3}'`
143 if [ $ports -ne $DEFAULT_PORTS ]; then
144 die "ports quota should be $DEFAULT_PORTS"
145 fi
146else
147 # without auth
148 neutron quota-update --port 100
149 if [ $? -eq 0 ]; then
150 die "without valid context on server, quota update command should fail."
151 fi
152 neutron quota-show
153 if [ $? -eq 0 ]; then
154 die "without valid context on server, quota show command should fail."
155 fi
156 neutron quota-delete
157 if [ $? -eq 0 ]; then
158 die "without valid context on server, quota delete command should fail."
159 fi
160 neutron quota-list || die "fail to update quota for self"
161fi
162
163cleanup
164echo "Success! :)"
165