blob: 0a3d2d02fce0d4c04e91f493f25917491ea7f1a1 [file] [log] [blame]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00001import pytest
2import json
Hanna Arhipova16e93fb2019-01-23 19:03:01 +02003import utils
Oleksii Zhurbae0668ae2017-10-27 23:58:18 +00004import os
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00005
6
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -05007def test_mtu(local_salt_client, nodes_in_group):
Oleksii Zhurba3dbed242017-10-31 19:58:53 +00008 testname = os.path.basename(__file__).split('.')[0]
Oleksii Zhurbae0668ae2017-10-27 23:58:18 +00009 config = utils.get_configuration()
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000010 skipped_ifaces = config.get(testname)["skipped_ifaces"] or \
Oleksii Zhurba1dd1d962018-08-07 15:01:40 -050011 ["bonding_masters", "lo", "veth", "tap", "cali", "qv", "qb", "br-int", "vxlan"]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000012 total = {}
13 network_info = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050014 tgt="L@"+','.join(nodes_in_group),
15 param='ls /sys/class/net/',
16 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000017
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050018 kvm_nodes = local_salt_client.test_ping(tgt='salt:control').keys()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000019
20 if len(network_info.keys()) < 2:
21 pytest.skip("Nothing to compare - only 1 node")
22
23 for node, ifaces_info in network_info.iteritems():
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050024 if isinstance(ifaces_info, bool):
25 print ("{} node is skipped".format(node))
26 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000027 if node in kvm_nodes:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050028 kvm_info = local_salt_client.cmd(tgt=node,
29 param="virsh list | "
30 "awk '{print $2}' | "
31 "xargs -n1 virsh domiflist | "
32 "grep -v br-pxe | grep br- | "
33 "awk '{print $1}'")
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000034 ifaces_info = kvm_info.get(node)
35 node_ifaces = ifaces_info.split('\n')
36 ifaces = {}
37 for iface in node_ifaces:
38 for skipped_iface in skipped_ifaces:
39 if skipped_iface in iface:
40 break
41 else:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050042 iface_mtu = local_salt_client.cmd(tgt=node,
43 param='cat /sys/class/'
44 'net/{}/mtu'.format(iface))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000045 ifaces[iface] = iface_mtu.get(node)
46 total[node] = ifaces
47
48 nodes = []
49 mtu_data = []
50 my_set = set()
51
52 for node in total:
53 nodes.append(node)
54 my_set.update(total[node].keys())
55 for interf in my_set:
56 diff = []
57 row = []
58 for node in nodes:
59 if interf in total[node].keys():
60 diff.append(total[node][interf])
61 row.append("{}: {}".format(node, total[node][interf]))
62 else:
Oleksii Zhurba24b71aa2019-02-27 17:02:05 -060063 # skip node with no virbr0 or virbr0-nic interfaces
64 if interf not in ['virbr0', 'virbr0-nic']:
65 row.append("{}: No interface".format(node))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000066 if diff.count(diff[0]) < len(nodes):
67 row.sort()
68 row.insert(0, interf)
69 mtu_data.append(row)
70 assert len(mtu_data) == 0, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050071 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050072 json.dumps(mtu_data, indent=4))