blob: 8dc4a79c732745322276310e627abab133165ba4 [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 \
Oleksii Zhurba674bd132019-05-28 18:42:00 -050013 ["bonding_masters", "lo", "veth", "tap", "cali", "qv", "qb", "br-int",
14 "vxlan", "virbr0", "virbr0-nic", "docker0", "o-hm0"]
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030015 total = {}
16 network_info = local_salt_client.cmd(
17 tgt="L@"+','.join(nodes_in_group),
18 param='ls /sys/class/net/',
19 expr_form='compound')
20
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030021 if len(network_info.keys()) < 2:
22 pytest.skip("Nothing to compare - only 1 node")
23
Oleksii Zhurba674bd132019-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
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030032 for node, ifaces_info in network_info.iteritems():
33 if isinstance(ifaces_info, bool):
Hanna Arhipova1eef8312019-05-06 20:14:18 +030034 logging.info("{} node is skipped".format(node))
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030035 continue
Oleksii Zhurba674bd132019-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]:
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030038 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}'")
44 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:
52 iface_mtu = local_salt_client.cmd(tgt=node,
53 param='cat /sys/class/'
54 'net/{}/mtu'.format(iface))
55 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 Zhurba674bd132019-05-28 18:42:00 -050073 row.append("{}: No interface".format(node))
Hanna Arhipovae6ed8e42019-05-15 16:27:08 +030074 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, \
79 "Several problems found: {0}".format(
Oleksii Zhurba674bd132019-05-28 18:42:00 -050080 json.dumps(mtu_data, indent=4))