blob: d3c71783d0377aca73920b16cdfb71246db0d118 [file] [log] [blame]
Hanna Arhipova55cc1292019-01-08 14:22:18 +02001import os
2import random
3import time
Ievgeniia Zadorozhnaadb49642019-10-01 18:27:50 +03004
Hanna Arhipova55cc1292019-01-08 14:22:18 +02005import pytest
Ievgeniia Zadorozhnaadb49642019-10-01 18:27:50 +03006from texttable import Texttable
7
Hanna Arhipova16e93fb2019-01-23 19:03:01 +02008import utils
9from utils import os_client
10from utils import ssh
Hanna Arhipova55cc1292019-01-08 14:22:18 +020011
12
Hanna Arhipova04ac2002019-03-01 13:12:41 +020013def test_vm2vm(openstack_clients, pair, os_resources, record_property):
Hanna Arhipova55cc1292019-01-08 14:22:18 +020014 os_actions = os_client.OSCliActions(openstack_clients)
15 config = utils.get_configuration()
16 timeout = int(config.get('nova_timeout', 30))
Ievgeniia Zadorozhnaadb49642019-10-01 18:27:50 +030017 result_table = Texttable()
Hanna Arhipova55cc1292019-01-08 14:22:18 +020018 try:
19 zone1 = [service.zone for service in openstack_clients.compute.services.list() if service.host == pair[0]]
20 zone2 = [service.zone for service in openstack_clients.compute.services.list() if service.host == pair[1]]
21 vm1 = os_actions.create_basic_server(os_resources['image_id'],
22 os_resources['flavor_id'],
23 os_resources['net1'],
24 '{0}:{1}'.format(zone1[0],pair[0]),
25 [os_resources['sec_group'].name],
26 os_resources['keypair'].name)
27
28 vm2 = os_actions.create_basic_server(os_resources['image_id'],
29 os_resources['flavor_id'],
30 os_resources['net1'],
31 '{0}:{1}'.format(zone1[0],pair[0]),
32 [os_resources['sec_group'].name],
33 os_resources['keypair'].name)
34
35 vm3 = os_actions.create_basic_server(os_resources['image_id'],
36 os_resources['flavor_id'],
37 os_resources['net1'],
38 '{0}:{1}'.format(zone2[0],pair[1]),
39 [os_resources['sec_group'].name],
40 os_resources['keypair'].name)
41
42 vm4 = os_actions.create_basic_server(os_resources['image_id'],
43 os_resources['flavor_id'],
44 os_resources['net2'],
45 '{0}:{1}'.format(zone2[0],pair[1]),
46 [os_resources['sec_group'].name],
47 os_resources['keypair'].name)
48
49 vm_info = []
50 vms = []
51 vms.extend([vm1,vm2,vm3,vm4])
52 fips = []
53 time.sleep(5)
54 for i in range(4):
55 fip = openstack_clients.compute.floating_ips.create(os_resources['ext_net']['name'])
56 fips.append(fip.id)
57 status = openstack_clients.compute.servers.get(vms[i]).status
58 if status != 'ACTIVE':
Hanna Arhipova04ac2002019-03-01 13:12:41 +020059 print("VM #{0} {1} is not ready. Status {2}".format(i,vms[i].id,status))
Hanna Arhipova55cc1292019-01-08 14:22:18 +020060 time.sleep(timeout)
61 status = openstack_clients.compute.servers.get(vms[i]).status
62 if status != 'ACTIVE':
63 raise Exception('VM is not ready')
64 vms[i].add_floating_ip(fip)
65 private_address = vms[i].addresses[vms[i].addresses.keys()[0]][0]['addr']
66 time.sleep(5)
67 try:
68 ssh.prepare_iperf(fip.ip,private_key=os_resources['keypair'].private_key)
69 except Exception as e:
Hanna Arhipova04ac2002019-03-01 13:12:41 +020070 print(e)
71 print("ssh.prepare_iperf was not successful, retry after {} sec".format(timeout))
Hanna Arhipova55cc1292019-01-08 14:22:18 +020072 time.sleep(timeout)
73 ssh.prepare_iperf(fip.ip,private_key=os_resources['keypair'].private_key)
Hanna Arhipova04ac2002019-03-01 13:12:41 +020074 vm_info.append({'vm': vms[i], 'fip': fip.ip, 'private_address': private_address})
75
Hanna Arhipova55cc1292019-01-08 14:22:18 +020076 transport1 = ssh.SSHTransport(vm_info[0]['fip'], 'ubuntu', password='dd', private_key=os_resources['keypair'].private_key)
Ievgeniia Zadorozhnaadb49642019-10-01 18:27:50 +030077 table_rows = []
78 table_rows.append(['Test Case', 'Host 1', 'Host 2', 'Result'])
Hanna Arhipova55cc1292019-01-08 14:22:18 +020079
Ievgeniia Zadorozhna42ed43a2019-01-27 23:58:35 +030080 result1 = transport1.exec_command('iperf -c {} -t 60 | tail -n 1'.format(vm_info[1]['private_address']))
Ievgeniia Zadorozhnaadb49642019-10-01 18:27:50 +030081 res1 = ' '.join(result1.split()[-2::])
82 table_rows.append(['VM to VM in same tenant on same node via Private IP, 1 thread',
83 "{}".format(pair[0]),
84 "{}".format(pair[0]),
85 "{}".format(res1)])
Hanna Arhipova04ac2002019-03-01 13:12:41 +020086
Ievgeniia Zadorozhna42ed43a2019-01-27 23:58:35 +030087 result2 = transport1.exec_command('iperf -c {} -t 60 | tail -n 1'.format(vm_info[2]['private_address']))
Ievgeniia Zadorozhnaadb49642019-10-01 18:27:50 +030088 res2 = ' '.join(result2.split()[-2::])
89 table_rows.append(['VM to VM in same tenant on different HW nodes via Private IP, 1 thread',
90 "{}".format(pair[0]),
91 "{}".format(pair[1]),
92 "{}".format(res2)])
Hanna Arhipova04ac2002019-03-01 13:12:41 +020093
Ievgeniia Zadorozhna42ed43a2019-01-27 23:58:35 +030094 result3 = transport1.exec_command('iperf -c {} -P 10 -t 60 | tail -n 1'.format(vm_info[2]['private_address']))
Ievgeniia Zadorozhnaadb49642019-10-01 18:27:50 +030095 res3 = ' '.join(result3.split()[-2::])
96 table_rows.append(['VM to VM in same tenant on different HW nodes via Private IP, 10 threads',
97 "{}".format(pair[0]),
98 "{}".format(pair[1]),
99 "{}".format(res3)])
Hanna Arhipova04ac2002019-03-01 13:12:41 +0200100
Ievgeniia Zadorozhna42ed43a2019-01-27 23:58:35 +0300101 result4 = transport1.exec_command('iperf -c {} -t 60 | tail -n 1'.format(vm_info[2]['fip']))
Ievgeniia Zadorozhnaadb49642019-10-01 18:27:50 +0300102 res4 = ' '.join(result4.split()[-2::])
103 table_rows.append(['VM to VM in same tenant via Floating IP and VMs are on different nodes, 1 thread',
104 "{}".format(pair[0]),
105 "{}".format(pair[1]),
106 "{}".format(res4)])
Hanna Arhipova04ac2002019-03-01 13:12:41 +0200107
Ievgeniia Zadorozhna42ed43a2019-01-27 23:58:35 +0300108 result5 = transport1.exec_command('iperf -c {} -t 60 | tail -n 1'.format(vm_info[3]['private_address']))
Ievgeniia Zadorozhnaadb49642019-10-01 18:27:50 +0300109 res5 = ' '.join(result5.split()[-2::])
110 table_rows.append(['VM to VM in same tenant, different HW nodes and each VM is connected to separate network which are connected using Router via Private IP, 1 thread',
111 "{}".format(pair[0]),
112 "{}".format(pair[1]),
113 "{}".format(res5)])
Hanna Arhipova04ac2002019-03-01 13:12:41 +0200114
Ievgeniia Zadorozhnaadb49642019-10-01 18:27:50 +0300115 result_table.add_rows(table_rows)
116 print(result_table.draw())
Hanna Arhipova55cc1292019-01-08 14:22:18 +0200117
Ievgeniia Zadorozhnaadb49642019-10-01 18:27:50 +0300118 print("Removing VMs...")
Hanna Arhipova55cc1292019-01-08 14:22:18 +0200119 for vm in vms:
120 openstack_clients.compute.servers.delete(vm)
Ievgeniia Zadorozhnaadb49642019-10-01 18:27:50 +0300121 print("Removing FIPs...")
Hanna Arhipova55cc1292019-01-08 14:22:18 +0200122 for fip in fips:
123 openstack_clients.compute.floating_ips.delete(fip)
124 except Exception as e:
Hanna Arhipova04ac2002019-03-01 13:12:41 +0200125 print(e)
126 print("Something went wrong")
Hanna Arhipova55cc1292019-01-08 14:22:18 +0200127 for vm in vms:
128 openstack_clients.compute.servers.delete(vm)
129 for fip in fips:
130 openstack_clients.compute.floating_ips.delete(fip)
131 pytest.fail("Something went wrong")