blob: b215c1d24e71e96cfdb29d79add6a608df97e9fb [file] [log] [blame]
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03001import pytest
2import json
3import utils
4import os
5
6
Oleksii Zhurba23c18332019-05-09 18:53:40 -05007@pytest.mark.full
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +03008def test_mtu(local_salt_client, nodes_in_group):
9 testname = os.path.basename(__file__).split('.')[0]
10 config = utils.get_configuration()
11 skipped_ifaces = config.get(testname)["skipped_ifaces"] or \
12 ["bonding_masters", "lo", "veth", "tap", "cali", "qv", "qb", "br-int", "vxlan"]
13 total = {}
14 network_info = local_salt_client.cmd(
15 tgt="L@"+','.join(nodes_in_group),
16 param='ls /sys/class/net/',
17 expr_form='compound')
18
19 kvm_nodes = local_salt_client.test_ping(tgt='salt:control').keys()
20
21 if len(network_info.keys()) < 2:
22 pytest.skip("Nothing to compare - only 1 node")
23
24 for node, ifaces_info in network_info.iteritems():
25 if isinstance(ifaces_info, bool):
26 print ("{} node is skipped".format(node))
27 continue
28 if node in kvm_nodes:
29 kvm_info = local_salt_client.cmd(tgt=node,
30 param="virsh list | "
31 "awk '{print $2}' | "
32 "xargs -n1 virsh domiflist | "
33 "grep -v br-pxe | grep br- | "
34 "awk '{print $1}'")
35 ifaces_info = kvm_info.get(node)
36 node_ifaces = ifaces_info.split('\n')
37 ifaces = {}
38 for iface in node_ifaces:
39 for skipped_iface in skipped_ifaces:
40 if skipped_iface in iface:
41 break
42 else:
43 iface_mtu = local_salt_client.cmd(tgt=node,
44 param='cat /sys/class/'
45 'net/{}/mtu'.format(iface))
46 ifaces[iface] = iface_mtu.get(node)
47 total[node] = ifaces
48
49 nodes = []
50 mtu_data = []
51 my_set = set()
52
53 for node in total:
54 nodes.append(node)
55 my_set.update(total[node].keys())
56 for interf in my_set:
57 diff = []
58 row = []
59 for node in nodes:
60 if interf in total[node].keys():
61 diff.append(total[node][interf])
62 row.append("{}: {}".format(node, total[node][interf]))
63 else:
64 # skip node with no virbr0 or virbr0-nic interfaces
65 if interf not in ['virbr0', 'virbr0-nic']:
66 row.append("{}: No interface".format(node))
67 if diff.count(diff[0]) < len(nodes):
68 row.sort()
69 row.insert(0, interf)
70 mtu_data.append(row)
71 assert len(mtu_data) == 0, \
72 "Several problems found: {0}".format(
73 json.dumps(mtu_data, indent=4))