Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 1 | import pytest |
| 2 | import json |
| 3 | import utils |
| 4 | import os |
Hanna Arhipova | 1eef831 | 2019-05-06 20:14:18 +0300 | [diff] [blame] | 5 | import logging |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 6 | |
| 7 | |
Oleksii Zhurba | 23c1833 | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 8 | @pytest.mark.full |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 9 | def 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 Zhurba | 674bd13 | 2019-05-28 18:42:00 -0500 | [diff] [blame] | 13 | ["bonding_masters", "lo", "veth", "tap", "cali", "qv", "qb", "br-int", |
| 14 | "vxlan", "virbr0", "virbr0-nic", "docker0", "o-hm0"] |
Dmitriy Kruglov | bc0a88b | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 15 | group, nodes = nodes_in_group |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 16 | total = {} |
| 17 | network_info = local_salt_client.cmd( |
Dmitriy Kruglov | bc0a88b | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 18 | tgt="L@"+','.join(nodes), |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 19 | param='ls /sys/class/net/', |
| 20 | expr_form='compound') |
| 21 | |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 22 | if len(network_info.keys()) < 2: |
| 23 | pytest.skip("Nothing to compare - only 1 node") |
| 24 | |
Oleksii Zhurba | 674bd13 | 2019-05-28 18:42:00 -0500 | [diff] [blame] | 25 | # collect all nodes and check if virsh is installed there |
| 26 | kvm_nodes = local_salt_client.cmd( |
| 27 | tgt='salt:control', |
| 28 | fun='pkg.version', |
| 29 | param='libvirt-clients', |
| 30 | expr_form='pillar' |
| 31 | ) |
| 32 | |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 33 | for node, ifaces_info in network_info.iteritems(): |
| 34 | if isinstance(ifaces_info, bool): |
Hanna Arhipova | 1eef831 | 2019-05-06 20:14:18 +0300 | [diff] [blame] | 35 | logging.info("{} node is skipped".format(node)) |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 36 | continue |
Oleksii Zhurba | 674bd13 | 2019-05-28 18:42:00 -0500 | [diff] [blame] | 37 | # if node is a kvm node and virsh is installed there |
| 38 | if node in kvm_nodes.keys() and kvm_nodes[node]: |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 39 | kvm_info = local_salt_client.cmd(tgt=node, |
| 40 | param="virsh list | " |
| 41 | "awk '{print $2}' | " |
| 42 | "xargs -n1 virsh domiflist | " |
| 43 | "grep -v br-pxe | grep br- | " |
| 44 | "awk '{print $1}'") |
| 45 | ifaces_info = kvm_info.get(node) |
| 46 | node_ifaces = ifaces_info.split('\n') |
| 47 | ifaces = {} |
| 48 | for iface in node_ifaces: |
| 49 | for skipped_iface in skipped_ifaces: |
| 50 | if skipped_iface in iface: |
| 51 | break |
| 52 | else: |
| 53 | iface_mtu = local_salt_client.cmd(tgt=node, |
| 54 | param='cat /sys/class/' |
| 55 | 'net/{}/mtu'.format(iface)) |
| 56 | ifaces[iface] = iface_mtu.get(node) |
| 57 | total[node] = ifaces |
| 58 | |
| 59 | nodes = [] |
| 60 | mtu_data = [] |
| 61 | my_set = set() |
| 62 | |
| 63 | for node in total: |
| 64 | nodes.append(node) |
| 65 | my_set.update(total[node].keys()) |
| 66 | for interf in my_set: |
| 67 | diff = [] |
| 68 | row = [] |
| 69 | for node in nodes: |
| 70 | if interf in total[node].keys(): |
| 71 | diff.append(total[node][interf]) |
| 72 | row.append("{}: {}".format(node, total[node][interf])) |
| 73 | else: |
Oleksii Zhurba | 674bd13 | 2019-05-28 18:42:00 -0500 | [diff] [blame] | 74 | row.append("{}: No interface".format(node)) |
Hanna Arhipova | e6ed8e4 | 2019-05-15 16:27:08 +0300 | [diff] [blame] | 75 | if diff.count(diff[0]) < len(nodes): |
| 76 | row.sort() |
| 77 | row.insert(0, interf) |
| 78 | mtu_data.append(row) |
Dmitriy Kruglov | bc0a88b | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 79 | assert len(mtu_data) == 0, ( |
| 80 | "Non-uniform MTUs are set on the same node interfaces of '{}' group " |
| 81 | "of nodes: {}".format(group, json.dumps(mtu_data, indent=4)) |
| 82 | ) |