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 |
Hanna Arhipova | 56eab94 | 2019-05-06 20:14:18 +0300 | [diff] [blame] | 5 | import logging |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 6 | |
| 7 | |
Oleksii Zhurba | 5b15b9b | 2019-05-09 18:53:40 -0500 | [diff] [blame] | 8 | @pytest.mark.full |
Oleksii Zhurba | d0ae87f | 2018-03-26 13:36:25 -0500 | [diff] [blame] | 9 | def test_mtu(local_salt_client, nodes_in_group): |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 10 | testname = os.path.basename(__file__).split('.')[0] |
Oleksii Zhurba | e0668ae | 2017-10-27 23:58:18 +0000 | [diff] [blame] | 11 | config = utils.get_configuration() |
Oleksii Zhurba | 3dbed24 | 2017-10-31 19:58:53 +0000 | [diff] [blame] | 12 | skipped_ifaces = config.get(testname)["skipped_ifaces"] or \ |
Oleksii Zhurba | 4e667e5 | 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 | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 15 | group, nodes = nodes_in_group |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 16 | total = {} |
| 17 | network_info = local_salt_client.cmd( |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 18 | tgt="L@"+','.join(nodes), |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 19 | param='ls /sys/class/net/', |
| 20 | expr_form='compound') |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 21 | |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 22 | if len(list(network_info.keys())) < 2: |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 23 | pytest.skip("Nothing to compare - only 1 node") |
| 24 | |
Oleksii Zhurba | 4e667e5 | 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 | |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 33 | for node, ifaces_info in network_info.items(): |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 34 | if isinstance(ifaces_info, bool): |
Valentyn Khalin | 60f57cc | 2020-05-13 19:45:36 +0300 | [diff] [blame] | 35 | logging.info("{} node skipped. No interfaces available.".format(node)) |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 36 | continue |
Oleksii Zhurba | 4e667e5 | 2019-05-28 18:42:00 -0500 | [diff] [blame] | 37 | # if node is a kvm node and virsh is installed there |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 38 | if node in list(kvm_nodes.keys()) and kvm_nodes[node]: |
Valentyn Khalin | 60f57cc | 2020-05-13 19:45:36 +0300 | [diff] [blame] | 39 | domain_name = node.split(".", 1)[1] |
| 40 | # vms_count calculated separately to have readable output |
| 41 | # and for further debug if needed |
| 42 | vms_count = local_salt_client.cmd(tgt=node, param="virsh list | grep {}" |
| 43 | .format(domain_name)) |
| 44 | if not vms_count[node]: |
| 45 | logging.info("{} node skipped. No OS vm's running.".format(node)) |
| 46 | continue |
| 47 | # param assumes that KVM has OS vm's running. |
| 48 | # virsh list | grep domain_name --- fails |
| 49 | # if KVM has nothing to grep and test fails |
| 50 | param = "virsh list | grep " + domain_name + "| awk '{print $2}' | " \ |
| 51 | "xargs -n1 virsh domiflist | " \ |
| 52 | "grep -v br-pxe | grep br- | " \ |
| 53 | "awk '{print $1}' " |
| 54 | kvm_info = local_salt_client.cmd(tgt=node, param=param) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 55 | ifaces_info = kvm_info.get(node) |
| 56 | node_ifaces = ifaces_info.split('\n') |
| 57 | ifaces = {} |
| 58 | for iface in node_ifaces: |
| 59 | for skipped_iface in skipped_ifaces: |
| 60 | if skipped_iface in iface: |
| 61 | break |
| 62 | else: |
Oleksii Zhurba | 4bfd2ee | 2019-04-10 21:56:58 -0500 | [diff] [blame] | 63 | iface_mtu = local_salt_client.cmd(tgt=node, |
| 64 | param='cat /sys/class/' |
| 65 | 'net/{}/mtu'.format(iface)) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 66 | ifaces[iface] = iface_mtu.get(node) |
| 67 | total[node] = ifaces |
| 68 | |
| 69 | nodes = [] |
| 70 | mtu_data = [] |
| 71 | my_set = set() |
| 72 | |
| 73 | for node in total: |
| 74 | nodes.append(node) |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 75 | my_set.update(list(total[node].keys())) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 76 | for interf in my_set: |
| 77 | diff = [] |
| 78 | row = [] |
| 79 | for node in nodes: |
Ekaterina Chernova | e32e3f9 | 2019-11-12 14:56:03 +0300 | [diff] [blame] | 80 | if interf in list(total[node].keys()): |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 81 | diff.append(total[node][interf]) |
| 82 | row.append("{}: {}".format(node, total[node][interf])) |
| 83 | else: |
Oleksii Zhurba | 4e667e5 | 2019-05-28 18:42:00 -0500 | [diff] [blame] | 84 | row.append("{}: No interface".format(node)) |
Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame] | 85 | if diff.count(diff[0]) < len(nodes): |
| 86 | row.sort() |
| 87 | row.insert(0, interf) |
| 88 | mtu_data.append(row) |
Dmitriy Kruglov | a34a304 | 2019-08-20 11:45:35 +0200 | [diff] [blame] | 89 | assert len(mtu_data) == 0, ( |
| 90 | "Non-uniform MTUs are set on the same node interfaces of '{}' group " |
| 91 | "of nodes: {}".format(group, json.dumps(mtu_data, indent=4)) |
Valentyn Khalin | 60f57cc | 2020-05-13 19:45:36 +0300 | [diff] [blame] | 92 | ) |