From 7bb0894583fc68640b142c28a93f6a3b1f0f4a57 Mon Sep 17 00:00:00 2001 From: AntonHryshchuk <76687950+AntonHryshchuk@users.noreply.github.com> Date: Fri, 14 May 2021 18:02:41 +0300 Subject: [PATCH] [pfcwd] fix test_pfcwd_mmu_change from pfcwd_function (#3473) Summary: updated method get_mmu_params() * to check whether the buffer configurations are in config db or appl db via checking whether buffer_model exists in DEVICE_METADATA|localhost * fetch the buffer configuration from the config db/appl db accordingly. Signed-off-by: Anton What is the motivation for this PR? fix tests in pfcwd/test_pfcwd_function.py previously the test "test_pfcwd_mmu_change" failed with error: '> )[0].encode("utf-8") E IndexError: list index out of range' In method "get_mmu_params", the reason for it was the "NULL" output in request asic.run_redis_cmd( argv = [ "redis-cli", "-n", db, "HGET", "BUFFER_PG|{}|3-4".format(port), "profile" ] ) --- tests/pfcwd/test_pfcwd_function.py | 39 +++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/tests/pfcwd/test_pfcwd_function.py b/tests/pfcwd/test_pfcwd_function.py index c29d920f36..26c1002660 100644 --- a/tests/pfcwd/test_pfcwd_function.py +++ b/tests/pfcwd/test_pfcwd_function.py @@ -28,6 +28,7 @@ logger = logging.getLogger(__name__) + @pytest.fixture(scope='function', autouse=True) def stop_pfcwd(duthosts, rand_one_dut_hostname): """ @@ -40,7 +41,31 @@ def stop_pfcwd(duthosts, rand_one_dut_hostname): logger.info("--- Stop Pfcwd --") duthost.command("pfcwd stop") + class PfcCmd(object): + buffer_model_initialized = False + buffer_model = None + + @staticmethod + def isBufferInApplDb(asic): + if not PfcCmd.buffer_model_initialized: + PfcCmd.buffer_model = asic.run_redis_cmd( + argv=[ + "redis-cli", "-n", "4", "hget", + "DEVICE_METADATA|localhost", "buffer_model" + ] + ) + + PfcCmd.buffer_model_initialized = True + logger.info( + "Buffer model is {}, buffer tables will be fetched from {}". + format( + PfcCmd.buffer_model or "not defined", + "APPL_DB" if PfcCmd.buffer_model else "CONFIG_DB" + ) + ) + return PfcCmd.buffer_model + @staticmethod def counter_cmd(dut, queue_oid, attr): """ @@ -115,21 +140,29 @@ def get_mmu_params(dut, port): logger.info("Retreiving pg profile and dynamic threshold for port: {}".format(port)) asic = dut.get_port_asic_instance(port) + if PfcCmd.isBufferInApplDb(asic): + db = "0" + pg_pattern = "BUFFER_PG_TABLE:{}:3-4" + else: + db = "4" + pg_pattern = "BUFFER_PG|{}|3-4" + pg_profile = asic.run_redis_cmd( argv = [ - "redis-cli", "-n", "4", "HGET", - "BUFFER_PG|{}|3-4".format(port), "profile" + "redis-cli", "-n", db, "HGET", + pg_pattern.format(port), "profile" ] )[0].encode("utf-8")[1:-1] alpha = asic.run_redis_cmd( argv = [ - "redis-cli", "-n", "4", "HGET", pg_profile, "dynamic_th" + "redis-cli", "-n", db, "HGET", pg_profile, "dynamic_th" ] )[0].encode("utf-8") return pg_profile, alpha + class PfcPktCntrs(object): """ PFCwd counter retrieval and verifications """ def __init__(self, dut, action):