blob: 4367ee89dd2f05a20180bf2ad9ba495be87e6278 [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
24 6. Measure VM to VM on different HW nodes via Private IP, 10 threads
25 7. Measure VM to VM on different HW nodes via Floating IP, 1 thread
26 8. Measure VM to VM on different HW nodes, each VM is in separate network,
27 the networks are connected using Router via Private IP, 1 thread
28 9. Draw the table with all pairs and results
29 """
30 os_actions = os_client.OSCliActions(openstack_clients)
31 config = utils.get_configuration()
32 timeout = int(config.get('nova_timeout', 30))
33 iperf_time = int(config.get('iperf_time', 60))
34 private_key = os_resources['keypair'].private_key
35 ssh_timeout = int(config.get('ssh_timeout', 500))
36 result_table = Texttable()
37
38 try:
39 zone1 = [service.zone for service in
40 openstack_clients.compute.services.list() if
41 service.host == pair[0]]
42 zone2 = [service.zone for service in
43 openstack_clients.compute.services.list()
44 if service.host == pair[1]]
45
46 # create 4 VMs
47 logger.info("Creating 4 VMs...")
48 vm1 = os_actions.create_basic_server(
49 os_resources['image_id'], os_resources['flavor_id'],
50 os_resources['net1'], '{0}:{1}'.format(zone1[0], pair[0]),
51 [os_resources['sec_group'].name], os_resources['keypair'].name)
52 logger.info("Created VM {}.".format(vm1.id))
53
54 vm2 = os_actions.create_basic_server(
55 os_resources['image_id'], os_resources['flavor_id'],
56 os_resources['net1'], '{0}:{1}'.format(zone1[0], pair[0]),
57 [os_resources['sec_group'].name], os_resources['keypair'].name)
58 logger.info("Created VM {}.".format(vm2.id))
59
60 vm3 = os_actions.create_basic_server(
61 os_resources['image_id'], os_resources['flavor_id'],
62 os_resources['net1'], '{0}:{1}'.format(zone2[0], pair[1]),
63 [os_resources['sec_group'].name], os_resources['keypair'].name)
64 logger.info("Created VM {}.".format(vm3.id))
65
66 vm4 = os_actions.create_basic_server(
67 os_resources['image_id'], os_resources['flavor_id'],
68 os_resources['net2'], '{0}:{1}'.format(zone2[0], pair[1]),
69 [os_resources['sec_group'].name], os_resources['keypair'].name)
70 logger.info("Created VM {}.".format(vm4.id))
71
72 vm_info = []
73 vms = []
74 vms.extend([vm1, vm2, vm3, vm4])
75 fips = []
76 time.sleep(5)
77
78 # Associate FIPs and check VMs are Active
79 logger.info("Creating Floating IPs and associating them...")
80 for i in range(4):
81 fip = openstack_clients.compute.floating_ips.create(
82 os_resources['ext_net']['name'])
83 fips.append(fip.id)
84 os_actions.check_vm_is_active(vms[i].id, timeout=timeout)
85 vms[i].add_floating_ip(fip)
86 private_address = vms[i].addresses[
87 list(vms[i].addresses.keys())[0]][0]['addr']
88 vm_info.append({'vm': vms[i], 'fip': fip.ip,
89 'private_address': private_address})
90 # Check VMs are reachable and prepare iperf3
91 transport1 = ssh.SSHTransport(vm_info[0]['fip'], 'ubuntu',
92 password='dd', private_key=private_key)
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +030093 logger.info("Checking VMs are reachable via SSH, getting MTU...")
94 mtus = []
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +020095 for i in range(4):
96 if transport1.check_vm_is_reachable_ssh(
97 floating_ip=vm_info[i]['fip'], timeout=ssh_timeout):
98 ssh.prepare_iperf(vm_info[i]['fip'], private_key=private_key)
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +030099 mtus.append(transport1.get_mtu_from_vm(
100 vm_info[i]['fip'], private_key=private_key))
101 logger.info("MTU at networks: {}, {}".format(os_resources['net1']['mtu'],
102 os_resources['net2']['mtu']))
103 logger.info("MTU at VMs: {}".format(", ".join(mtus)))
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200104
105 # Prepare the result table and run iperf3
106 table_rows = []
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300107 table_rows.append(['Test Case', 'Host 1', 'Host 2',
108 'MTU at VMs', 'Result'])
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200109 # Do iperf3 measurement #1
110 logger.info("Doing 'VM to VM in same tenant on same node via Private "
111 "IP, 1 thread' measurement...")
112 result1 = transport1.exec_command(
113 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
114 vm_info[1]['private_address'], iperf_time))
115 res1 = (b" ".join(result1.split()[-4:-2:])).decode('utf-8')
116 logger.info("Result #1 is {}".format(res1))
117 table_rows.append(['VM to VM in same tenant on same node via '
118 'Private IP, 1 thread',
119 "{}".format(pair[0]),
120 "{}".format(pair[0]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300121 "{}, {}".format(mtus[0], mtus[1]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200122 "{}".format(res1)])
123
124 # Do iperf3 measurement #2
125 logger.info("Doing 'VM to VM in same tenant on different HW nodes "
126 "via Private IP, 1 thread' measurement...")
127 result2 = transport1.exec_command(
128 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
129 vm_info[2]['private_address'], iperf_time))
130 res2 = (b" ".join(result2.split()[-4:-2:])).decode('utf-8')
131 logger.info("Result #2 is {}".format(res2))
132 table_rows.append(['VM to VM in same tenant on different HW nodes '
133 'via Private IP, 1 thread',
134 "{}".format(pair[0]),
135 "{}".format(pair[1]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300136 "{}, {}".format(mtus[0], mtus[2]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200137 "{}".format(res2)])
138
139 # Do iperf3 measurement #3
140 logger.info("Doing 'VM to VM in same tenant on different HW nodes "
141 "via Private IP, 10 threads' measurement...")
142 result3 = transport1.exec_command(
143 'iperf3 -c {} -P 10 -t {} | grep sender | tail -n 1'.format(
144 vm_info[2]['private_address'], iperf_time))
145 res3 = (b" ".join(result3.split()[-4:-2:])).decode('utf-8')
146 logger.info("Result #3 is {}".format(res3))
147 table_rows.append(['VM to VM in same tenant on different HW nodes '
148 'via Private IP, 10 threads',
149 "{}".format(pair[0]),
150 "{}".format(pair[1]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300151 "{}, {}".format(mtus[0], mtus[2]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200152 "{}".format(res3)])
153
154 # Do iperf3 measurement #4
155 logger.info("Doing 'VM to VM in same tenant via Floating IP and VMs "
156 "are on different nodes, 1 thread' measurement...")
157 result4 = transport1.exec_command(
158 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
159 vm_info[2]['fip'], iperf_time))
160 res4 = (b" ".join(result4.split()[-4:-2:])).decode('utf-8')
161 logger.info("Result #4 is {}".format(res4))
162 table_rows.append(['VM to VM in same tenant via Floating IP and VMs '
163 'are on different nodes, 1 thread',
164 "{}".format(pair[0]),
165 "{}".format(pair[1]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300166 "{}, {}".format(mtus[0], mtus[2]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200167 "{}".format(res4)])
168
169 # Do iperf3 measurement #5
170 logger.info("Doing 'VM to VM in same tenant, different HW nodes and "
171 "each VM is connected to separate network which are "
172 " connected using Router via Private IP, 1 thread' "
173 "measurement...")
174 result5 = transport1.exec_command(
175 'iperf3 -c {} -t {} | grep sender | tail -n 1'.format(
176 vm_info[3]['private_address'], iperf_time))
177 res5 = (b" ".join(result5.split()[-4:-2:])).decode('utf-8')
178 logger.info("Result #5 is {}".format(res5))
179 table_rows.append(['VM to VM in same tenant, different HW nodes and '
180 'each VM is connected to separate network which are'
181 ' connected using Router via Private IP, 1 thread',
182 "{}".format(pair[0]),
183 "{}".format(pair[1]),
Ievgeniia Zadorozhna0facf3c2022-06-16 16:19:09 +0300184 "{}, {}".format(mtus[0], mtus[3]),
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200185 "{}".format(res5)])
186
187 logger.info("Drawing the table with iperf results...")
188 result_table.add_rows(table_rows)
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +0300189 sys.stdout.write('\n{}\n'.format(result_table.draw()))
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200190
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200191 logger.info("Removing VMs and FIPs...")
192 for vm in vms:
193 openstack_clients.compute.servers.delete(vm)
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +0300194 logger.info("Removing FIPs...")
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200195 for fip in fips:
196 openstack_clients.compute.floating_ips.delete(fip)
197 except Exception as e:
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +0300198 sys.stdout.write("\n{}".format(e))
199 sys.stdout.write("\nSomething went wrong\n")
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200200 if 'vms' in locals():
201 logger.info("Removing VMs...")
202 for vm in vms:
203 openstack_clients.compute.servers.delete(vm)
204 if 'fips' in locals():
205 logger.info("Removing FIPs...")
206 for fip in fips:
207 openstack_clients.compute.floating_ips.delete(fip)
208 else:
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +0300209 sys.stdout.write("\nSkipping cleaning, VMs were not created")
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +0200210 pytest.fail("Something went wrong")