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