From a7fcbb3390548fe14c8f02842776cf96a30e8f41 Mon Sep 17 00:00:00 2001 From: Vasundhara Volam <163894573+vvolam@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:08:13 -0800 Subject: [PATCH] test_config_fec_oper_mode: Set the fec_mode to align with the current configuration of the interface. (#16360) * Configure the fec_mode that interface is already configured for * Fix a backslash --- tests/platform_tests/test_intf_fec.py | 32 ++++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/tests/platform_tests/test_intf_fec.py b/tests/platform_tests/test_intf_fec.py index 7447ff13e56..f7ec0c43fc9 100644 --- a/tests/platform_tests/test_intf_fec.py +++ b/tests/platform_tests/test_intf_fec.py @@ -1,6 +1,7 @@ import logging import pytest +from tests.common.helpers.assertions import pytest_assert from tests.common.utilities import skip_release, wait_until pytestmark = [ @@ -28,6 +29,15 @@ def is_supported_platform(duthost): pytest.skip("DUT has platform {}, test is not supported".format(duthost.facts['platform'])) +def get_fec_oper_mode(duthost, interface): + """ + @Return: FEC operational mode for a specific interface + """ + logging.info("Get output of '{} {}'".format("show interfaces fec status", interface)) + fec_status = duthost.show_and_parse("show interfaces fec status {}".format(interface)) + return fec_status[0].get('fec oper', '').lower() + + def test_verify_fec_oper_mode(duthosts, enum_rand_one_per_hwsku_frontend_hostname, enum_frontend_asic_index, conn_graph_facts): """ @@ -52,9 +62,7 @@ def test_verify_fec_oper_mode(duthosts, enum_rand_one_per_hwsku_frontend_hostnam if presence == "present" and oper == "up" and speed in SUPPORTED_SPEEDS: # Verify the FEC operational mode is valid - logging.info("Get output of '{} {}'".format("show interfaces fec status", intf['interface'])) - fec_status = duthost.show_and_parse("show interfaces fec status {}".format(intf['interface'])) - fec = fec_status[0].get('fec oper', '').lower() + fec = get_fec_oper_mode(duthost, intf['interface']) if fec == "n/a": pytest.fail("FEC status is N/A for interface {}".format(intf['interface'])) @@ -84,16 +92,18 @@ def test_config_fec_oper_mode(duthosts, enum_rand_one_per_hwsku_frontend_hostnam if presence == "not present" or oper != "up" or speed not in SUPPORTED_SPEEDS: continue - config_status = duthost.command("sudo config interface fec {} rs" - .format(intf['interface'])) + fec_mode = get_fec_oper_mode(duthost, intf['interface']) + if fec_mode == "n/a": + pytest.fail("FEC status is N/A for interface {}".format(intf['interface'])) + + config_status = duthost.command("sudo config interface fec {} {}" + .format(intf['interface'], fec_mode)) if config_status: - wait_until(30, 2, 0, duthost.is_interface_status_up, intf["interface"]) + pytest_assert(wait_until(30, 2, 0, duthost.is_interface_status_up, intf["interface"]), + "Interface {} did not come up after configuring FEC mode".format(intf["interface"])) # Verify the FEC operational mode is restored - logging.info("Get output of '{} {}'".format("show interfaces fec status", intf['interface'])) - fec_status = duthost.show_and_parse("show interfaces fec status {}".format(intf['interface'])) - fec = fec_status[0].get('fec oper', '').lower() - - if not (fec == "rs"): + post_fec = get_fec_oper_mode(duthost, intf['interface']) + if not (post_fec == fec_mode): pytest.fail("FEC status is not restored for interface {}".format(intf['interface']))