Oleksii Zhurba | a10927b | 2017-09-27 22:09:23 +0000 | [diff] [blame^] | 1 | import pytest |
| 2 | import json |
| 3 | from cvp_checks import utils |
| 4 | |
| 5 | |
| 6 | @pytest.mark.parametrize( |
| 7 | "group", |
| 8 | utils.get_groups(utils.get_configuration(__file__)) |
| 9 | ) |
| 10 | def test_mtu(local_salt_client, group): |
| 11 | config = utils.get_configuration(__file__) |
| 12 | skipped_ifaces = config["skipped_ifaces"] |
| 13 | total = {} |
| 14 | network_info = local_salt_client.cmd( |
| 15 | group, 'cmd.run', ['ls /sys/class/net/'], expr_form='pcre') |
| 16 | |
| 17 | kvm_nodes = local_salt_client.cmd( |
| 18 | 'salt:control', 'test.ping', expr_form='pillar').keys() |
| 19 | |
| 20 | if len(network_info.keys()) < 2: |
| 21 | pytest.skip("Nothing to compare - only 1 node") |
| 22 | |
| 23 | for node, ifaces_info in network_info.iteritems(): |
| 24 | if node in kvm_nodes: |
| 25 | kvm_info = local_salt_client.cmd(node, 'cmd.run', |
| 26 | ["virsh list | " |
| 27 | "awk '{print $2}' | " |
| 28 | "xargs -n1 virsh domiflist | " |
| 29 | "grep -v br-pxe | grep br- | " |
| 30 | "awk '{print $1}'"]) |
| 31 | ifaces_info = kvm_info.get(node) |
| 32 | node_ifaces = ifaces_info.split('\n') |
| 33 | ifaces = {} |
| 34 | for iface in node_ifaces: |
| 35 | for skipped_iface in skipped_ifaces: |
| 36 | if skipped_iface in iface: |
| 37 | break |
| 38 | else: |
| 39 | iface_mtu = local_salt_client.cmd(node, 'cmd.run', |
| 40 | ['cat /sys/class/' |
| 41 | 'net/{}/mtu'.format(iface)]) |
| 42 | ifaces[iface] = iface_mtu.get(node) |
| 43 | total[node] = ifaces |
| 44 | |
| 45 | nodes = [] |
| 46 | mtu_data = [] |
| 47 | my_set = set() |
| 48 | |
| 49 | for node in total: |
| 50 | nodes.append(node) |
| 51 | my_set.update(total[node].keys()) |
| 52 | for interf in my_set: |
| 53 | diff = [] |
| 54 | row = [] |
| 55 | for node in nodes: |
| 56 | if interf in total[node].keys(): |
| 57 | diff.append(total[node][interf]) |
| 58 | row.append("{}: {}".format(node, total[node][interf])) |
| 59 | else: |
| 60 | row.append("{}: No interface".format(node)) |
| 61 | if diff.count(diff[0]) < len(nodes): |
| 62 | row.sort() |
| 63 | row.insert(0, interf) |
| 64 | mtu_data.append(row) |
| 65 | assert len(mtu_data) == 0, \ |
| 66 | "Several problems found for {0} group: {1}".format( |
| 67 | group, json.dumps(mtu_data, indent=4)) |
| 68 | |