blob: 9c6d1072cad4dfe0f00d47e8b6fb2c0c9f95d86e [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))
38 result_table = Texttable(max_width=120)
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +020039
40 try:
41 zone1 = [service.zone for service in
42 openstack_clients.compute.services.list() if
43 service.host == pair[0]]
44 zone2 = [service.zone for service in
45 openstack_clients.compute.services.list()
46 if service.host == pair[1]]
47
48 # create 4 VMs
49 logger.info("Creating 4 VMs...")
50 vm1 = os_actions.create_basic_server(
51 os_resources['image_id'], os_resources['flavor_id'],
52 os_resources['net1'], '{0}:{1}'.format(zone1[0], pair[0]),
53 [os_resources['sec_group'].name], os_resources['keypair'].name)
54 logger.info("Created VM {}.".format(vm1.id))
55
56 vm2 = os_actions.create_basic_server(
57 os_resources['image_id'], os_resources['flavor_id'],
58 os_resources['net1'], '{0}:{1}'.format(zone1[0], pair[0]),
59 [os_resources['sec_group'].name], os_resources['keypair'].name)
60 logger.info("Created VM {}.".format(vm2.id))
61
62 vm3 = os_actions.create_basic_server(
63 os_resources['image_id'], os_resources['flavor_id'],
64 os_resources['net1'], '{0}:{1}'.format(zone2[0], pair[1]),
65 [os_resources['sec_group'].name], os_resources['keypair'].name)
66 logger.info("Created VM {}.".format(vm3.id))
67
68 vm4 = os_actions.create_basic_server(
69 os_resources['image_id'], os_resources['flavor_id'],
70 os_resources['net2'], '{0}:{1}'.format(zone2[0], pair[1]),
71 [os_resources['sec_group'].name], os_resources['keypair'].name)
72 logger.info("Created VM {}.".format(vm4.id))
73
74 vm_info = []
75 vms = []
76 vms.extend([vm1, vm2, vm3, vm4])
77 fips = []
78 time.sleep(5)
79
80 # Associate FIPs and check VMs are Active
81 logger.info("Creating Floating IPs and associating them...")
82 for i in range(4):
83 fip = openstack_clients.compute.floating_ips.create(
84 os_resources['ext_net']['name'])
85 fips.append(fip.id)
86 os_actions.check_vm_is_active(vms[i].id, timeout=timeout)
87 vms[i].add_floating_ip(fip)
88 private_address = vms[i].addresses[
89 list(vms[i].addresses.keys())[0]][0]['addr']
90 vm_info.append({'vm': vms[i], 'fip': fip.ip,
91 'private_address': private_address})
92 # Check VMs are reachable and prepare iperf3
93 transport1 = ssh.SSHTransport(vm_info[0]['fip'], 'ubuntu',
94 password='dd', private_key=private_key)
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +030095 logger.info("Checking VMs are reachable via SSH, getting MTU...")
96 mtus = []
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +020097 for i in range(4):
98 if transport1.check_vm_is_reachable_ssh(
99 floating_ip=vm_info[i]['fip'], timeout=ssh_timeout):
100 ssh.prepare_iperf(vm_info[i]['fip'], private_key=private_key)
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300101 mtus.append(transport1.get_mtu_from_vm(
102 vm_info[i]['fip'], private_key=private_key))
103 logger.info("MTU at networks: {}, {}".format(os_resources['net1']['mtu'],
104 os_resources['net2']['mtu']))
105 logger.info("MTU at VMs: {}".format(", ".join(mtus)))
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200106
107 # Prepare the result table and run iperf3
108 table_rows = []
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300109 table_rows.append(['Test Case', 'Host 1', 'Host 2',
110 'MTU at VMs', 'Result'])
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200111 # Do iperf3 measurement #1
112 logger.info("Doing 'VM to VM in same tenant on same node via Private "
113 "IP, 1 thread' measurement...")
114 result1 = transport1.exec_command(
115 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
116 vm_info[1]['private_address'], iperf_time))
117 res1 = (b" ".join(result1.split()[-4:-2:])).decode('utf-8')
118 logger.info("Result #1 is {}".format(res1))
119 table_rows.append(['VM to VM in same tenant on same node via '
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +0300120 'Private IP, 1 thread; iperf3',
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200121 "{}".format(pair[0]),
122 "{}".format(pair[0]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300123 "{}, {}".format(mtus[0], mtus[1]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200124 "{}".format(res1)])
125
126 # Do iperf3 measurement #2
127 logger.info("Doing 'VM to VM in same tenant on different HW nodes "
128 "via Private IP, 1 thread' measurement...")
129 result2 = transport1.exec_command(
130 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
131 vm_info[2]['private_address'], iperf_time))
132 res2 = (b" ".join(result2.split()[-4:-2:])).decode('utf-8')
133 logger.info("Result #2 is {}".format(res2))
134 table_rows.append(['VM to VM in same tenant on different HW nodes '
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +0300135 'via Private IP, 1 thread; iperf3',
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200136 "{}".format(pair[0]),
137 "{}".format(pair[1]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300138 "{}, {}".format(mtus[0], mtus[2]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200139 "{}".format(res2)])
140
141 # Do iperf3 measurement #3
142 logger.info("Doing 'VM to VM in same tenant on different HW nodes "
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +0300143 "via Private IP, {} threads' measurement..."
144 "".format(threads))
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200145 result3 = transport1.exec_command(
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +0300146 'iperf -c {} -P {} -t {} | tail -n 1'.format(
147 vm_info[2]['private_address'], threads, iperf_time))
148 res3 = (b" ".join(result3.split()[-2::])).decode('utf-8')
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200149 logger.info("Result #3 is {}".format(res3))
150 table_rows.append(['VM to VM in same tenant on different HW nodes '
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +0300151 'via Private IP, {} threads; iperf (v2)'.format(threads),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200152 "{}".format(pair[0]),
153 "{}".format(pair[1]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300154 "{}, {}".format(mtus[0], mtus[2]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200155 "{}".format(res3)])
156
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +0300157 # Do iperf (v2) measurement #4
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200158 logger.info("Doing 'VM to VM in same tenant via Floating IP and VMs "
159 "are on different nodes, 1 thread' measurement...")
160 result4 = transport1.exec_command(
161 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
162 vm_info[2]['fip'], iperf_time))
163 res4 = (b" ".join(result4.split()[-4:-2:])).decode('utf-8')
164 logger.info("Result #4 is {}".format(res4))
165 table_rows.append(['VM to VM in same tenant via Floating IP and VMs '
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +0300166 'are on different nodes, 1 thread; iperf3',
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200167 "{}".format(pair[0]),
168 "{}".format(pair[1]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300169 "{}, {}".format(mtus[0], mtus[2]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200170 "{}".format(res4)])
171
172 # Do iperf3 measurement #5
173 logger.info("Doing 'VM to VM in same tenant, different HW nodes and "
174 "each VM is connected to separate network which are "
175 " connected using Router via Private IP, 1 thread' "
176 "measurement...")
177 result5 = transport1.exec_command(
178 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
179 vm_info[3]['private_address'], iperf_time))
180 res5 = (b" ".join(result5.split()[-4:-2:])).decode('utf-8')
181 logger.info("Result #5 is {}".format(res5))
182 table_rows.append(['VM to VM in same tenant, different HW nodes and '
183 'each VM is connected to separate network which are'
Ievgeniia Zadorozhna5ed74e22022-07-26 16:56:23 +0300184 ' connected using Router via Private IP, 1 thread; '
185 'iperf3',
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200186 "{}".format(pair[0]),
187 "{}".format(pair[1]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300188 "{}, {}".format(mtus[0], mtus[3]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200189 "{}".format(res5)])
190
191 logger.info("Drawing the table with iperf results...")
192 result_table.add_rows(table_rows)
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +0300193 sys.stdout.write('\n{}\n'.format(result_table.draw()))
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200194
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200195 logger.info("Removing VMs and FIPs...")
196 for vm in vms:
197 openstack_clients.compute.servers.delete(vm)
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +0300198 logger.info("Removing FIPs...")
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200199 for fip in fips:
200 openstack_clients.compute.floating_ips.delete(fip)
201 except Exception as e:
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +0300202 sys.stdout.write("\n{}".format(e))
203 sys.stdout.write("\nSomething went wrong\n")
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200204 if 'vms' in locals():
205 logger.info("Removing VMs...")
206 for vm in vms:
207 openstack_clients.compute.servers.delete(vm)
208 if 'fips' in locals():
209 logger.info("Removing FIPs...")
210 for fip in fips:
211 openstack_clients.compute.floating_ips.delete(fip)
212 else:
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +0300213 sys.stdout.write("\nSkipping cleaning, VMs were not created")
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200214 pytest.fail("Something went wrong")