blob: 44b584e094ed070945273b5cee48457011950a7b [file] [log] [blame]
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +02001import logging
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +03002import sys
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +02003import time
4
5import pytest
6from texttable import Texttable
7
8import utils
9from utils import os_client
10from utils import ssh
11
12
13logger = logging.getLogger(__name__)
14
15
16def test_vm2vm(openstack_clients, pair, os_resources, record_property):
17 """
18 Simplified Performance Tests VM to VM test in different topologies
19 1. Create 4 VMs admin project
20 2. Associate floating IPs to the VMs
21 3. Connect to each VM via SSH and install iperf3
22 4. Measure VM to VM on same node via Private IP, 1 thread
23 5. Measure VM to VM on different HW nodes via Private IP, 1 thread
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +030024 6. Measure VM to VM on different HW nodes via Private IP, multiple threads
25 (10 by default)
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +020026 7. Measure VM to VM on different HW nodes via Floating IP, 1 thread
27 8. Measure VM to VM on different HW nodes, each VM is in separate network,
28 the networks are connected using Router via Private IP, 1 thread
29 9. Draw the table with all pairs and results
30 """
31 os_actions = os_client.OSCliActions(openstack_clients)
32 config = utils.get_configuration()
33 timeout = int(config.get('nova_timeout', 30))
34 iperf_time = int(config.get('iperf_time', 60))
35 private_key = os_resources['keypair'].private_key
36 ssh_timeout = int(config.get('ssh_timeout', 500))
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +030037 threads = int(config.get('multiple_threads_number', 10))
Ievgeniia Zadorozhna90aa8022022-08-11 18:00:23 +030038 iperf_utility = config.get('multiple_threads_iperf_utility', 'iperf3')
Ievgeniia Zadorozhnac67b86b2023-02-02 18:09:12 +030039 custom_mtu = config.get('custom_mtu') or 'default'
Ievgeniia Zadorozhna90aa8022022-08-11 18:00:23 +030040 utils.check_iperf_utility(iperf_utility)
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +030041 result_table = Texttable(max_width=120)
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +020042
43 try:
44 zone1 = [service.zone for service in
45 openstack_clients.compute.services.list() if
46 service.host == pair[0]]
47 zone2 = [service.zone for service in
48 openstack_clients.compute.services.list()
49 if service.host == pair[1]]
50
51 # create 4 VMs
52 logger.info("Creating 4 VMs...")
53 vm1 = 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]),
Ievgeniia Zadorozhna2c6469d2022-08-10 17:21:10 +030056 [os_resources['sec_group']['name']], os_resources['keypair'].name)
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +020057 logger.info("Created VM {}.".format(vm1.id))
58
59 vm2 = os_actions.create_basic_server(
60 os_resources['image_id'], os_resources['flavor_id'],
61 os_resources['net1'], '{0}:{1}'.format(zone1[0], pair[0]),
Ievgeniia Zadorozhna2c6469d2022-08-10 17:21:10 +030062 [os_resources['sec_group']['name']], os_resources['keypair'].name)
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +020063 logger.info("Created VM {}.".format(vm2.id))
64
65 vm3 = os_actions.create_basic_server(
66 os_resources['image_id'], os_resources['flavor_id'],
67 os_resources['net1'], '{0}:{1}'.format(zone2[0], pair[1]),
Ievgeniia Zadorozhna2c6469d2022-08-10 17:21:10 +030068 [os_resources['sec_group']['name']], os_resources['keypair'].name)
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +020069 logger.info("Created VM {}.".format(vm3.id))
70
71 vm4 = os_actions.create_basic_server(
72 os_resources['image_id'], os_resources['flavor_id'],
73 os_resources['net2'], '{0}:{1}'.format(zone2[0], pair[1]),
Ievgeniia Zadorozhna2c6469d2022-08-10 17:21:10 +030074 [os_resources['sec_group']['name']], os_resources['keypair'].name)
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +020075 logger.info("Created VM {}.".format(vm4.id))
76
77 vm_info = []
78 vms = []
79 vms.extend([vm1, vm2, vm3, vm4])
80 fips = []
81 time.sleep(5)
82
83 # Associate FIPs and check VMs are Active
84 logger.info("Creating Floating IPs and associating them...")
85 for i in range(4):
Ievgeniia Zadorozhna2c6469d2022-08-10 17:21:10 +030086 fip = os_actions.create_floating_ip(os_resources['ext_net']['id'])
87 fips.append(fip['id'])
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +020088 os_actions.check_vm_is_active(vms[i].id, timeout=timeout)
Ievgeniia Zadorozhna2c6469d2022-08-10 17:21:10 +030089 vms[i].add_floating_ip(fip['floating_ip_address'])
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +020090 private_address = vms[i].addresses[
91 list(vms[i].addresses.keys())[0]][0]['addr']
Ievgeniia Zadorozhna2c6469d2022-08-10 17:21:10 +030092 vm_info.append({'vm': vms[i], 'fip': fip['floating_ip_address'],
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +020093 'private_address': private_address})
Ievgeniia Zadorozhnac67b86b2023-02-02 18:09:12 +030094 # Set custom MTU if required
95 if os_actions.is_cloud_tf() and (custom_mtu != "default"):
96 logger.info("Setting up custom MTU at network ports...")
97 for vm in vms:
98 os_actions.update_network_port_with_custom_mtu(vm.id,
99 custom_mtu)
100
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200101 # Check VMs are reachable and prepare iperf3
102 transport1 = ssh.SSHTransport(vm_info[0]['fip'], 'ubuntu',
103 password='dd', private_key=private_key)
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300104 logger.info("Checking VMs are reachable via SSH, getting MTU...")
105 mtus = []
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200106 for i in range(4):
107 if transport1.check_vm_is_reachable_ssh(
108 floating_ip=vm_info[i]['fip'], timeout=ssh_timeout):
109 ssh.prepare_iperf(vm_info[i]['fip'], private_key=private_key)
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300110 mtus.append(transport1.get_mtu_from_vm(
111 vm_info[i]['fip'], private_key=private_key))
Ievgeniia Zadorozhnac67b86b2023-02-02 18:09:12 +0300112 logger.info("MTU at networks: {}, {}".format(
113 os_resources['net1']['mtu'], os_resources['net2']['mtu']))
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300114 logger.info("MTU at VMs: {}".format(", ".join(mtus)))
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200115
116 # Prepare the result table and run iperf3
Ievgeniia Zadorozhnac67b86b2023-02-02 18:09:12 +0300117 table_rows = [[
118 'Test Case', 'Host 1', 'Host 2', 'MTU at VMs', 'Result'
119 ]]
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200120 # Do iperf3 measurement #1
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300121 measurement1 = ("VM to VM in same project on same node via Private "
122 "IP, 1 thread; iperf3")
123 logger.info("Doing '{}' measurement...".format(measurement1))
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200124 result1 = transport1.exec_command(
125 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
126 vm_info[1]['private_address'], iperf_time))
127 res1 = (b" ".join(result1.split()[-4:-2:])).decode('utf-8')
128 logger.info("Result #1 is {}".format(res1))
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300129 table_rows.append([measurement1,
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200130 "{}".format(pair[0]),
131 "{}".format(pair[0]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300132 "{}, {}".format(mtus[0], mtus[1]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200133 "{}".format(res1)])
134
135 # Do iperf3 measurement #2
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300136 measurement2 = ("VM to VM in same project on different HW nodes via "
137 "Private IP, 1 thread; iperf3")
138 logger.info("Doing '{}' measurement...".format(measurement2))
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200139 result2 = transport1.exec_command(
140 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
141 vm_info[2]['private_address'], iperf_time))
142 res2 = (b" ".join(result2.split()[-4:-2:])).decode('utf-8')
143 logger.info("Result #2 is {}".format(res2))
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300144 table_rows.append([measurement2,
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200145 "{}".format(pair[0]),
146 "{}".format(pair[1]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300147 "{}, {}".format(mtus[0], mtus[2]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200148 "{}".format(res2)])
149
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300150 # Do iperf/iperf3 measurement #3
151 measurement3 = ("VM to VM in same project on different HW nodes via "
152 "Private IP, {} threads; {}"
153 "".format(threads, iperf_utility))
154 logger.info("Doing '{}' measurement...".format(measurement3))
Ievgeniia Zadorozhna90aa8022022-08-11 18:00:23 +0300155 if iperf_utility == "iperf3":
156 result3 = transport1.exec_command(
157 '{} -c {} -P {} -t {} | grep sender | tail -n 1'
158 ''.format(iperf_utility, vm_info[2]['private_address'],
159 threads, iperf_time))
160 res3 = (b" ".join(result3.split()[-4:-2:])).decode('utf-8')
161 else:
162 iperf_utility = "iperf"
163 result3 = transport1.exec_command(
Ievgeniia Zadorozhnac67b86b2023-02-02 18:09:12 +0300164 '{} -c {} -P {} -t {} | tail -n 1'.format(
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300165 iperf_utility, vm_info[2]['private_address'], threads,
166 iperf_time))
Ievgeniia Zadorozhna90aa8022022-08-11 18:00:23 +0300167 res3 = (b" ".join(result3.split()[-2::])).decode('utf-8')
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200168 logger.info("Result #3 is {}".format(res3))
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300169 table_rows.append([measurement3,
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200170 "{}".format(pair[0]),
171 "{}".format(pair[1]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300172 "{}, {}".format(mtus[0], mtus[2]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200173 "{}".format(res3)])
174
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300175 # Do iperf3 measurement #4
176 measurement4 = ("VM to VM in same project via Floating IP and VMs "
177 "are on different nodes, 1 thread; iperf3")
178 logger.info("Doing '{}' measurement...".format(measurement4))
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200179 result4 = transport1.exec_command(
180 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
181 vm_info[2]['fip'], iperf_time))
182 res4 = (b" ".join(result4.split()[-4:-2:])).decode('utf-8')
183 logger.info("Result #4 is {}".format(res4))
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300184 table_rows.append([measurement4,
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200185 "{}".format(pair[0]),
186 "{}".format(pair[1]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300187 "{}, {}".format(mtus[0], mtus[2]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200188 "{}".format(res4)])
189
190 # Do iperf3 measurement #5
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300191 measurement5 = ("VM to VM in same project, different HW nodes and "
192 "each VM is connected to separate network which are "
193 "connected using Router via Private IP, 1 thread; "
194 "iperf3")
195 logger.info("Doing '{}' measurement...".format(measurement5))
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200196 result5 = transport1.exec_command(
197 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
198 vm_info[3]['private_address'], iperf_time))
199 res5 = (b" ".join(result5.split()[-4:-2:])).decode('utf-8')
200 logger.info("Result #5 is {}".format(res5))
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300201 table_rows.append([measurement5,
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200202 "{}".format(pair[0]),
203 "{}".format(pair[1]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300204 "{}, {}".format(mtus[0], mtus[3]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200205 "{}".format(res5)])
206
207 logger.info("Drawing the table with iperf results...")
208 result_table.add_rows(table_rows)
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +0300209 sys.stdout.write('\n{}\n'.format(result_table.draw()))
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200210
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200211 logger.info("Removing VMs and FIPs...")
212 for vm in vms:
213 openstack_clients.compute.servers.delete(vm)
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +0300214 logger.info("Removing FIPs...")
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200215 for fip in fips:
Ievgeniia Zadorozhna2c6469d2022-08-10 17:21:10 +0300216 os_actions.delete_floating_ip(fip)
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200217 except Exception as e:
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +0300218 sys.stdout.write("\n{}".format(e))
219 sys.stdout.write("\nSomething went wrong\n")
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200220 if 'vms' in locals():
221 logger.info("Removing VMs...")
222 for vm in vms:
223 openstack_clients.compute.servers.delete(vm)
224 if 'fips' in locals():
225 logger.info("Removing FIPs...")
226 for fip in fips:
Ievgeniia Zadorozhna2c6469d2022-08-10 17:21:10 +0300227 os_actions.delete_floating_ip(fip)
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200228 else:
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +0300229 sys.stdout.write("\nSkipping cleaning, VMs were not created")
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200230 pytest.fail("Something went wrong")