blob: fc93347cffc0da3b89ff5956d86ee19d331bcefc [file] [log] [blame]
Hanna Arhipova55cc1292019-01-08 14:22:18 +02001import os
2import random
3import time
4import pytest
Hanna Arhipova16e93fb2019-01-23 19:03:01 +02005import utils
6from utils import os_client
7from utils import ssh
Hanna Arhipova55cc1292019-01-08 14:22:18 +02008
9
Hanna Arhipova04ac2002019-03-01 13:12:41 +020010def test_vm2vm(openstack_clients, pair, os_resources, record_property):
Hanna Arhipova55cc1292019-01-08 14:22:18 +020011 os_actions = os_client.OSCliActions(openstack_clients)
12 config = utils.get_configuration()
13 timeout = int(config.get('nova_timeout', 30))
14 try:
15 zone1 = [service.zone for service in openstack_clients.compute.services.list() if service.host == pair[0]]
16 zone2 = [service.zone for service in openstack_clients.compute.services.list() if service.host == pair[1]]
17 vm1 = os_actions.create_basic_server(os_resources['image_id'],
18 os_resources['flavor_id'],
19 os_resources['net1'],
20 '{0}:{1}'.format(zone1[0],pair[0]),
21 [os_resources['sec_group'].name],
22 os_resources['keypair'].name)
23
24 vm2 = os_actions.create_basic_server(os_resources['image_id'],
25 os_resources['flavor_id'],
26 os_resources['net1'],
27 '{0}:{1}'.format(zone1[0],pair[0]),
28 [os_resources['sec_group'].name],
29 os_resources['keypair'].name)
30
31 vm3 = os_actions.create_basic_server(os_resources['image_id'],
32 os_resources['flavor_id'],
33 os_resources['net1'],
34 '{0}:{1}'.format(zone2[0],pair[1]),
35 [os_resources['sec_group'].name],
36 os_resources['keypair'].name)
37
38 vm4 = os_actions.create_basic_server(os_resources['image_id'],
39 os_resources['flavor_id'],
40 os_resources['net2'],
41 '{0}:{1}'.format(zone2[0],pair[1]),
42 [os_resources['sec_group'].name],
43 os_resources['keypair'].name)
44
45 vm_info = []
46 vms = []
47 vms.extend([vm1,vm2,vm3,vm4])
48 fips = []
49 time.sleep(5)
50 for i in range(4):
51 fip = openstack_clients.compute.floating_ips.create(os_resources['ext_net']['name'])
52 fips.append(fip.id)
53 status = openstack_clients.compute.servers.get(vms[i]).status
54 if status != 'ACTIVE':
Hanna Arhipova04ac2002019-03-01 13:12:41 +020055 print("VM #{0} {1} is not ready. Status {2}".format(i,vms[i].id,status))
Hanna Arhipova55cc1292019-01-08 14:22:18 +020056 time.sleep(timeout)
57 status = openstack_clients.compute.servers.get(vms[i]).status
58 if status != 'ACTIVE':
59 raise Exception('VM is not ready')
60 vms[i].add_floating_ip(fip)
61 private_address = vms[i].addresses[vms[i].addresses.keys()[0]][0]['addr']
62 time.sleep(5)
63 try:
64 ssh.prepare_iperf(fip.ip,private_key=os_resources['keypair'].private_key)
65 except Exception as e:
Hanna Arhipova04ac2002019-03-01 13:12:41 +020066 print(e)
67 print("ssh.prepare_iperf was not successful, retry after {} sec".format(timeout))
Hanna Arhipova55cc1292019-01-08 14:22:18 +020068 time.sleep(timeout)
69 ssh.prepare_iperf(fip.ip,private_key=os_resources['keypair'].private_key)
Hanna Arhipova04ac2002019-03-01 13:12:41 +020070 vm_info.append({'vm': vms[i], 'fip': fip.ip, 'private_address': private_address})
71
Hanna Arhipova55cc1292019-01-08 14:22:18 +020072 transport1 = ssh.SSHTransport(vm_info[0]['fip'], 'ubuntu', password='dd', private_key=os_resources['keypair'].private_key)
73
Ievgeniia Zadorozhna42ed43a2019-01-27 23:58:35 +030074 result1 = transport1.exec_command('iperf -c {} -t 60 | tail -n 1'.format(vm_info[1]['private_address']))
Hanna Arhipova04ac2002019-03-01 13:12:41 +020075 print(' '.join(result1.split()[-2::]))
76
Hanna Arhipova55cc1292019-01-08 14:22:18 +020077 record_property("same {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result1.split()[-2::]))
Ievgeniia Zadorozhna42ed43a2019-01-27 23:58:35 +030078 result2 = transport1.exec_command('iperf -c {} -t 60 | tail -n 1'.format(vm_info[2]['private_address']))
Hanna Arhipova04ac2002019-03-01 13:12:41 +020079 print(' '.join(result2.split()[-2::]))
80
Hanna Arhipova55cc1292019-01-08 14:22:18 +020081 record_property("diff host {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result2.split()[-2::]))
Ievgeniia Zadorozhna42ed43a2019-01-27 23:58:35 +030082 result3 = transport1.exec_command('iperf -c {} -P 10 -t 60 | tail -n 1'.format(vm_info[2]['private_address']))
Hanna Arhipova04ac2002019-03-01 13:12:41 +020083 print(' '.join(result3.split()[-2::]))
84
Hanna Arhipova55cc1292019-01-08 14:22:18 +020085 record_property("dif host 10 threads {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result3.split()[-2::]))
Ievgeniia Zadorozhna42ed43a2019-01-27 23:58:35 +030086 result4 = transport1.exec_command('iperf -c {} -t 60 | tail -n 1'.format(vm_info[2]['fip']))
Hanna Arhipova04ac2002019-03-01 13:12:41 +020087 print(' '.join(result4.split()[-2::]))
88
Hanna Arhipova55cc1292019-01-08 14:22:18 +020089 record_property("diff host fip {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result4.split()[-2::]))
Ievgeniia Zadorozhna42ed43a2019-01-27 23:58:35 +030090 result5 = transport1.exec_command('iperf -c {} -t 60 | tail -n 1'.format(vm_info[3]['private_address']))
Hanna Arhipova04ac2002019-03-01 13:12:41 +020091 print(' '.join(result5.split()[-2::]))
92
Hanna Arhipova55cc1292019-01-08 14:22:18 +020093 record_property("diff host, diff net {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result5.split()[-2::]))
94
Hanna Arhipova04ac2002019-03-01 13:12:41 +020095 print("Remove VMs")
Hanna Arhipova55cc1292019-01-08 14:22:18 +020096 for vm in vms:
97 openstack_clients.compute.servers.delete(vm)
Hanna Arhipova04ac2002019-03-01 13:12:41 +020098 print("Remove FIPs")
Hanna Arhipova55cc1292019-01-08 14:22:18 +020099 for fip in fips:
100 openstack_clients.compute.floating_ips.delete(fip)
101 except Exception as e:
Hanna Arhipova04ac2002019-03-01 13:12:41 +0200102 print(e)
103 print("Something went wrong")
Hanna Arhipova55cc1292019-01-08 14:22:18 +0200104 for vm in vms:
105 openstack_clients.compute.servers.delete(vm)
106 for fip in fips:
107 openstack_clients.compute.floating_ips.delete(fip)
108 pytest.fail("Something went wrong")