blob: 1fa885016ac399d26b00c5b6bb759b005a8d4fe9 [file] [log] [blame]
Ievgeniia Zadorozhna96a715b2024-03-02 00:09:58 +01001from concurrent.futures import ThreadPoolExecutor
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +03002import logging
3import sys
4import time
5
6import pytest
7from texttable import Texttable
8
9import utils
Ievgeniia Zadorozhna9664b422023-03-28 21:09:46 +030010from utils import helpers
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +030011from utils import os_client
12from utils import ssh
13
14
15logger = logging.getLogger(__name__)
16
17
18def test_vm2vm_different_project_different_routers(
19 openstack_clients, openstack_alt_clients, pair,
Ievgeniia Zadorozhna9664b422023-03-28 21:09:46 +030020 os_resources, os_resources_alt_project, request, html_report):
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +030021 """
22 Simplified Performance Tests VM to VM test in different projects, different
23 networks, different routers, measure by Floating IPs (common floating net):
24 1. Create a new project
25 2. Create a network, router, VM in admin project
26 3. Create a network, router, 2 VMs in the newly created project (on
27 different nodes)
28 4. Associate floating IPs to all 3 VMs
29 5. Connect to each VM via SSH and install iperf3
30 6. Measure VM to VM on same node, in different projects, different network,
31 router, via Floating IP, 1 thread
32 7. Measure VM to VM on same node, in different projects, different network,
33 router, via Floating IP, multiple threads (10 by default)
34 8. Measure VM to VM on different nodes, in different projects, different
35 network, router, via Floating IP, 1 thread
36 9. Measure VM to VM on different nodes, in different projects, different
37 network, router, via Floating IP, multiple threads (10 by default)
38 10. Draw the table with all pairs and results
39 """
40 os_actions = os_client.OSCliActions(openstack_clients)
41 alt_os_actions = os_client.OSCliActions(openstack_alt_clients)
42 config = utils.get_configuration()
43 timeout = int(config.get('nova_timeout', 30))
44 iperf_time = int(config.get('iperf_time', 60))
45 private_key = os_resources['keypair'].private_key
46 ssh_timeout = int(config.get('ssh_timeout', 500))
47 threads = int(config.get('multiple_threads_number', 10))
48 iperf_utility = config.get('multiple_threads_iperf_utility', 'iperf3')
49 custom_mtu = config.get('custom_mtu') or 'default'
50 utils.check_iperf_utility(iperf_utility)
51 result_table = Texttable(max_width=120)
52
53 try:
54 zone1 = [service.zone for service in
55 openstack_clients.compute.services.list() if
56 service.host == pair[0]]
57 zone2 = [service.zone for service in
58 openstack_clients.compute.services.list()
59 if service.host == pair[1]]
60
61 # create 3 VMs: 1 VM in admin project (zone1), 2 VMs in a separate
62 # project (zone1, zone2)
63 logger.info("Creating 3 VMs...")
64 vm1 = os_actions.create_basic_server(
65 os_resources['image_id'], os_resources['flavor_id'],
66 os_resources['net1'], '{0}:{1}'.format(zone1[0], pair[0]),
67 [os_resources['sec_group']['name']], os_resources['keypair'].name)
68 logger.info("Created VM {} in {} project.".format(
69 vm1.id, openstack_clients.project_name))
70
71 vm2 = alt_os_actions.create_basic_server(
72 os_resources_alt_project['image_id'],
73 os_resources_alt_project['flavor_id'],
74 os_resources_alt_project['net1'],
75 '{0}:{1}'.format(zone1[0], pair[0]),
76 [os_resources_alt_project['sec_group']['name']],
77 os_resources['keypair'].name)
78 logger.info("Created VM {} in {} project.".format(
79 vm2.id, openstack_alt_clients.project_name))
80
81 vm3 = alt_os_actions.create_basic_server(
82 os_resources_alt_project['image_id'],
83 os_resources_alt_project['flavor_id'],
84 os_resources_alt_project['net1'],
85 '{0}:{1}'.format(zone2[0], pair[1]),
86 [os_resources_alt_project['sec_group']['name']],
87 os_resources['keypair'].name)
88 logger.info("Created VM {} in {} project.".format(
89 vm3.id, openstack_alt_clients.project_name))
90
91 vm_info = []
92 vms = []
93 vms.extend([vm1, vm2, vm3])
94 fips = []
95 time.sleep(5)
96
97 # Associate FIPs and check VMs are Active
98 logger.info("Creating Floating IPs and associating them...")
99 fip0 = os_actions.create_floating_ip(os_resources['ext_net']['id'])
100 fip1 = alt_os_actions.create_floating_ip(os_resources['ext_net']['id'])
101 fip2 = alt_os_actions.create_floating_ip(os_resources['ext_net']['id'])
102 fips.extend([fip0, fip1, fip2])
103 os_actions.check_vm_is_active(vms[0].id, timeout=timeout)
104 alt_os_actions.check_vm_is_active(vms[1].id, timeout=timeout)
105 alt_os_actions.check_vm_is_active(vms[2].id, timeout=timeout)
106 vms[0].add_floating_ip(fip0['floating_ip_address'])
107 vms[1].add_floating_ip(fip1['floating_ip_address'])
108 vms[2].add_floating_ip(fip2['floating_ip_address'])
109 for i in range(len(vms)):
110 vm_info.append({'vm': vms[i],
Ievgeniia Zadorozhna96a715b2024-03-02 00:09:58 +0100111 'fip': fips[i]['floating_ip_address'],
112 'private_key': private_key})
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300113
114 # Set custom MTU if required
115 if os_actions.is_cloud_tf() and (custom_mtu != "default"):
116 logger.info("Setting up custom MTU at network ports...")
117 for vm in vms:
118 os_actions.update_network_port_with_custom_mtu(vm.id,
119 custom_mtu)
120
121 # Check VMs are reachable and prepare iperf3
Ievgeniia Zadorozhna96a715b2024-03-02 00:09:58 +0100122 logger.info("Checking VMs are reachable via SSH...")
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300123 transport1 = ssh.SSHTransport(vm_info[0]['fip'], 'ubuntu',
124 password='dd', private_key=private_key)
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300125 for i in range(len(vms)):
Ievgeniia Zadorozhna96a715b2024-03-02 00:09:58 +0100126 transport1.check_vm_is_reachable_ssh(
127 floating_ip=vm_info[i]['fip'], timeout=ssh_timeout)
128 with ThreadPoolExecutor() as executor:
129 futures = [
Ievgeniia Zadorozhnaa8e8b572025-03-28 14:29:45 +0100130 executor.submit(ssh.install_iperf_at_vm, vm_info)
Ievgeniia Zadorozhna96a715b2024-03-02 00:09:58 +0100131 for vm_info in vm_info]
Ievgeniia Zadorozhnaa8e8b572025-03-28 14:29:45 +0100132 logger.info("Getting MTUs at VMs...")
133 mtus = []
134 for vm in vm_info:
135 mtus.append(ssh.get_mtu_at_vm(vm))
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300136 logger.info(
137 "MTU at networks: {}, {}".format(
138 os_resources['net1']['mtu'],
139 os_resources_alt_project['net1']['mtu']))
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300140 # Prepare the result table and run iperf3
141 table_rows = []
142 table_rows.append(['Test Case', 'Host 1', 'Host 2',
143 'Project 1', 'Project 2', 'MTU at VMs', 'Result'])
144 # Do iperf3 measurement #1
145 measurement1 = ("VM to VM in different projects, nets, routers on "
146 "same node via Floating IP, 1 thread; iperf3")
147 logger.info("Doing '{}' measurement...".format(measurement1))
148 result1 = transport1.exec_command(
149 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
150 vm_info[1]['fip'], iperf_time))
151 res1 = (b" ".join(result1.split()[-4:-2:])).decode('utf-8')
152 logger.info("Result #1 is {}".format(res1))
153 table_rows.append([measurement1,
154 "{}".format(pair[0]),
155 "{}".format(pair[0]),
156 "{}".format(openstack_clients.project_name),
157 "{}".format(openstack_alt_clients.project_name),
158 "{}, {}".format(mtus[0], mtus[1]),
159 "{}".format(res1)])
160
161 # Do iperf/iperf3 measurement #2
162 measurement2 = ("VM to VM in different projects, nets, routers on "
163 "same node via Floating IP, {} threads; {}"
164 "".format(threads, iperf_utility))
165 logger.info("Doing '{}' measurement...".format(measurement2))
166 if iperf_utility == "iperf3":
167 result2 = transport1.exec_command(
168 '{} -c {} -P {} -t {} | grep sender | tail -n 1'.format(
169 iperf_utility, vm_info[1]['fip'], threads, iperf_time))
170 res2 = (b" ".join(result2.split()[-4:-2:])).decode('utf-8')
171 else:
172 iperf_utility = "iperf"
173 result2 = transport1.exec_command(
174 '{} -c {} -P {} -t {} | tail -n 1'.format(
175 iperf_utility, vm_info[1]['fip'], threads, iperf_time))
176 res2 = (b" ".join(result2.split()[-2::])).decode('utf-8')
177 logger.info("Result #2 is {}".format(res2))
178 table_rows.append([measurement2,
179 "{}".format(pair[0]),
180 "{}".format(pair[0]),
181 "{}".format(openstack_clients.project_name),
182 "{}".format(openstack_alt_clients.project_name),
183 "{}, {}".format(mtus[0], mtus[1]),
184 "{}".format(res2)])
185
186 # Do iperf3 measurement #3
187 measurement3 = ("VM to VM in different projects, nets, routers on "
188 "different nodes via Floating IP, 1 thread; iperf3")
189 logger.info("Doing '{}' measurement...".format(measurement3))
190 result3 = transport1.exec_command(
191 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
192 vm_info[2]['fip'], iperf_time))
193 res3 = (b" ".join(result3.split()[-4:-2:])).decode('utf-8')
194 logger.info("Result #3 is {}".format(res3))
195 table_rows.append([measurement3,
196 "{}".format(pair[0]),
197 "{}".format(pair[1]),
198 "{}".format(openstack_clients.project_name),
199 "{}".format(openstack_alt_clients.project_name),
200 "{}, {}".format(mtus[0], mtus[1]),
201 "{}".format(res3)])
202
203 # Do iperf/iperf3 measurement #4
204 measurement4 = ("VM to VM in different projects, nets, routers on "
205 "different nodes via Floating IP, {} threads; {}"
206 "".format(threads, iperf_utility))
207 logger.info("Doing '{}' measurement...".format(measurement4))
208 if iperf_utility == "iperf3":
209 result4 = transport1.exec_command(
210 '{} -c {} -P {} -t {} | grep sender | tail -n 1'.format(
211 iperf_utility, vm_info[2]['fip'], threads, iperf_time))
212 res4 = (b" ".join(result4.split()[-4:-2:])).decode('utf-8')
213 else:
214 iperf_utility = "iperf"
215 result4 = transport1.exec_command(
216 '{} -c {} -P {} -t {} | tail -n 1'.format(
217 iperf_utility, vm_info[2]['fip'], threads, iperf_time))
218 res4 = (b" ".join(result4.split()[-2::])).decode('utf-8')
219 logger.info("Result #4 is {}".format(res4))
220 table_rows.append([measurement4,
221 "{}".format(pair[0]),
222 "{}".format(pair[1]),
223 "{}".format(openstack_clients.project_name),
224 "{}".format(openstack_alt_clients.project_name),
225 "{}, {}".format(mtus[0], mtus[1]),
226 "{}".format(res4)])
227
228 logger.info("Drawing the table with iperf results...")
229 result_table.add_rows(table_rows)
230 sys.stdout.write('\n{}\n'.format(result_table.draw()))
231
Ievgeniia Zadorozhna9664b422023-03-28 21:09:46 +0300232 # Send the results to CSV file at reports/ directory
233 helpers.create_test_result_table_csv_file(
234 table_rows, request.node.name)
235
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300236 logger.info("Removing VMs and FIPs...")
237 for vm in vms:
238 openstack_clients.compute.servers.delete(vm)
239 logger.info("Removing FIPs...")
240 for fip in fips:
241 os_actions.delete_floating_ip(fip['id'])
242 except Exception as e:
243 sys.stdout.write("\n{}".format(e))
244 sys.stdout.write("\nSomething went wrong\n")
245 if 'vms' in locals():
246 logger.info("Removing VMs...")
247 for vm in vms:
248 openstack_clients.compute.servers.delete(vm)
249 if 'fips' in locals():
250 logger.info("Removing FIPs...")
251 for fip in fips:
252 os_actions.delete_floating_ip(fip['id'])
253 else:
254 sys.stdout.write("\nSkipping cleaning, VMs were not created")
255 pytest.fail("Something went wrong")