blob: b215c1d24e71e96cfdb29d79add6a608df97e9fb [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 Zhurba5b15b9b2019-05-09 18:53:40 -05007@pytest.mark.full
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -05008def test_mtu(local_salt_client, nodes_in_group):
Oleksii Zhurba3dbed242017-10-31 19:58:53 +00009 testname = os.path.basename(__file__).split('.')[0]
Oleksii Zhurbae0668ae2017-10-27 23:58:18 +000010 config = utils.get_configuration()
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000011 skipped_ifaces = config.get(testname)["skipped_ifaces"] or \
Oleksii Zhurba1dd1d962018-08-07 15:01:40 -050012 ["bonding_masters", "lo", "veth", "tap", "cali", "qv", "qb", "br-int", "vxlan"]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000013 total = {}
14 network_info = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050015 tgt="L@"+','.join(nodes_in_group),
16 param='ls /sys/class/net/',
17 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000018
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050019 kvm_nodes = local_salt_client.test_ping(tgt='salt:control').keys()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000020
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():
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050025 if isinstance(ifaces_info, bool):
26 print ("{} node is skipped".format(node))
27 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000028 if node in kvm_nodes:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050029 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}'")
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000035 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:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050043 iface_mtu = local_salt_client.cmd(tgt=node,
44 param='cat /sys/class/'
45 'net/{}/mtu'.format(iface))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000046 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:
Oleksii Zhurba24b71aa2019-02-27 17:02:05 -060064 # skip node with no virbr0 or virbr0-nic interfaces
65 if interf not in ['virbr0', 'virbr0-nic']:
66 row.append("{}: No interface".format(node))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000067 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, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050072 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050073 json.dumps(mtu_data, indent=4))