Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 1 | import pytest |
| 2 | import json |
Hanna Arhipova | 16e93fb | 2019-01-23 19:03:01 +0200 | [diff] [blame] | 3 | import utils |
Oleksii Zhurba | e0668ae | 2017-10-27 23:58:18 +0000 | [diff] [blame] | 4 | import os |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 5 | |
| 6 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame^] | 7 | @pytest.mark.full |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 8 | def test_mtu(local_salt_client, nodes_in_group): |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 9 | testname = os.path.basename(__file__).split('.')[0] |
Oleksii Zhurba | e0668ae | 2017-10-27 23:58:18 +0000 | [diff] [blame] | 10 | config = utils.get_configuration() |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 11 | skipped_ifaces = config.get(testname)["skipped_ifaces"] or \ |
Oleksii Zhurba | 1dd1d96 | 2018-08-07 15:01:40 -0500 | [diff] [blame] | 12 | ["bonding_masters", "lo", "veth", "tap", "cali", "qv", "qb", "br-int", "vxlan"] |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 13 | total = {} |
| 14 | network_info = local_salt_client.cmd( |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 15 | tgt="L@"+','.join(nodes_in_group), |
| 16 | param='ls /sys/class/net/', |
| 17 | expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 18 | |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 19 | kvm_nodes = local_salt_client.test_ping(tgt='salt:control').keys() |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 20 | |
| 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 Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 25 | if isinstance(ifaces_info, bool): |
| 26 | print ("{} node is skipped".format(node)) |
| 27 | continue |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 28 | if node in kvm_nodes: |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 29 | 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 Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 35 | 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 Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 43 | iface_mtu = local_salt_client.cmd(tgt=node, |
| 44 | param='cat /sys/class/' |
| 45 | 'net/{}/mtu'.format(iface)) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 46 | 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 Zhurba | 24b71aa | 2019-02-27 17:02:05 -0600 | [diff] [blame] | 64 | # 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 Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 67 | 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 Zhurba | a32d92f | 2018-03-29 16:22:35 -0500 | [diff] [blame] | 72 | "Several problems found: {0}".format( |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 73 | json.dumps(mtu_data, indent=4)) |