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 | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 7 | def test_mtu(local_salt_client, nodes_in_group): |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 8 | testname = os.path.basename(__file__).split('.')[0] |
Oleksii Zhurba | e0668ae | 2017-10-27 23:58:18 +0000 | [diff] [blame] | 9 | config = utils.get_configuration() |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 10 | skipped_ifaces = config.get(testname)["skipped_ifaces"] or \ |
Oleksii Zhurba | 1dd1d96 | 2018-08-07 15:01:40 -0500 | [diff] [blame] | 11 | ["bonding_masters", "lo", "veth", "tap", "cali", "qv", "qb", "br-int", "vxlan"] |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 12 | total = {} |
| 13 | network_info = local_salt_client.cmd( |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 14 | "L@"+','.join(nodes_in_group), 'cmd.run', ['ls /sys/class/net/'], expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 15 | |
| 16 | kvm_nodes = local_salt_client.cmd( |
| 17 | 'salt:control', 'test.ping', expr_form='pillar').keys() |
| 18 | |
| 19 | if len(network_info.keys()) < 2: |
| 20 | pytest.skip("Nothing to compare - only 1 node") |
| 21 | |
| 22 | for node, ifaces_info in network_info.iteritems(): |
| 23 | if node in kvm_nodes: |
| 24 | kvm_info = local_salt_client.cmd(node, 'cmd.run', |
| 25 | ["virsh list | " |
| 26 | "awk '{print $2}' | " |
| 27 | "xargs -n1 virsh domiflist | " |
| 28 | "grep -v br-pxe | grep br- | " |
| 29 | "awk '{print $1}'"]) |
| 30 | ifaces_info = kvm_info.get(node) |
| 31 | node_ifaces = ifaces_info.split('\n') |
| 32 | ifaces = {} |
| 33 | for iface in node_ifaces: |
| 34 | for skipped_iface in skipped_ifaces: |
| 35 | if skipped_iface in iface: |
| 36 | break |
| 37 | else: |
| 38 | iface_mtu = local_salt_client.cmd(node, 'cmd.run', |
| 39 | ['cat /sys/class/' |
| 40 | 'net/{}/mtu'.format(iface)]) |
| 41 | ifaces[iface] = iface_mtu.get(node) |
| 42 | total[node] = ifaces |
| 43 | |
| 44 | nodes = [] |
| 45 | mtu_data = [] |
| 46 | my_set = set() |
| 47 | |
| 48 | for node in total: |
| 49 | nodes.append(node) |
| 50 | my_set.update(total[node].keys()) |
| 51 | for interf in my_set: |
| 52 | diff = [] |
| 53 | row = [] |
| 54 | for node in nodes: |
| 55 | if interf in total[node].keys(): |
| 56 | diff.append(total[node][interf]) |
| 57 | row.append("{}: {}".format(node, total[node][interf])) |
| 58 | else: |
Oleksii Zhurba | 24b71aa | 2019-02-27 17:02:05 -0600 | [diff] [blame] | 59 | # skip node with no virbr0 or virbr0-nic interfaces |
| 60 | if interf not in ['virbr0', 'virbr0-nic']: |
| 61 | row.append("{}: No interface".format(node)) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 62 | if diff.count(diff[0]) < len(nodes): |
| 63 | row.sort() |
| 64 | row.insert(0, interf) |
| 65 | mtu_data.append(row) |
| 66 | assert len(mtu_data) == 0, \ |
Oleksii Zhurba | a32d92f | 2018-03-29 16:22:35 -0500 | [diff] [blame] | 67 | "Several problems found: {0}".format( |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 68 | json.dumps(mtu_data, indent=4)) |