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) |
Ievgeniia Zadorozhna | 0facf3c | 2022-06-16 16:19:09 +0300 | [diff] [blame] | 92 | logger.info("Checking VMs are reachable via SSH, getting MTU...") |
| 93 | mtus = [] |
Ievgeniia Zadorozhna | 8402302 | 2021-12-30 13:00:41 +0200 | [diff] [blame] | 94 | for i in range(4): |
| 95 | if transport1.check_vm_is_reachable_ssh( |
| 96 | floating_ip=vm_info[i]['fip'], timeout=ssh_timeout): |
| 97 | ssh.prepare_iperf(vm_info[i]['fip'], private_key=private_key) |
Ievgeniia Zadorozhna | 0facf3c | 2022-06-16 16:19:09 +0300 | [diff] [blame] | 98 | mtus.append(transport1.get_mtu_from_vm( |
| 99 | vm_info[i]['fip'], private_key=private_key)) |
| 100 | logger.info("MTU at networks: {}, {}".format(os_resources['net1']['mtu'], |
| 101 | os_resources['net2']['mtu'])) |
| 102 | logger.info("MTU at VMs: {}".format(", ".join(mtus))) |
Ievgeniia Zadorozhna | 8402302 | 2021-12-30 13:00:41 +0200 | [diff] [blame] | 103 | |
| 104 | # Prepare the result table and run iperf3 |
| 105 | table_rows = [] |
Ievgeniia Zadorozhna | 0facf3c | 2022-06-16 16:19:09 +0300 | [diff] [blame] | 106 | table_rows.append(['Test Case', 'Host 1', 'Host 2', |
| 107 | 'MTU at VMs', 'Result']) |
Ievgeniia Zadorozhna | 8402302 | 2021-12-30 13:00:41 +0200 | [diff] [blame] | 108 | # Do iperf3 measurement #1 |
| 109 | logger.info("Doing 'VM to VM in same tenant on same node via Private " |
| 110 | "IP, 1 thread' measurement...") |
| 111 | result1 = transport1.exec_command( |
| 112 | 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format( |
| 113 | vm_info[1]['private_address'], iperf_time)) |
| 114 | res1 = (b" ".join(result1.split()[-4:-2:])).decode('utf-8') |
| 115 | logger.info("Result #1 is {}".format(res1)) |
| 116 | table_rows.append(['VM to VM in same tenant on same node via ' |
| 117 | 'Private IP, 1 thread', |
| 118 | "{}".format(pair[0]), |
| 119 | "{}".format(pair[0]), |
Ievgeniia Zadorozhna | 0facf3c | 2022-06-16 16:19:09 +0300 | [diff] [blame] | 120 | "{}, {}".format(mtus[0], mtus[1]), |
Ievgeniia Zadorozhna | 8402302 | 2021-12-30 13:00:41 +0200 | [diff] [blame] | 121 | "{}".format(res1)]) |
| 122 | |
| 123 | # Do iperf3 measurement #2 |
| 124 | logger.info("Doing 'VM to VM in same tenant on different HW nodes " |
| 125 | "via Private IP, 1 thread' measurement...") |
| 126 | result2 = transport1.exec_command( |
| 127 | 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format( |
| 128 | vm_info[2]['private_address'], iperf_time)) |
| 129 | res2 = (b" ".join(result2.split()[-4:-2:])).decode('utf-8') |
| 130 | logger.info("Result #2 is {}".format(res2)) |
| 131 | table_rows.append(['VM to VM in same tenant on different HW nodes ' |
| 132 | 'via Private IP, 1 thread', |
| 133 | "{}".format(pair[0]), |
| 134 | "{}".format(pair[1]), |
Ievgeniia Zadorozhna | 0facf3c | 2022-06-16 16:19:09 +0300 | [diff] [blame] | 135 | "{}, {}".format(mtus[0], mtus[2]), |
Ievgeniia Zadorozhna | 8402302 | 2021-12-30 13:00:41 +0200 | [diff] [blame] | 136 | "{}".format(res2)]) |
| 137 | |
| 138 | # Do iperf3 measurement #3 |
| 139 | logger.info("Doing 'VM to VM in same tenant on different HW nodes " |
| 140 | "via Private IP, 10 threads' measurement...") |
| 141 | result3 = transport1.exec_command( |
| 142 | 'iperf3 -c {} -P 10 -t {} | grep sender | tail -n 1'.format( |
| 143 | vm_info[2]['private_address'], iperf_time)) |
| 144 | res3 = (b" ".join(result3.split()[-4:-2:])).decode('utf-8') |
| 145 | logger.info("Result #3 is {}".format(res3)) |
| 146 | table_rows.append(['VM to VM in same tenant on different HW nodes ' |
| 147 | 'via Private IP, 10 threads', |
| 148 | "{}".format(pair[0]), |
| 149 | "{}".format(pair[1]), |
Ievgeniia Zadorozhna | 0facf3c | 2022-06-16 16:19:09 +0300 | [diff] [blame] | 150 | "{}, {}".format(mtus[0], mtus[2]), |
Ievgeniia Zadorozhna | 8402302 | 2021-12-30 13:00:41 +0200 | [diff] [blame] | 151 | "{}".format(res3)]) |
| 152 | |
| 153 | # Do iperf3 measurement #4 |
| 154 | logger.info("Doing 'VM to VM in same tenant via Floating IP and VMs " |
| 155 | "are on different nodes, 1 thread' measurement...") |
| 156 | result4 = transport1.exec_command( |
| 157 | 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format( |
| 158 | vm_info[2]['fip'], iperf_time)) |
| 159 | res4 = (b" ".join(result4.split()[-4:-2:])).decode('utf-8') |
| 160 | logger.info("Result #4 is {}".format(res4)) |
| 161 | table_rows.append(['VM to VM in same tenant via Floating IP and VMs ' |
| 162 | 'are on different nodes, 1 thread', |
| 163 | "{}".format(pair[0]), |
| 164 | "{}".format(pair[1]), |
Ievgeniia Zadorozhna | 0facf3c | 2022-06-16 16:19:09 +0300 | [diff] [blame] | 165 | "{}, {}".format(mtus[0], mtus[2]), |
Ievgeniia Zadorozhna | 8402302 | 2021-12-30 13:00:41 +0200 | [diff] [blame] | 166 | "{}".format(res4)]) |
| 167 | |
| 168 | # Do iperf3 measurement #5 |
| 169 | logger.info("Doing 'VM to VM in same tenant, different HW nodes and " |
| 170 | "each VM is connected to separate network which are " |
| 171 | " connected using Router via Private IP, 1 thread' " |
| 172 | "measurement...") |
| 173 | result5 = transport1.exec_command( |
| 174 | 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format( |
| 175 | vm_info[3]['private_address'], iperf_time)) |
| 176 | res5 = (b" ".join(result5.split()[-4:-2:])).decode('utf-8') |
| 177 | logger.info("Result #5 is {}".format(res5)) |
| 178 | table_rows.append(['VM to VM in same tenant, different HW nodes and ' |
| 179 | 'each VM is connected to separate network which are' |
| 180 | ' connected using Router via Private IP, 1 thread', |
| 181 | "{}".format(pair[0]), |
| 182 | "{}".format(pair[1]), |
Ievgeniia Zadorozhna | 0facf3c | 2022-06-16 16:19:09 +0300 | [diff] [blame] | 183 | "{}, {}".format(mtus[0], mtus[3]), |
Ievgeniia Zadorozhna | 8402302 | 2021-12-30 13:00:41 +0200 | [diff] [blame] | 184 | "{}".format(res5)]) |
| 185 | |
| 186 | logger.info("Drawing the table with iperf results...") |
| 187 | result_table.add_rows(table_rows) |
Ievgeniia Zadorozhna | 0facf3c | 2022-06-16 16:19:09 +0300 | [diff] [blame] | 188 | print('\n{}'.format(result_table.draw())) |
Ievgeniia Zadorozhna | 8402302 | 2021-12-30 13:00:41 +0200 | [diff] [blame] | 189 | |
| 190 | print("Removing VMs and FIPs...") |
| 191 | logger.info("Removing VMs and FIPs...") |
| 192 | for vm in vms: |
| 193 | openstack_clients.compute.servers.delete(vm) |
| 194 | print("Removing FIPs...") |
| 195 | for fip in fips: |
| 196 | openstack_clients.compute.floating_ips.delete(fip) |
| 197 | except Exception as e: |
| 198 | print(e) |
| 199 | print("Something went wrong") |
| 200 | if 'vms' in locals(): |
| 201 | logger.info("Removing VMs...") |
| 202 | for vm in vms: |
| 203 | openstack_clients.compute.servers.delete(vm) |
| 204 | if 'fips' in locals(): |
| 205 | logger.info("Removing FIPs...") |
| 206 | for fip in fips: |
| 207 | openstack_clients.compute.floating_ips.delete(fip) |
| 208 | else: |
| 209 | print("Skipping cleaning, VMs were not created") |
| 210 | pytest.fail("Something went wrong") |