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