Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 1 | from netaddr import IPNetwork, IPAddress |
| 2 | |
Ievgeniia Zadorozhna | 10acf3e | 2019-10-02 18:41:49 +0300 | [diff] [blame] | 3 | import pytest |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 4 | |
Ievgeniia Zadorozhna | 10acf3e | 2019-10-02 18:41:49 +0300 | [diff] [blame] | 5 | import utils |
| 6 | from utils import helpers |
| 7 | |
| 8 | |
| 9 | def network_precheck(local_salt_client, hw_pair, net): |
| 10 | network_present = False |
| 11 | check = local_salt_client.cmd(expr_form='compound', |
| 12 | tgt=str(hw_pair[0]+' or '+hw_pair[1]), |
| 13 | fun='network.in_subnet', |
| 14 | param=['{}'.format(net)]) |
| 15 | if all(check.values()): # if all are True |
| 16 | network_present = True |
| 17 | return network_present |
| 18 | |
| 19 | |
| 20 | def test_hw2hw (local_salt_client, hw_pair, record_property): |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 21 | helpp = helpers.helpers(local_salt_client) |
| 22 | config = utils.get_configuration() |
| 23 | nodes = local_salt_client.cmd(expr_form='compound', tgt=str(hw_pair[0]+' or '+hw_pair[1]), |
| 24 | fun='network.interfaces') |
| 25 | short_name = [] |
| 26 | short_name.append(hw_pair[0].split('.')[0]) |
| 27 | short_name.append(hw_pair[1].split('.')[0]) |
| 28 | nets = config.get('networks').split(',') |
Ievgeniia Zadorozhna | 10acf3e | 2019-10-02 18:41:49 +0300 | [diff] [blame] | 29 | |
| 30 | for net in nets: |
| 31 | precheck = network_precheck(local_salt_client, hw_pair, net) |
| 32 | if not precheck: |
| 33 | pytest.fail("The network {} is not present at the pair {} on one " |
| 34 | "or both nodes. Please recheck and fix 'networks' " |
| 35 | "parameter in the test config.".format(net, hw_pair)) |
| 36 | |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 37 | local_salt_client.cmd(expr_form='compound', tgt=str(hw_pair[0]+' or '+hw_pair[1]), |
| 38 | fun='cmd.run', param=['nohup iperf -s > file 2>&1 &']) |
| 39 | global_results = [] |
| 40 | for net in nets: |
| 41 | for interf in nodes[hw_pair[0]]: |
| 42 | if 'inet' not in nodes[hw_pair[0]][interf].keys(): |
| 43 | continue |
| 44 | ip = nodes[hw_pair[0]][interf]['inet'][0]['address'] |
| 45 | if (IPAddress(ip) in IPNetwork(net)) and (nodes[hw_pair[0]][interf]['inet'][0]['broadcast']): |
| 46 | for interf2 in nodes[hw_pair[1]]: |
| 47 | if 'inet' not in nodes[hw_pair[1]][interf2].keys(): |
| 48 | continue |
| 49 | ip2 = nodes[hw_pair[1]][interf2]['inet'][0]['address'] |
| 50 | if (IPAddress(ip2) in IPNetwork(net)) and (nodes[hw_pair[1]][interf2]['inet'][0]['broadcast']): |
| 51 | print "Will IPERF between {0} and {1}".format(ip,ip2) |
| 52 | try: |
| 53 | res = helpp.start_iperf_between_hosts(global_results, hw_pair[0], hw_pair[1], |
| 54 | ip, ip2, net) |
| 55 | record_property("1-worst {0}-{1}".format(short_name[0],short_name[1]), res[0] if res[0] < res[2] else res[2]) |
| 56 | record_property("1-best {0}-{1}".format(short_name[0],short_name[1]), res[0] if res[0] > res[2] else res[2]) |
| 57 | record_property("10-best {0}-{1}".format(short_name[0],short_name[1]), res[1] if res[1] > res[3] else res[3]) |
| 58 | record_property("10-best {0}-{1}".format(short_name[0],short_name[1]), res[1] if res[1] > res[3] else res[3]) |
| 59 | print "Measurement between {} and {} " \ |
| 60 | "has been finished".format(hw_pair[0], |
| 61 | hw_pair[1]) |
| 62 | except Exception as e: |
| 63 | print "Failed for {0} {1}".format( |
| 64 | hw_pair[0], hw_pair[1]) |
| 65 | print e |
| 66 | local_salt_client.cmd(expr_form='compound', tgt=str(hw_pair[0]+' or '+hw_pair[1]), |
| 67 | fun='cmd.run', param=['killall -9 iperf']) |
| 68 | helpp.draw_table_with_results(global_results) |