From 0c63c3fb94f7814c5fbd852dc2bf85e385ef5fe8 Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Thu, 13 Nov 2025 19:14:58 +0000 Subject: [PATCH 1/3] add test_poll_mode_srv6_sid_counters --- tests/telemetry/test_telemetry_poll.py | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/telemetry/test_telemetry_poll.py b/tests/telemetry/test_telemetry_poll.py index 01521cb924d..80f1049d3a0 100644 --- a/tests/telemetry/test_telemetry_poll.py +++ b/tests/telemetry/test_telemetry_poll.py @@ -239,3 +239,51 @@ def test_poll_mode_default_route_supervisor(duthosts, enum_rand_one_per_hwsku_ho update_responses_match = re.findall("json_ietf_val", result) pytest_assert(len(update_responses_match) == 5, "Missing update responses") modify_fake_appdb_table(duthost, False, 1) # Remove added table + + +@pytest.mark.parametrize('setup_streaming_telemetry', [False], indirect=True) +def test_poll_mode_srv6_sid_counters(duthosts, enum_rand_one_per_hwsku_hostname, ptfhost, + setup_streaming_telemetry, gnxi_path): + """ + Test poll mode from COUNTERS_DB and query SRv6 MY_SID counters: + First, query when the data does not exist,ensure no errors and present data + Second, add data and then test query again ensuring data comes. + """ + duthost = duthosts[enum_rand_one_per_hwsku_hostname] + namespace = "" + if duthost.is_multi_asic: + namespace = "asic0" + logger.info('Start telemetry poll mode testing') + cmd = generate_client_cli(duthost=duthost, gnxi_path=gnxi_path, method=METHOD_SUBSCRIBE, + subscribe_mode=SUBSCRIBE_MODE_POLL, polling_interval=2, + xpath="\"COUNTERS\" \"SID:*\"", # noqa: W605 + target="COUNTERS_DB", max_sync_count=-1, update_count=5, timeout=30, namespace=namespace) + + ptf_result = ptfhost.shell(cmd) + pytest_assert(ptf_result['rc'] == 0, "ptf cmd command {} failed".format(cmd)) + show_gnmi_out = ptf_result['stdout'] + logger.info("GNMI Server output") + logger.info(show_gnmi_out) + result = str(show_gnmi_out) + update_responses_match = re.findall("json_ietf_val", result) + pytest_assert(len(update_responses_match) == 5, "Missing update responses") + # TODO: verify an empty update is sent. + + cmd = generate_client_cli(duthost=duthost, gnxi_path=gnxi_path, method=METHOD_SUBSCRIBE, + subscribe_mode=SUBSCRIBE_MODE_POLL, polling_interval=10, + xpath="\"COUNTERS\" \"SID:*\"", # noqa: W605 + target="COUNTERS_DB", max_sync_count=-1, update_count=10, + timeout=120, namespace=namespace) + + def callback(show_gnmi_out): + result = str(show_gnmi_out) + logger.info(result) + # TODO: verify that actual data is sent. + + client_thread = InterruptableThread(target=invoke_py_cli_from_ptf, args=(ptfhost, cmd, callback,)) + client_thread.start() + + wait_until(5, 1, 0, check_gnmi_cli_running, duthost, ptfhost) + + # Give 60 seconds for client to connect to server and then 60 for default route to populate after bgp session start + client_thread.join(120) From 16866ff34e7cbd36e7f28da6d2a2875c2a7173e4 Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Thu, 13 Nov 2025 20:29:18 +0000 Subject: [PATCH 2/3] complete the test code --- tests/telemetry/test_telemetry_poll.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/telemetry/test_telemetry_poll.py b/tests/telemetry/test_telemetry_poll.py index 80f1049d3a0..e90941f53c8 100644 --- a/tests/telemetry/test_telemetry_poll.py +++ b/tests/telemetry/test_telemetry_poll.py @@ -266,8 +266,13 @@ def test_poll_mode_srv6_sid_counters(duthosts, enum_rand_one_per_hwsku_hostname, logger.info(show_gnmi_out) result = str(show_gnmi_out) update_responses_match = re.findall("json_ietf_val", result) - pytest_assert(len(update_responses_match) == 5, "Missing update responses") - # TODO: verify an empty update is sent. + pytest_assert(len(update_responses_match) > 0, "Incorrect update responses") + + # Now generate some SRv6 SID counter values by adding mock data + duthost.shell("sonic-db-cli -n {} COUNTERS_DB HSET \"COUNTERS:oid:0x11110000001eb3\" SAI_COUNTER_STAT_PACKETS 10 \ + SAI_COUNTER_STAT_BYTES 40960".format(namespace)) + duthost.shell("sonic-db-cli -n {} COUNTERS_DB HSET \"COUNTERS_SRV6_NAME_MAP\" \"fcbb:bbbb:1::/48\" \ + \"oid:0x11110000001eb3\"".format(namespace)) cmd = generate_client_cli(duthost=duthost, gnxi_path=gnxi_path, method=METHOD_SUBSCRIBE, subscribe_mode=SUBSCRIBE_MODE_POLL, polling_interval=10, @@ -278,7 +283,8 @@ def test_poll_mode_srv6_sid_counters(duthosts, enum_rand_one_per_hwsku_hostname, def callback(show_gnmi_out): result = str(show_gnmi_out) logger.info(result) - # TODO: verify that actual data is sent. + update_responses_match = re.findall("SAI_COUNTER_STAT_PACKETS", result) + pytest_assert(len(update_responses_match) > 0, "Missing update responses") client_thread = InterruptableThread(target=invoke_py_cli_from_ptf, args=(ptfhost, cmd, callback,)) client_thread.start() @@ -287,3 +293,6 @@ def callback(show_gnmi_out): # Give 60 seconds for client to connect to server and then 60 for default route to populate after bgp session start client_thread.join(120) + + duthost.shell(f"sonic-db-cli -n {namespace} COUNTERS_DB DEL \"COUNTERS:oid:0x11110000001eb3\"") + duthost.shell(f"sonic-db-cli -n {namespace} COUNTERS_DB HDEL \"COUNTERS_SRV6_NAME_MAP\" \"fcbb:bbbb:1::/48\"") From 85758401fbf69b2270f3fe8b9669273c61189717 Mon Sep 17 00:00:00 2001 From: BYGX-wcr Date: Thu, 13 Nov 2025 23:29:03 +0000 Subject: [PATCH 3/3] fix test bug --- tests/telemetry/test_telemetry_poll.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/telemetry/test_telemetry_poll.py b/tests/telemetry/test_telemetry_poll.py index e90941f53c8..aec27892fc6 100644 --- a/tests/telemetry/test_telemetry_poll.py +++ b/tests/telemetry/test_telemetry_poll.py @@ -256,7 +256,7 @@ def test_poll_mode_srv6_sid_counters(duthosts, enum_rand_one_per_hwsku_hostname, logger.info('Start telemetry poll mode testing') cmd = generate_client_cli(duthost=duthost, gnxi_path=gnxi_path, method=METHOD_SUBSCRIBE, subscribe_mode=SUBSCRIBE_MODE_POLL, polling_interval=2, - xpath="\"COUNTERS\" \"SID:*\"", # noqa: W605 + xpath="\"COUNTERS/SID:*\"", # noqa: W605 target="COUNTERS_DB", max_sync_count=-1, update_count=5, timeout=30, namespace=namespace) ptf_result = ptfhost.shell(cmd) @@ -268,15 +268,19 @@ def test_poll_mode_srv6_sid_counters(duthosts, enum_rand_one_per_hwsku_hostname, update_responses_match = re.findall("json_ietf_val", result) pytest_assert(len(update_responses_match) > 0, "Incorrect update responses") + if namespace != "": + SONIC_DB_CLI = f"sonic-db-cli -n {namespace}" + else: + SONIC_DB_CLI = "sonic-db-cli" # Now generate some SRv6 SID counter values by adding mock data - duthost.shell("sonic-db-cli -n {} COUNTERS_DB HSET \"COUNTERS:oid:0x11110000001eb3\" SAI_COUNTER_STAT_PACKETS 10 \ - SAI_COUNTER_STAT_BYTES 40960".format(namespace)) - duthost.shell("sonic-db-cli -n {} COUNTERS_DB HSET \"COUNTERS_SRV6_NAME_MAP\" \"fcbb:bbbb:1::/48\" \ - \"oid:0x11110000001eb3\"".format(namespace)) + duthost.shell(f"{SONIC_DB_CLI} COUNTERS_DB HSET \"COUNTERS:oid:0x11110000001eb3\" SAI_COUNTER_STAT_PACKETS 10 \ + SAI_COUNTER_STAT_BYTES 40960") + duthost.shell(f"{SONIC_DB_CLI} COUNTERS_DB HSET \"COUNTERS_SRV6_NAME_MAP\" \"fcbb:bbbb:1::/48\" \ + \"oid:0x11110000001eb3\"") cmd = generate_client_cli(duthost=duthost, gnxi_path=gnxi_path, method=METHOD_SUBSCRIBE, subscribe_mode=SUBSCRIBE_MODE_POLL, polling_interval=10, - xpath="\"COUNTERS\" \"SID:*\"", # noqa: W605 + xpath="\"COUNTERS/SID:*\"", # noqa: W605 target="COUNTERS_DB", max_sync_count=-1, update_count=10, timeout=120, namespace=namespace) @@ -294,5 +298,5 @@ def callback(show_gnmi_out): # Give 60 seconds for client to connect to server and then 60 for default route to populate after bgp session start client_thread.join(120) - duthost.shell(f"sonic-db-cli -n {namespace} COUNTERS_DB DEL \"COUNTERS:oid:0x11110000001eb3\"") - duthost.shell(f"sonic-db-cli -n {namespace} COUNTERS_DB HDEL \"COUNTERS_SRV6_NAME_MAP\" \"fcbb:bbbb:1::/48\"") + duthost.shell(f"{SONIC_DB_CLI} COUNTERS_DB DEL \"COUNTERS:oid:0x11110000001eb3\"") + duthost.shell(f"{SONIC_DB_CLI} COUNTERS_DB HDEL \"COUNTERS_SRV6_NAME_MAP\" \"fcbb:bbbb:1::/48\"")