blob: 21632c2dd155271a1913b2cfed116038b574412d [file] [log] [blame]
Hanna Arhipova55cc1292019-01-08 14:22:18 +02001from netaddr import IPNetwork, IPAddress
2
Ievgeniia Zadorozhna10acf3e2019-10-02 18:41:49 +03003import pytest
Hanna Arhipova55cc1292019-01-08 14:22:18 +02004
Ievgeniia Zadorozhna10acf3e2019-10-02 18:41:49 +03005import utils
6from utils import helpers
7
8
9def 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
20def test_hw2hw (local_salt_client, hw_pair, record_property):
Hanna Arhipova55cc1292019-01-08 14:22:18 +020021 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 Zadorozhna10acf3e2019-10-02 18:41:49 +030029
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 Arhipova55cc1292019-01-08 14:22:18 +020037 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)