ChetanGaonker | 62b6404 | 2016-12-08 00:37:21 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | set -x |
| 3 | function die() { |
| 4 | local exitcode=$? |
| 5 | set +o xtrace |
| 6 | echo $@ |
| 7 | cleanup |
| 8 | exit $exitcode |
| 9 | } |
| 10 | |
| 11 | net_name=cord-vtn-net1 |
| 12 | subnet_name=cord-vtn-subnet1 |
| 13 | port_name=cord-vtn-port1 |
| 14 | function 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 | |
| 21 | noauth_tenant_id=me |
| 22 | if [ "$1" == "noauth" ]; then |
| 23 | NOAUTH="--tenant_id $noauth_tenant_id" |
| 24 | else |
| 25 | NOAUTH= |
| 26 | fi |
| 27 | |
| 28 | echo "NOTE: User should be admin in order to perform all operations." |
| 29 | sleep 3 |
| 30 | |
| 31 | # test the CRUD of network |
| 32 | network=$net_name |
| 33 | neutron net-create $NOAUTH $network || die "fail to create network $network" |
| 34 | temp=`neutron net-list -- --name $network --fields id | wc -l` |
| 35 | echo $temp |
| 36 | if [ $temp -ne 5 ]; then |
| 37 | die "networks with name $network is not unique or found" |
| 38 | fi |
| 39 | network_id=`neutron net-list -- --name $network --fields id | tail -n 2 | head -n 1 | cut -d' ' -f 2` |
| 40 | echo "ID of network with name $network is $network_id" |
| 41 | |
| 42 | neutron net-show $network || die "fail to show network $network" |
| 43 | neutron net-show $network_id || die "fail to show network $network_id" |
| 44 | |
| 45 | neutron net-update $network --admin_state_up False || die "fail to update network $network" |
| 46 | neutron net-update $network_id --admin_state_up True || die "fail to update network $network_id" |
| 47 | |
| 48 | neutron net-list -c id -- --id fakeid || die "fail to list networks with column selection on empty list" |
| 49 | |
| 50 | # test the CRUD of subnet |
| 51 | subnet=$subnet_name |
| 52 | cidr=10.0.1.0/24 |
| 53 | neutron subnet-create $NOAUTH $network $cidr --name $subnet || die "fail to create subnet $subnet" |
| 54 | tempsubnet=`neutron subnet-list -- --name $subnet --fields id | wc -l` |
| 55 | echo $tempsubnet |
| 56 | if [ $tempsubnet -ne 5 ]; then |
| 57 | die "subnets with name $subnet is not unique or found" |
| 58 | fi |
| 59 | subnet_id=`neutron subnet-list -- --name $subnet --fields id | tail -n 2 | head -n 1 | cut -d' ' -f 2` |
| 60 | echo "ID of subnet with name $subnet is $subnet_id" |
| 61 | neutron subnet-show $subnet || die "fail to show subnet $subnet" |
| 62 | neutron subnet-show $subnet_id || die "fail to show subnet $subnet_id" |
| 63 | |
| 64 | neutron subnet-update $subnet --dns_nameservers list=true 1.1.1.11 1.1.1.12 || die "fail to update subnet $subnet" |
| 65 | neutron 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 |
| 68 | port=$port_name |
| 69 | neutron port-create $NOAUTH $network --name $port || die "fail to create port $port" |
| 70 | tempport=`neutron port-list -- --name $port --fields id | wc -l` |
| 71 | echo $tempport |
| 72 | if [ $tempport -ne 5 ]; then |
| 73 | die "ports with name $port is not unique or found" |
| 74 | fi |
| 75 | port_id=`neutron port-list -- --name $port --fields id | tail -n 2 | head -n 1 | cut -d' ' -f 2` |
| 76 | echo "ID of port with name $port is $port_id" |
| 77 | neutron port-show $port || die "fail to show port $port" |
| 78 | neutron port-show $port_id || die "fail to show port $port_id" |
| 79 | neutron port-update $port --device_id deviceid1 || die "fail to update port $port" |
| 80 | neutron port-update $port_id --device_id deviceid2 || die "fail to update port $port_id" |
| 81 | neutron 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" |
| 82 | neutron port-show $port || die "fail to show port $port" |
| 83 | neutron port-show $port_id || die "fail to show port $port_id" |
| 84 | neutron port-update $port_id --no-allowed-address-pairs || die "fail to update port $port_id --no-allowed-address-pairs" |
| 85 | neutron port-show $port || die "fail to show port $port" |
| 86 | neutron port-show $port_id || die "fail to show port $port_id" |
| 87 | neutron port-delete $port_id |
| 88 | |
| 89 | # test the create port with allowed-address-pairs |
| 90 | port=$port_name |
| 91 | neutron 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" |
| 92 | tempport=`neutron port-list -- --name $port --fields id | wc -l` |
| 93 | echo $tempport |
| 94 | if [ $tempport -ne 5 ]; then |
| 95 | die "ports with name $port is not unique or found" |
| 96 | fi |
| 97 | port_id=`neutron port-list -- --name $port --fields id | tail -n 2 | head -n 1 | cut -d' ' -f 2` |
| 98 | echo "ID of port with name $port is $port_id" |
| 99 | neutron port-show $port || die "fail to show port $port" |
| 100 | neutron port-show $port_id || die "fail to show port $port_id" |
| 101 | neutron port-update $port_id --no-allowed-address-pairs || die "fail to update port $port_id --no-allowed-address-pairs" |
| 102 | neutron port-show $port_id |
| 103 | |
| 104 | # test quota commands RUD |
| 105 | DEFAULT_NETWORKS=10 |
| 106 | DEFAULT_PORTS=50 |
| 107 | tenant_id=tenant_a |
| 108 | tenant_id_b=tenant_b |
| 109 | neutron quota-update --tenant_id $tenant_id --network 30 || die "fail to update quota for tenant $tenant_id" |
| 110 | neutron quota-update --tenant_id $tenant_id_b --network 20 || die "fail to update quota for tenant $tenant_id" |
| 111 | networks=`neutron quota-list -c network -c tenant_id | grep $tenant_id | awk '{print $2}'` |
| 112 | if [ $networks -ne 30 ]; then |
| 113 | die "networks quota should be 30" |
| 114 | fi |
| 115 | networks=`neutron quota-list -c network -c tenant_id | grep $tenant_id_b | awk '{print $2}'` |
| 116 | if [ $networks -ne 20 ]; then |
| 117 | die "networks quota should be 20" |
| 118 | fi |
| 119 | networks=`neutron quota-show --tenant_id $tenant_id | grep network | awk -F'|' '{print $3}'` |
| 120 | if [ $networks -ne 30 ]; then |
| 121 | die "networks quota should be 30" |
| 122 | fi |
| 123 | neutron quota-delete --tenant_id $tenant_id || die "fail to delete quota for tenant $tenant_id" |
| 124 | networks=`neutron quota-show --tenant_id $tenant_id | grep network | awk -F'|' '{print $3}'` |
| 125 | if [ $networks -ne $DEFAULT_NETWORKS ]; then |
| 126 | die "networks quota should be $DEFAULT_NETWORKS" |
| 127 | fi |
| 128 | # update self |
| 129 | if [ "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 |
| 146 | else |
| 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" |
| 161 | fi |
| 162 | |
| 163 | cleanup |
| 164 | echo "Success! :)" |
| 165 | |