blob: 8dc4a79c732745322276310e627abab133165ba4 [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 Zhurba4e667e52019-05-28 18:42:00 -050013 ["bonding_masters", "lo", "veth", "tap", "cali", "qv", "qb", "br-int",
14 "vxlan", "virbr0", "virbr0-nic", "docker0", "o-hm0"]
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000015 total = {}
16 network_info = local_salt_client.cmd(
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050017 tgt="L@"+','.join(nodes_in_group),
18 param='ls /sys/class/net/',
19 expr_form='compound')
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000020
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000021 if len(network_info.keys()) < 2:
22 pytest.skip("Nothing to compare - only 1 node")
23
Oleksii Zhurba4e667e52019-05-28 18:42:00 -050024 # collect all nodes and check if virsh is installed there
25 kvm_nodes = local_salt_client.cmd(
26 tgt='salt:control',
27 fun='pkg.version',
28 param='libvirt-clients',
29 expr_form='pillar'
30 )
31
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000032 for node, ifaces_info in network_info.iteritems():
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050033 if isinstance(ifaces_info, bool):
Hanna Arhipova56eab942019-05-06 20:14:18 +030034 logging.info("{} node is skipped".format(node))
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050035 continue
Oleksii Zhurba4e667e52019-05-28 18:42:00 -050036 # if node is a kvm node and virsh is installed there
37 if node in kvm_nodes.keys() and kvm_nodes[node]:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050038 kvm_info = local_salt_client.cmd(tgt=node,
39 param="virsh list | "
40 "awk '{print $2}' | "
41 "xargs -n1 virsh domiflist | "
42 "grep -v br-pxe | grep br- | "
43 "awk '{print $1}'")
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000044 ifaces_info = kvm_info.get(node)
45 node_ifaces = ifaces_info.split('\n')
46 ifaces = {}
47 for iface in node_ifaces:
48 for skipped_iface in skipped_ifaces:
49 if skipped_iface in iface:
50 break
51 else:
Oleksii Zhurba4bfd2ee2019-04-10 21:56:58 -050052 iface_mtu = local_salt_client.cmd(tgt=node,
53 param='cat /sys/class/'
54 'net/{}/mtu'.format(iface))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000055 ifaces[iface] = iface_mtu.get(node)
56 total[node] = ifaces
57
58 nodes = []
59 mtu_data = []
60 my_set = set()
61
62 for node in total:
63 nodes.append(node)
64 my_set.update(total[node].keys())
65 for interf in my_set:
66 diff = []
67 row = []
68 for node in nodes:
69 if interf in total[node].keys():
70 diff.append(total[node][interf])
71 row.append("{}: {}".format(node, total[node][interf]))
72 else:
Oleksii Zhurba4e667e52019-05-28 18:42:00 -050073 row.append("{}: No interface".format(node))
Oleksii Zhurbaa10927b2017-09-27 22:09:23 +000074 if diff.count(diff[0]) < len(nodes):
75 row.sort()
76 row.insert(0, interf)
77 mtu_data.append(row)
78 assert len(mtu_data) == 0, \
Oleksii Zhurbaa32d92f2018-03-29 16:22:35 -050079 "Several problems found: {0}".format(
Oleksii Zhurba4e667e52019-05-28 18:42:00 -050080 json.dumps(mtu_data, indent=4))