blob: 01d664264b100e06c05d60a6b2aad8b3137ebcc7 [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
Hanna Arhipova56eab942019-05-06 20:14:18 +03005import logging
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +00006
7
Oleksii Zhurba5b15b9b2019-05-09 18:53:40 -05008@pytest.mark.full
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -05009def test_mtu(local_salt_client, nodes_in_group):
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000010 testname = os.path.basename(__file__).split('.')[0]
Oleksii Zhurbae0668ae2017-10-27 23:58:18 +000011 config = utils.get_configuration()
Oleksii Zhurba3dbed242017-10-31 19:58:53 +000012 skipped_ifaces = config.get(testname)["skipped_ifaces"] or \
Oleksii Zhurba1dd1d962018-08-07 15:01:40 -050013 ["bonding_masters", "lo", "veth", "tap", "cali", "qv", "qb", "br-int", "vxlan"]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000014 total = {}
15 network_info = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050016 tgt="L@"+','.join(nodes_in_group),
17 param='ls /sys/class/net/',
18 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000019
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050020 kvm_nodes = local_salt_client.test_ping(tgt='salt:control').keys()
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000021
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():
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050026 if isinstance(ifaces_info, bool):
Hanna Arhipova56eab942019-05-06 20:14:18 +030027 logging.info("{} node is skipped".format(node))
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050028 continue
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000029 if node in kvm_nodes:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050030 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}'")
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000036 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:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050044 iface_mtu = local_salt_client.cmd(tgt=node,
45 param='cat /sys/class/'
46 'net/{}/mtu'.format(iface))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000047 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:
Oleksii Zhurba24b71aa2019-02-27 17:02:05 -060065 # skip node with no virbr0 or virbr0-nic interfaces
66 if interf not in ['virbr0', 'virbr0-nic']:
67 row.append("{}: No interface".format(node))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000068 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, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050073 "Several problems found: {0}".format(
Oleksii Zhurbad0ae87f2018-03-26 13:36:25 -050074 json.dumps(mtu_data, indent=4))