|
| 1 | +import logging |
| 2 | +import pytest |
| 3 | +import random |
| 4 | +import time |
| 5 | + |
| 6 | +from tests.common.helpers.assertions import pytest_assert |
| 7 | +from tests.common.utilities import skip_release |
| 8 | + |
| 9 | +pytestmark = [ |
| 10 | + pytest.mark.disable_loganalyzer, # disable automatic loganalyzer |
| 11 | + pytest.mark.topology('any') |
| 12 | +] |
| 13 | + |
| 14 | +SUPPORTED_PLATFORMS = ["arista_7060x6"] |
| 15 | + |
| 16 | + |
| 17 | +class TestMACFault(object): |
| 18 | + @pytest.fixture(autouse=True) |
| 19 | + def is_supported_platform(self, duthost): |
| 20 | + if any(platform in duthost.facts['platform'] for platform in SUPPORTED_PLATFORMS): |
| 21 | + skip_release(duthost, ["201811", "201911", "202012", "202205", "202211", "202305", "202405"]) |
| 22 | + else: |
| 23 | + pytest.skip("DUT has platform {}, test is not supported".format(duthost.facts['platform'])) |
| 24 | + |
| 25 | + @staticmethod |
| 26 | + def get_mac_fault_count(dut, interface, fault_type): |
| 27 | + output = dut.show_and_parse("show int errors {}".format(interface)) |
| 28 | + logging.info("Raw output for show int errors on {}: {}".format(interface, output)) |
| 29 | + |
| 30 | + fault_count = 0 |
| 31 | + for error_info in output: |
| 32 | + if error_info['port errors'] == fault_type: |
| 33 | + fault_count = int(error_info['count']) |
| 34 | + break |
| 35 | + |
| 36 | + logging.info("{} count on {}: {}".format(fault_type, interface, fault_count)) |
| 37 | + return fault_count |
| 38 | + |
| 39 | + @staticmethod |
| 40 | + def get_interface_status(dut, interface): |
| 41 | + return dut.show_and_parse("show interfaces status {}".format(interface))[0].get("oper", "unknown") |
| 42 | + |
| 43 | + @pytest.fixture |
| 44 | + def select_random_interface(self, duthosts, enum_rand_one_per_hwsku_frontend_hostname): |
| 45 | + dut = duthosts[enum_rand_one_per_hwsku_frontend_hostname] |
| 46 | + interfaces = list(dut.show_and_parse("show interfaces status")) |
| 47 | + return dut, random.choice(interfaces)["interface"] |
| 48 | + |
| 49 | + def test_mac_local_fault_increment(self, select_random_interface): |
| 50 | + dut, interface = select_random_interface |
| 51 | + |
| 52 | + local_fault_before = self.get_mac_fault_count(dut, interface, "mac local fault") |
| 53 | + logging.info("Initial MAC local fault count on {}: {}".format(interface, local_fault_before)) |
| 54 | + |
| 55 | + dut.shell("sudo sfputil debug rx-output {} disable".format(interface)) |
| 56 | + time.sleep(5) |
| 57 | + pytest_assert(self.get_interface_status(dut, interface) == "down", |
| 58 | + "Interface {} did not go down after enabling low-power mode".format(interface)) |
| 59 | + |
| 60 | + dut.shell("sudo sfputil debug rx-output {} enable".format(interface)) |
| 61 | + time.sleep(20) |
| 62 | + pytest_assert(self.get_interface_status(dut, interface) == "up", |
| 63 | + "Interface {} did not come up after disabling low-power mode".format(interface)) |
| 64 | + |
| 65 | + local_fault_after = self.get_mac_fault_count(dut, interface, "mac local fault") |
| 66 | + logging.info("MAC local fault count after toggling low-power mode on " + |
| 67 | + "{}: {}".format(interface, local_fault_after)) |
| 68 | + |
| 69 | + pytest_assert(local_fault_after > local_fault_before, |
| 70 | + "MAC local fault count did not increment after toggling low-power mode") |
| 71 | + |
| 72 | + def test_mac_remote_fault_increment(self, select_random_interface): |
| 73 | + dut, interface = select_random_interface |
| 74 | + |
| 75 | + remote_fault_before = self.get_mac_fault_count(dut, interface, "mac remote fault") |
| 76 | + logging.info("Initial MAC remote fault count on {}: {}".format(interface, remote_fault_before)) |
| 77 | + |
| 78 | + dut.shell("sudo sfputil debug tx-output {} disable".format(interface)) |
| 79 | + time.sleep(5) |
| 80 | + dut.shell("sudo sfputil debug tx-output {} enable".format(interface)) |
| 81 | + time.sleep(20) |
| 82 | + |
| 83 | + pytest_assert(self.get_interface_status(dut, interface) == "up", |
| 84 | + "Interface {} did not come up after disabling low-power mode".format(interface)) |
| 85 | + |
| 86 | + remote_fault_after = self.get_mac_fault_count(dut, interface, "mac remote fault") |
| 87 | + logging.info("MAC remote fault count after toggling low-power mode on " + |
| 88 | + "{}: {}".format(interface, remote_fault_after)) |
| 89 | + |
| 90 | + pytest_assert(remote_fault_after > remote_fault_before, |
| 91 | + "MAC remote fault count did not increment after toggling low-power mode on remote device") |
0 commit comments