blob: 612e5be4d00069f15ec2eda9aee5a120af55ab56 [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):
Ievgeniia Zadorozhnaa080ec02023-12-05 02:08:52 +0100128 ssh.IperfAtVM(
129 vm_info[i]['fip'], private_key=private_key)
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300130 mtus.append(transport1.get_mtu_from_vm(
131 vm_info[i]['fip'], private_key=private_key))
132 logger.info(
133 "MTU at networks: {}, {}".format(
134 os_resources['net1']['mtu'],
135 os_resources_alt_project['net1']['mtu']))
136 logger.info("MTU at VMs: {}".format(", ".join(mtus)))
137
138 # Prepare the result table and run iperf3
139 table_rows = []
140 table_rows.append(['Test Case', 'Host 1', 'Host 2',
141 'Project 1', 'Project 2', 'MTU at VMs', 'Result'])
142 # Do iperf3 measurement #1
143 measurement1 = ("VM to VM in different projects, nets, routers on "
144 "same node via Floating IP, 1 thread; iperf3")
145 logger.info("Doing '{}' measurement...".format(measurement1))
146 result1 = transport1.exec_command(
147 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
148 vm_info[1]['fip'], iperf_time))
149 res1 = (b" ".join(result1.split()[-4:-2:])).decode('utf-8')
150 logger.info("Result #1 is {}".format(res1))
151 table_rows.append([measurement1,
152 "{}".format(pair[0]),
153 "{}".format(pair[0]),
154 "{}".format(openstack_clients.project_name),
155 "{}".format(openstack_alt_clients.project_name),
156 "{}, {}".format(mtus[0], mtus[1]),
157 "{}".format(res1)])
158
159 # Do iperf/iperf3 measurement #2
160 measurement2 = ("VM to VM in different projects, nets, routers on "
161 "same node via Floating IP, {} threads; {}"
162 "".format(threads, iperf_utility))
163 logger.info("Doing '{}' measurement...".format(measurement2))
164 if iperf_utility == "iperf3":
165 result2 = transport1.exec_command(
166 '{} -c {} -P {} -t {} | grep sender | tail -n 1'.format(
167 iperf_utility, vm_info[1]['fip'], threads, iperf_time))
168 res2 = (b" ".join(result2.split()[-4:-2:])).decode('utf-8')
169 else:
170 iperf_utility = "iperf"
171 result2 = transport1.exec_command(
172 '{} -c {} -P {} -t {} | tail -n 1'.format(
173 iperf_utility, vm_info[1]['fip'], threads, iperf_time))
174 res2 = (b" ".join(result2.split()[-2::])).decode('utf-8')
175 logger.info("Result #2 is {}".format(res2))
176 table_rows.append([measurement2,
177 "{}".format(pair[0]),
178 "{}".format(pair[0]),
179 "{}".format(openstack_clients.project_name),
180 "{}".format(openstack_alt_clients.project_name),
181 "{}, {}".format(mtus[0], mtus[1]),
182 "{}".format(res2)])
183
184 # Do iperf3 measurement #3
185 measurement3 = ("VM to VM in different projects, nets, routers on "
186 "different nodes via Floating IP, 1 thread; iperf3")
187 logger.info("Doing '{}' measurement...".format(measurement3))
188 result3 = transport1.exec_command(
189 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
190 vm_info[2]['fip'], iperf_time))
191 res3 = (b" ".join(result3.split()[-4:-2:])).decode('utf-8')
192 logger.info("Result #3 is {}".format(res3))
193 table_rows.append([measurement3,
194 "{}".format(pair[0]),
195 "{}".format(pair[1]),
196 "{}".format(openstack_clients.project_name),
197 "{}".format(openstack_alt_clients.project_name),
198 "{}, {}".format(mtus[0], mtus[1]),
199 "{}".format(res3)])
200
201 # Do iperf/iperf3 measurement #4
202 measurement4 = ("VM to VM in different projects, nets, routers on "
203 "different nodes via Floating IP, {} threads; {}"
204 "".format(threads, iperf_utility))
205 logger.info("Doing '{}' measurement...".format(measurement4))
206 if iperf_utility == "iperf3":
207 result4 = transport1.exec_command(
208 '{} -c {} -P {} -t {} | grep sender | tail -n 1'.format(
209 iperf_utility, vm_info[2]['fip'], threads, iperf_time))
210 res4 = (b" ".join(result4.split()[-4:-2:])).decode('utf-8')
211 else:
212 iperf_utility = "iperf"
213 result4 = transport1.exec_command(
214 '{} -c {} -P {} -t {} | tail -n 1'.format(
215 iperf_utility, vm_info[2]['fip'], threads, iperf_time))
216 res4 = (b" ".join(result4.split()[-2::])).decode('utf-8')
217 logger.info("Result #4 is {}".format(res4))
218 table_rows.append([measurement4,
219 "{}".format(pair[0]),
220 "{}".format(pair[1]),
221 "{}".format(openstack_clients.project_name),
222 "{}".format(openstack_alt_clients.project_name),
223 "{}, {}".format(mtus[0], mtus[1]),
224 "{}".format(res4)])
225
226 logger.info("Drawing the table with iperf results...")
227 result_table.add_rows(table_rows)
228 sys.stdout.write('\n{}\n'.format(result_table.draw()))
229
Ievgeniia Zadorozhna9664b422023-03-28 21:09:46 +0300230 # Send the results to CSV file at reports/ directory
231 helpers.create_test_result_table_csv_file(
232 table_rows, request.node.name)
233
Ievgeniia Zadorozhnaf22827b2022-07-20 13:30:32 +0300234 logger.info("Removing VMs and FIPs...")
235 for vm in vms:
236 openstack_clients.compute.servers.delete(vm)
237 logger.info("Removing FIPs...")
238 for fip in fips:
239 os_actions.delete_floating_ip(fip['id'])
240 except Exception as e:
241 sys.stdout.write("\n{}".format(e))
242 sys.stdout.write("\nSomething went wrong\n")
243 if 'vms' in locals():
244 logger.info("Removing VMs...")
245 for vm in vms:
246 openstack_clients.compute.servers.delete(vm)
247 if 'fips' in locals():
248 logger.info("Removing FIPs...")
249 for fip in fips:
250 os_actions.delete_floating_ip(fip['id'])
251 else:
252 sys.stdout.write("\nSkipping cleaning, VMs were not created")
253 pytest.fail("Something went wrong")