blob: 1b81268cf1204f6de104253f9407fb02b07155df [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')
39 utils.check_iperf_utility(iperf_utility)
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +030040 result_table = Texttable(max_width=120)
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +020041
42 try:
43 zone1 = [service.zone for service in
44 openstack_clients.compute.services.list() if
45 service.host == pair[0]]
46 zone2 = [service.zone for service in
47 openstack_clients.compute.services.list()
48 if service.host == pair[1]]
49
50 # create 4 VMs
51 logger.info("Creating 4 VMs...")
52 vm1 = os_actions.create_basic_server(
53 os_resources['image_id'], os_resources['flavor_id'],
54 os_resources['net1'], '{0}:{1}'.format(zone1[0], pair[0]),
55 [os_resources['sec_group'].name], os_resources['keypair'].name)
56 logger.info("Created VM {}.".format(vm1.id))
57
58 vm2 = os_actions.create_basic_server(
59 os_resources['image_id'], os_resources['flavor_id'],
60 os_resources['net1'], '{0}:{1}'.format(zone1[0], pair[0]),
61 [os_resources['sec_group'].name], os_resources['keypair'].name)
62 logger.info("Created VM {}.".format(vm2.id))
63
64 vm3 = os_actions.create_basic_server(
65 os_resources['image_id'], os_resources['flavor_id'],
66 os_resources['net1'], '{0}:{1}'.format(zone2[0], pair[1]),
67 [os_resources['sec_group'].name], os_resources['keypair'].name)
68 logger.info("Created VM {}.".format(vm3.id))
69
70 vm4 = os_actions.create_basic_server(
71 os_resources['image_id'], os_resources['flavor_id'],
72 os_resources['net2'], '{0}:{1}'.format(zone2[0], pair[1]),
73 [os_resources['sec_group'].name], os_resources['keypair'].name)
74 logger.info("Created VM {}.".format(vm4.id))
75
76 vm_info = []
77 vms = []
78 vms.extend([vm1, vm2, vm3, vm4])
79 fips = []
80 time.sleep(5)
81
82 # Associate FIPs and check VMs are Active
83 logger.info("Creating Floating IPs and associating them...")
84 for i in range(4):
85 fip = openstack_clients.compute.floating_ips.create(
86 os_resources['ext_net']['name'])
87 fips.append(fip.id)
88 os_actions.check_vm_is_active(vms[i].id, timeout=timeout)
89 vms[i].add_floating_ip(fip)
90 private_address = vms[i].addresses[
91 list(vms[i].addresses.keys())[0]][0]['addr']
92 vm_info.append({'vm': vms[i], 'fip': fip.ip,
93 'private_address': private_address})
94 # Check VMs are reachable and prepare iperf3
95 transport1 = ssh.SSHTransport(vm_info[0]['fip'], 'ubuntu',
96 password='dd', private_key=private_key)
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +030097 logger.info("Checking VMs are reachable via SSH, getting MTU...")
98 mtus = []
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +020099 for i in range(4):
100 if transport1.check_vm_is_reachable_ssh(
101 floating_ip=vm_info[i]['fip'], timeout=ssh_timeout):
102 ssh.prepare_iperf(vm_info[i]['fip'], private_key=private_key)
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300103 mtus.append(transport1.get_mtu_from_vm(
104 vm_info[i]['fip'], private_key=private_key))
105 logger.info("MTU at networks: {}, {}".format(os_resources['net1']['mtu'],
106 os_resources['net2']['mtu']))
107 logger.info("MTU at VMs: {}".format(", ".join(mtus)))
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200108
109 # Prepare the result table and run iperf3
110 table_rows = []
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300111 table_rows.append(['Test Case', 'Host 1', 'Host 2',
112 'MTU at VMs', 'Result'])
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200113 # Do iperf3 measurement #1
114 logger.info("Doing 'VM to VM in same tenant on same node via Private "
115 "IP, 1 thread' measurement...")
116 result1 = transport1.exec_command(
117 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
118 vm_info[1]['private_address'], iperf_time))
119 res1 = (b" ".join(result1.split()[-4:-2:])).decode('utf-8')
120 logger.info("Result #1 is {}".format(res1))
121 table_rows.append(['VM to VM in same tenant on same node via '
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +0300122 'Private IP, 1 thread; iperf3',
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200123 "{}".format(pair[0]),
124 "{}".format(pair[0]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300125 "{}, {}".format(mtus[0], mtus[1]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200126 "{}".format(res1)])
127
128 # Do iperf3 measurement #2
129 logger.info("Doing 'VM to VM in same tenant on different HW nodes "
130 "via Private IP, 1 thread' measurement...")
131 result2 = transport1.exec_command(
132 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
133 vm_info[2]['private_address'], iperf_time))
134 res2 = (b" ".join(result2.split()[-4:-2:])).decode('utf-8')
135 logger.info("Result #2 is {}".format(res2))
136 table_rows.append(['VM to VM in same tenant on different HW nodes '
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +0300137 'via Private IP, 1 thread; iperf3',
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200138 "{}".format(pair[0]),
139 "{}".format(pair[1]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300140 "{}, {}".format(mtus[0], mtus[2]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200141 "{}".format(res2)])
142
143 # Do iperf3 measurement #3
144 logger.info("Doing 'VM to VM in same tenant on different HW nodes "
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +0300145 "via Private IP, {} threads' measurement..."
146 "".format(threads))
Ievgeniia Zadorozhna90aa8022022-08-11 18:00:23 +0300147 if iperf_utility == "iperf3":
148 result3 = transport1.exec_command(
149 '{} -c {} -P {} -t {} | grep sender | tail -n 1'
150 ''.format(iperf_utility, vm_info[2]['private_address'],
151 threads, iperf_time))
152 res3 = (b" ".join(result3.split()[-4:-2:])).decode('utf-8')
153 else:
154 iperf_utility = "iperf"
155 result3 = transport1.exec_command(
156 '{} -c {} -P {} -t {} | tail -n 1'.format(iperf_utility,
157 vm_info[2]['private_address'], threads, iperf_time))
158 res3 = (b" ".join(result3.split()[-2::])).decode('utf-8')
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200159 logger.info("Result #3 is {}".format(res3))
160 table_rows.append(['VM to VM in same tenant on different HW nodes '
Ievgeniia Zadorozhna90aa8022022-08-11 18:00:23 +0300161 'via Private IP, {} threads; {}'
162 ''.format(threads, iperf_utility),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200163 "{}".format(pair[0]),
164 "{}".format(pair[1]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300165 "{}, {}".format(mtus[0], mtus[2]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200166 "{}".format(res3)])
167
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +0300168 # Do iperf (v2) measurement #4
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200169 logger.info("Doing 'VM to VM in same tenant via Floating IP and VMs "
170 "are on different nodes, 1 thread' measurement...")
171 result4 = transport1.exec_command(
172 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
173 vm_info[2]['fip'], iperf_time))
174 res4 = (b" ".join(result4.split()[-4:-2:])).decode('utf-8')
175 logger.info("Result #4 is {}".format(res4))
176 table_rows.append(['VM to VM in same tenant via Floating IP and VMs '
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +0300177 'are on different nodes, 1 thread; iperf3',
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200178 "{}".format(pair[0]),
179 "{}".format(pair[1]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300180 "{}, {}".format(mtus[0], mtus[2]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200181 "{}".format(res4)])
182
183 # Do iperf3 measurement #5
184 logger.info("Doing 'VM to VM in same tenant, different HW nodes and "
185 "each VM is connected to separate network which are "
186 " connected using Router via Private IP, 1 thread' "
187 "measurement...")
188 result5 = transport1.exec_command(
189 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
190 vm_info[3]['private_address'], iperf_time))
191 res5 = (b" ".join(result5.split()[-4:-2:])).decode('utf-8')
192 logger.info("Result #5 is {}".format(res5))
193 table_rows.append(['VM to VM in same tenant, different HW nodes and '
194 'each VM is connected to separate network which are'
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +0300195 ' connected using Router via Private IP, 1 thread; '
196 'iperf3',
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200197 "{}".format(pair[0]),
198 "{}".format(pair[1]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300199 "{}, {}".format(mtus[0], mtus[3]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200200 "{}".format(res5)])
201
202 logger.info("Drawing the table with iperf results...")
203 result_table.add_rows(table_rows)
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +0300204 sys.stdout.write('\n{}\n'.format(result_table.draw()))
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200205
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200206 logger.info("Removing VMs and FIPs...")
207 for vm in vms:
208 openstack_clients.compute.servers.delete(vm)
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +0300209 logger.info("Removing FIPs...")
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200210 for fip in fips:
211 openstack_clients.compute.floating_ips.delete(fip)
212 except Exception as e:
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +0300213 sys.stdout.write("\n{}".format(e))
214 sys.stdout.write("\nSomething went wrong\n")
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200215 if 'vms' in locals():
216 logger.info("Removing VMs...")
217 for vm in vms:
218 openstack_clients.compute.servers.delete(vm)
219 if 'fips' in locals():
220 logger.info("Removing FIPs...")
221 for fip in fips:
222 openstack_clients.compute.floating_ips.delete(fip)
223 else:
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +0300224 sys.stdout.write("\nSkipping cleaning, VMs were not created")
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200225 pytest.fail("Something went wrong")