blob: 9e1d5d70b39c2a95157b003d517285ce45c8766c [file] [log] [blame]
Hanna Arhipova55cc1292019-01-08 14:22:18 +02001import os
2import random
3import time
4import pytest
5from cvp_spt import utils
6from cvp_spt.utils import os_client
7from cvp_spt.utils import ssh
8
9
10def test_vm2vm (openstack_clients, pair, os_resources, record_property):
11 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':
55 print "VM #{0} {1} is not ready. Status {2}".format(i,vms[i].id,status)
56 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:
66 print e
67 print "ssh.prepare_iperf was not successful, retry after {} sec".format(timeout)
68 time.sleep(timeout)
69 ssh.prepare_iperf(fip.ip,private_key=os_resources['keypair'].private_key)
70 vm_info.append({'vm': vms[i], 'fip': fip.ip, 'private_address': private_address})
71
72 transport1 = ssh.SSHTransport(vm_info[0]['fip'], 'ubuntu', password='dd', private_key=os_resources['keypair'].private_key)
73
74 result1 = transport1.exec_command('iperf -c {} | tail -n 1'.format(vm_info[1]['private_address']))
75 print ' '.join(result1.split()[-2::])
76 record_property("same {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result1.split()[-2::]))
77 result2 = transport1.exec_command('iperf -c {} | tail -n 1'.format(vm_info[2]['private_address']))
78 print ' '.join(result2.split()[-2::])
79 record_property("diff host {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result2.split()[-2::]))
80 result3 = transport1.exec_command('iperf -c {} -P 10 | tail -n 1'.format(vm_info[2]['private_address']))
81 print ' '.join(result3.split()[-2::])
82 record_property("dif host 10 threads {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result3.split()[-2::]))
83 result4 = transport1.exec_command('iperf -c {} | tail -n 1'.format(vm_info[2]['fip']))
84 print ' '.join(result4.split()[-2::])
85 record_property("diff host fip {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result4.split()[-2::]))
86 result5 = transport1.exec_command('iperf -c {} | tail -n 1'.format(vm_info[3]['private_address']))
87 print ' '.join(result5.split()[-2::])
88 record_property("diff host, diff net {0}-{1}".format(zone1[0],zone2[0]), ' '.join(result5.split()[-2::]))
89
90 print "Remove VMs"
91 for vm in vms:
92 openstack_clients.compute.servers.delete(vm)
93 print "Remove FIPs"
94 for fip in fips:
95 openstack_clients.compute.floating_ips.delete(fip)
96 except Exception as e:
97 print e
98 print "Something went wrong"
99 for vm in vms:
100 openstack_clients.compute.servers.delete(vm)
101 for fip in fips:
102 openstack_clients.compute.floating_ips.delete(fip)
103 pytest.fail("Something went wrong")