Ievgeniia Zadorozhna | 8402302 | 2021-12-30 13:00:41 +0200 | [diff] [blame^] | 1 | import logging |
| 2 | import time |
| 3 | |
| 4 | import pytest |
| 5 | from texttable import Texttable |
| 6 | |
| 7 | import utils |
| 8 | from utils import os_client |
| 9 | from utils import ssh |
| 10 | |
| 11 | |
| 12 | logger = logging.getLogger(__name__) |
| 13 | |
| 14 | |
| 15 | def test_vm2vm(openstack_clients, pair, os_resources, record_property): |
| 16 | """ |
| 17 | Simplified Performance Tests VM to VM test in different topologies |
| 18 | 1. Create 4 VMs admin project |
| 19 | 2. Associate floating IPs to the VMs |
| 20 | 3. Connect to each VM via SSH and install iperf3 |
| 21 | 4. Measure VM to VM on same node via Private IP, 1 thread |
| 22 | 5. Measure VM to VM on different HW nodes via Private IP, 1 thread |
| 23 | 6. Measure VM to VM on different HW nodes via Private IP, 10 threads |
| 24 | 7. Measure VM to VM on different HW nodes via Floating IP, 1 thread |
| 25 | 8. Measure VM to VM on different HW nodes, each VM is in separate network, |
| 26 | the networks are connected using Router via Private IP, 1 thread |
| 27 | 9. Draw the table with all pairs and results |
| 28 | """ |
| 29 | os_actions = os_client.OSCliActions(openstack_clients) |
| 30 | config = utils.get_configuration() |
| 31 | timeout = int(config.get('nova_timeout', 30)) |
| 32 | iperf_time = int(config.get('iperf_time', 60)) |
| 33 | private_key = os_resources['keypair'].private_key |
| 34 | ssh_timeout = int(config.get('ssh_timeout', 500)) |
| 35 | result_table = Texttable() |
| 36 | |
| 37 | try: |
| 38 | zone1 = [service.zone for service in |
| 39 | openstack_clients.compute.services.list() if |
| 40 | service.host == pair[0]] |
| 41 | zone2 = [service.zone for service in |
| 42 | openstack_clients.compute.services.list() |
| 43 | if service.host == pair[1]] |
| 44 | |
| 45 | # create 4 VMs |
| 46 | logger.info("Creating 4 VMs...") |
| 47 | vm1 = os_actions.create_basic_server( |
| 48 | os_resources['image_id'], os_resources['flavor_id'], |
| 49 | os_resources['net1'], '{0}:{1}'.format(zone1[0], pair[0]), |
| 50 | [os_resources['sec_group'].name], os_resources['keypair'].name) |
| 51 | logger.info("Created VM {}.".format(vm1.id)) |
| 52 | |
| 53 | vm2 = os_actions.create_basic_server( |
| 54 | os_resources['image_id'], os_resources['flavor_id'], |
| 55 | os_resources['net1'], '{0}:{1}'.format(zone1[0], pair[0]), |
| 56 | [os_resources['sec_group'].name], os_resources['keypair'].name) |
| 57 | logger.info("Created VM {}.".format(vm2.id)) |
| 58 | |
| 59 | vm3 = os_actions.create_basic_server( |
| 60 | os_resources['image_id'], os_resources['flavor_id'], |
| 61 | os_resources['net1'], '{0}:{1}'.format(zone2[0], pair[1]), |
| 62 | [os_resources['sec_group'].name], os_resources['keypair'].name) |
| 63 | logger.info("Created VM {}.".format(vm3.id)) |
| 64 | |
| 65 | vm4 = os_actions.create_basic_server( |
| 66 | os_resources['image_id'], os_resources['flavor_id'], |
| 67 | os_resources['net2'], '{0}:{1}'.format(zone2[0], pair[1]), |
| 68 | [os_resources['sec_group'].name], os_resources['keypair'].name) |
| 69 | logger.info("Created VM {}.".format(vm4.id)) |
| 70 | |
| 71 | vm_info = [] |
| 72 | vms = [] |
| 73 | vms.extend([vm1, vm2, vm3, vm4]) |
| 74 | fips = [] |
| 75 | time.sleep(5) |
| 76 | |
| 77 | # Associate FIPs and check VMs are Active |
| 78 | logger.info("Creating Floating IPs and associating them...") |
| 79 | for i in range(4): |
| 80 | fip = openstack_clients.compute.floating_ips.create( |
| 81 | os_resources['ext_net']['name']) |
| 82 | fips.append(fip.id) |
| 83 | os_actions.check_vm_is_active(vms[i].id, timeout=timeout) |
| 84 | vms[i].add_floating_ip(fip) |
| 85 | private_address = vms[i].addresses[ |
| 86 | list(vms[i].addresses.keys())[0]][0]['addr'] |
| 87 | vm_info.append({'vm': vms[i], 'fip': fip.ip, |
| 88 | 'private_address': private_address}) |
| 89 | # Check VMs are reachable and prepare iperf3 |
| 90 | transport1 = ssh.SSHTransport(vm_info[0]['fip'], 'ubuntu', |
| 91 | password='dd', private_key=private_key) |
| 92 | logger.info("Checking VMs are reachable via SSH...") |
| 93 | for i in range(4): |
| 94 | if transport1.check_vm_is_reachable_ssh( |
| 95 | floating_ip=vm_info[i]['fip'], timeout=ssh_timeout): |
| 96 | ssh.prepare_iperf(vm_info[i]['fip'], private_key=private_key) |
| 97 | |
| 98 | # Prepare the result table and run iperf3 |
| 99 | table_rows = [] |
| 100 | table_rows.append(['Test Case', 'Host 1', 'Host 2', 'Result']) |
| 101 | # Do iperf3 measurement #1 |
| 102 | logger.info("Doing 'VM to VM in same tenant on same node via Private " |
| 103 | "IP, 1 thread' measurement...") |
| 104 | result1 = transport1.exec_command( |
| 105 | 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format( |
| 106 | vm_info[1]['private_address'], iperf_time)) |
| 107 | res1 = (b" ".join(result1.split()[-4:-2:])).decode('utf-8') |
| 108 | logger.info("Result #1 is {}".format(res1)) |
| 109 | table_rows.append(['VM to VM in same tenant on same node via ' |
| 110 | 'Private IP, 1 thread', |
| 111 | "{}".format(pair[0]), |
| 112 | "{}".format(pair[0]), |
| 113 | "{}".format(res1)]) |
| 114 | |
| 115 | # Do iperf3 measurement #2 |
| 116 | logger.info("Doing 'VM to VM in same tenant on different HW nodes " |
| 117 | "via Private IP, 1 thread' measurement...") |
| 118 | result2 = transport1.exec_command( |
| 119 | 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format( |
| 120 | vm_info[2]['private_address'], iperf_time)) |
| 121 | res2 = (b" ".join(result2.split()[-4:-2:])).decode('utf-8') |
| 122 | logger.info("Result #2 is {}".format(res2)) |
| 123 | table_rows.append(['VM to VM in same tenant on different HW nodes ' |
| 124 | 'via Private IP, 1 thread', |
| 125 | "{}".format(pair[0]), |
| 126 | "{}".format(pair[1]), |
| 127 | "{}".format(res2)]) |
| 128 | |
| 129 | # Do iperf3 measurement #3 |
| 130 | logger.info("Doing 'VM to VM in same tenant on different HW nodes " |
| 131 | "via Private IP, 10 threads' measurement...") |
| 132 | result3 = transport1.exec_command( |
| 133 | 'iperf3 -c {} -P 10 -t {} | grep sender | tail -n 1'.format( |
| 134 | vm_info[2]['private_address'], iperf_time)) |
| 135 | res3 = (b" ".join(result3.split()[-4:-2:])).decode('utf-8') |
| 136 | logger.info("Result #3 is {}".format(res3)) |
| 137 | table_rows.append(['VM to VM in same tenant on different HW nodes ' |
| 138 | 'via Private IP, 10 threads', |
| 139 | "{}".format(pair[0]), |
| 140 | "{}".format(pair[1]), |
| 141 | "{}".format(res3)]) |
| 142 | |
| 143 | # Do iperf3 measurement #4 |
| 144 | logger.info("Doing 'VM to VM in same tenant via Floating IP and VMs " |
| 145 | "are on different nodes, 1 thread' measurement...") |
| 146 | result4 = transport1.exec_command( |
| 147 | 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format( |
| 148 | vm_info[2]['fip'], iperf_time)) |
| 149 | res4 = (b" ".join(result4.split()[-4:-2:])).decode('utf-8') |
| 150 | logger.info("Result #4 is {}".format(res4)) |
| 151 | table_rows.append(['VM to VM in same tenant via Floating IP and VMs ' |
| 152 | 'are on different nodes, 1 thread', |
| 153 | "{}".format(pair[0]), |
| 154 | "{}".format(pair[1]), |
| 155 | "{}".format(res4)]) |
| 156 | |
| 157 | # Do iperf3 measurement #5 |
| 158 | logger.info("Doing 'VM to VM in same tenant, different HW nodes and " |
| 159 | "each VM is connected to separate network which are " |
| 160 | " connected using Router via Private IP, 1 thread' " |
| 161 | "measurement...") |
| 162 | result5 = transport1.exec_command( |
| 163 | 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format( |
| 164 | vm_info[3]['private_address'], iperf_time)) |
| 165 | res5 = (b" ".join(result5.split()[-4:-2:])).decode('utf-8') |
| 166 | logger.info("Result #5 is {}".format(res5)) |
| 167 | table_rows.append(['VM to VM in same tenant, different HW nodes and ' |
| 168 | 'each VM is connected to separate network which are' |
| 169 | ' connected using Router via Private IP, 1 thread', |
| 170 | "{}".format(pair[0]), |
| 171 | "{}".format(pair[1]), |
| 172 | "{}".format(res5)]) |
| 173 | |
| 174 | logger.info("Drawing the table with iperf results...") |
| 175 | result_table.add_rows(table_rows) |
| 176 | print((result_table.draw())) |
| 177 | |
| 178 | print("Removing VMs and FIPs...") |
| 179 | logger.info("Removing VMs and FIPs...") |
| 180 | for vm in vms: |
| 181 | openstack_clients.compute.servers.delete(vm) |
| 182 | print("Removing FIPs...") |
| 183 | for fip in fips: |
| 184 | openstack_clients.compute.floating_ips.delete(fip) |
| 185 | except Exception as e: |
| 186 | print(e) |
| 187 | print("Something went wrong") |
| 188 | if 'vms' in locals(): |
| 189 | logger.info("Removing VMs...") |
| 190 | for vm in vms: |
| 191 | openstack_clients.compute.servers.delete(vm) |
| 192 | if 'fips' in locals(): |
| 193 | logger.info("Removing FIPs...") |
| 194 | for fip in fips: |
| 195 | openstack_clients.compute.floating_ips.delete(fip) |
| 196 | else: |
| 197 | print("Skipping cleaning, VMs were not created") |
| 198 | pytest.fail("Something went wrong") |