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