Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 1 | import os |
| 2 | import random |
| 3 | import time |
Ievgeniia Zadorozhna | adb4964 | 2019-10-01 18:27:50 +0300 | [diff] [blame] | 4 | |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 5 | import pytest |
Ievgeniia Zadorozhna | adb4964 | 2019-10-01 18:27:50 +0300 | [diff] [blame] | 6 | from texttable import Texttable |
| 7 | |
Hanna Arhipova | 16e93fb | 2019-01-23 19:03:01 +0200 | [diff] [blame] | 8 | import utils |
| 9 | from utils import os_client |
| 10 | from utils import ssh |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 11 | |
| 12 | |
Hanna Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 13 | def test_vm2vm(openstack_clients, pair, os_resources, record_property): |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 14 | os_actions = os_client.OSCliActions(openstack_clients) |
| 15 | config = utils.get_configuration() |
| 16 | timeout = int(config.get('nova_timeout', 30)) |
Ievgeniia Zadorozhna | adb4964 | 2019-10-01 18:27:50 +0300 | [diff] [blame] | 17 | result_table = Texttable() |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 18 | 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 Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 59 | 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] | 60 | 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 Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 70 | print(e) |
| 71 | print("ssh.prepare_iperf was not successful, retry after {} sec".format(timeout)) |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 72 | time.sleep(timeout) |
| 73 | ssh.prepare_iperf(fip.ip,private_key=os_resources['keypair'].private_key) |
Hanna Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 74 | vm_info.append({'vm': vms[i], 'fip': fip.ip, 'private_address': private_address}) |
| 75 | |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 76 | transport1 = ssh.SSHTransport(vm_info[0]['fip'], 'ubuntu', password='dd', private_key=os_resources['keypair'].private_key) |
Ievgeniia Zadorozhna | adb4964 | 2019-10-01 18:27:50 +0300 | [diff] [blame] | 77 | table_rows = [] |
| 78 | table_rows.append(['Test Case', 'Host 1', 'Host 2', 'Result']) |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 79 | |
Ievgeniia Zadorozhna | 42ed43a | 2019-01-27 23:58:35 +0300 | [diff] [blame] | 80 | result1 = transport1.exec_command('iperf -c {} -t 60 | tail -n 1'.format(vm_info[1]['private_address'])) |
Ievgeniia Zadorozhna | adb4964 | 2019-10-01 18:27:50 +0300 | [diff] [blame] | 81 | 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 Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 86 | |
Ievgeniia Zadorozhna | 42ed43a | 2019-01-27 23:58:35 +0300 | [diff] [blame] | 87 | result2 = transport1.exec_command('iperf -c {} -t 60 | tail -n 1'.format(vm_info[2]['private_address'])) |
Ievgeniia Zadorozhna | adb4964 | 2019-10-01 18:27:50 +0300 | [diff] [blame] | 88 | 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 Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 93 | |
Ievgeniia Zadorozhna | 42ed43a | 2019-01-27 23:58:35 +0300 | [diff] [blame] | 94 | result3 = transport1.exec_command('iperf -c {} -P 10 -t 60 | tail -n 1'.format(vm_info[2]['private_address'])) |
Ievgeniia Zadorozhna | adb4964 | 2019-10-01 18:27:50 +0300 | [diff] [blame] | 95 | 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 Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 100 | |
Ievgeniia Zadorozhna | 42ed43a | 2019-01-27 23:58:35 +0300 | [diff] [blame] | 101 | result4 = transport1.exec_command('iperf -c {} -t 60 | tail -n 1'.format(vm_info[2]['fip'])) |
Ievgeniia Zadorozhna | adb4964 | 2019-10-01 18:27:50 +0300 | [diff] [blame] | 102 | 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 Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 107 | |
Ievgeniia Zadorozhna | 42ed43a | 2019-01-27 23:58:35 +0300 | [diff] [blame] | 108 | result5 = transport1.exec_command('iperf -c {} -t 60 | tail -n 1'.format(vm_info[3]['private_address'])) |
Ievgeniia Zadorozhna | adb4964 | 2019-10-01 18:27:50 +0300 | [diff] [blame] | 109 | 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 Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 114 | |
Ievgeniia Zadorozhna | adb4964 | 2019-10-01 18:27:50 +0300 | [diff] [blame] | 115 | result_table.add_rows(table_rows) |
| 116 | print(result_table.draw()) |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 117 | |
Ievgeniia Zadorozhna | adb4964 | 2019-10-01 18:27:50 +0300 | [diff] [blame] | 118 | print("Removing VMs...") |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 119 | for vm in vms: |
| 120 | openstack_clients.compute.servers.delete(vm) |
Ievgeniia Zadorozhna | adb4964 | 2019-10-01 18:27:50 +0300 | [diff] [blame] | 121 | print("Removing FIPs...") |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 122 | for fip in fips: |
| 123 | openstack_clients.compute.floating_ips.delete(fip) |
| 124 | except Exception as e: |
Hanna Arhipova | 04ac200 | 2019-03-01 13:12:41 +0200 | [diff] [blame] | 125 | print(e) |
| 126 | print("Something went wrong") |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 127 | 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") |