Nikolay Pliashechnykov | 316823e | 2020-08-14 15:44:50 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | #A simple integration test that will allow you to check whether the LBaaS 2.0 integration is working on your cloud. |
| 4 | #May require some minor tuning depending on the LB provider (i.e. specifying flavor, order of listener/pool creation etc) |
| 5 | #Requires a project, permissive security group, tenant network, floating network, keypair and image/flavor to start the VM. |
| 6 | |
| 7 | #Testing of the load balancing is still manual. Start the test in screen, wait until the LB is up and then test it in another tab. |
| 8 | IMAGE=6d989e06-493f-4f2d-9d07-81650fd04581 |
| 9 | FLAVOR=dfa1ecac-e8a9-408a-b93c-75077272e10e |
| 10 | NETWORK=5435a882-32f0-4abf-b1f6-3f942f85c3e7 |
| 11 | FIP_NET=ee84f06b-be00-4295-a27a-4c6653e960ef |
| 12 | KEY=qa-lb-kp |
| 13 | SGID=008f8c20-133c-4ff8-9ae0-5d8de301b3e7 |
| 14 | PROTO=TCP |
| 15 | PORT=22 |
| 16 | LBNAME=qa-testlb |
| 17 | echo "Spawning the pool VMs" |
| 18 | openstack server create lb-1 --image ${IMAGE} --flavor ${FLAVOR} --key ${KEY} --nic net-id=${NETWORK} --security-group ${SGID} |
| 19 | openstack server create lb-2 --image ${IMAGE} --flavor ${FLAVOR} --key ${KEY} --nic net-id=${NETWORK} --security-group ${SGID} |
| 20 | openstack server create lb-3 --image ${IMAGE} --flavor ${FLAVOR} --key ${KEY} --nic net-id=${NETWORK} --security-group ${SGID} |
| 21 | echo "Obtaining the service subnet ID" |
| 22 | SUBNET=`openstack network show ${NETWORK} | grep subnets | awk '{print $4}'` |
| 23 | echo "Creating the load balancer" |
| 24 | neutron lbaas-loadbalancer-create --name ${LBNAME} ${SUBNET} |
| 25 | LB=`neutron lbaas-loadbalancer-list | grep ${LBNAME} | awk '{print $2}'` |
| 26 | echo "Obtaining the LB VIP port and adding the permissive security group" |
| 27 | LB_PORT=`neutron lbaas-loadbalancer-show ${LB} | grep 'port_id' | awk '{print $4}'` |
| 28 | neutron port-update ${LB_PORT} --no-security-groups |
| 29 | neutron port-update ${LB_PORT} --security-group ${SGID} |
| 30 | echo "Creating the LB listener and pool" |
| 31 | LISTENER=`neutron lbaas-listener-create --loadbalancer ${LB} --protocol ${PROTO} --protocol-port ${PORT} --name ${LBNAME}-listener | grep '\ id' | awk '{print $4}'` |
| 32 | POOL=`neutron lbaas-pool-create --listener ${LISTENER} --protocol ${PROTO} --name ${LBNAME}-pool --lb-algorithm ROUND_ROBIN | grep '\ id' | awk '{print $4}'` |
| 33 | echo "Obtaining the fixed IP addresses for the pool VMs" |
| 34 | IP1=`openstack server show lb-1 | grep addresses | awk '{print $4}' | cut -d '=' -f 2` |
| 35 | IP2=`openstack server show lb-2 | grep addresses | awk '{print $4}' | cut -d '=' -f 2` |
| 36 | IP3=`openstack server show lb-3 | grep addresses | awk '{print $4}' | cut -d '=' -f 2` |
| 37 | echo "Adding the VMs to the pool" |
| 38 | neutron lbaas-member-create --protocol-port ${PORT} ${POOL} --subnet ${SUBNET} --address ${IP1} |
| 39 | neutron lbaas-member-create --protocol-port ${PORT} ${POOL} --subnet ${SUBNET} --address ${IP2} |
| 40 | neutron lbaas-member-create --protocol-port ${PORT} ${POOL} --subnet ${SUBNET} --address ${IP3} |
| 41 | echo "Associating the floating IP with the LB VIP" |
| 42 | FIP_ID=`neutron floatingip-create ${FIP_NET} | grep '\ id' | awk '{print $4}'` |
| 43 | neutron floatingip-associate ${FIP_ID} ${LB_PORT} |
| 44 | FIP_IP=`neutron floatingip-show ${FIP_ID} | grep address | awk '{print $4}'` |
| 45 | echo Load balancer is up with the floating IP ${FIP_IP}:${PORT}, protocol ${PROTO}. Press Enter for LB decommissioning. |
| 46 | read _ |
| 47 | neutron lbaas-member-list ${POOL} | grep ${SUBNET} | awk -v pool=${POOL} '{system("neutron lbaas-member-delete " $2 " " pool)}' |
| 48 | neutron lbaas-pool-delete ${POOL} |
| 49 | neutron lbaas-listener-delete ${LISTENER} |
| 50 | neutron lbaas-loadbalancer-delete ${LB} |
| 51 | neutron floatingip-delete ${FIP_ID} |
| 52 | openstack server delete lb-1 |
| 53 | openstack server delete lb-2 |
| 54 | openstack server delete lb-3 |