From 767cfb60d2978f38a935825ada62fd9ffc73820a Mon Sep 17 00:00:00 2001 From: vdahiya12 <67608553+vdahiya12@users.noreply.github.com> Date: Tue, 9 Aug 2022 13:13:59 -0700 Subject: [PATCH] [ycabled] add capability to enable/disable telemetry (#279) This PR provides a capability to sonic-utilities CLI to enable/disable telemetry for ycabled. Basically there is a periodic loop for ycabled which posts telemetry data for that configured interval of time(currently 60 sec). This PR diables this data posting, and does not call platform API calls for ycable. This PR is required for the initiative of getting some failover/switchover not get interfered because of sonic-telemetry API calls. The CLI for enabling/disabling telemetry is config muxcable telemetry enable/disable Description Motivation and Context How Has This Been Tested? UT and deploying changes on Arista testbed Signed-off-by: vaibhav-dahiya --- sonic-ycabled/tests/test_y_cable_helper.py | 18 +++++++ .../ycable/ycable_utilities/y_cable_helper.py | 53 +++++++++++++------ 2 files changed, 56 insertions(+), 15 deletions(-) diff --git a/sonic-ycabled/tests/test_y_cable_helper.py b/sonic-ycabled/tests/test_y_cable_helper.py index 283c71ae0..094b34cc7 100644 --- a/sonic-ycabled/tests/test_y_cable_helper.py +++ b/sonic-ycabled/tests/test_y_cable_helper.py @@ -5331,3 +5331,21 @@ def test_get_grpc_credentials_root(self, open): rc = get_grpc_credentials(type, kvp) assert(rc != None) + + + @patch('ycable.ycable_utilities.y_cable_helper.disable_telemetry') + def test_handle_ycable_enable_disable_tel_notification(self, patch): + + fvp_m = {"disable_telemetry": "True"} + rc = handle_ycable_enable_disable_tel_notification(fvp_m, "Y_CABLE") + assert(rc == None) + + def test_handle_ycable_enable_disable_tel_notification_probe(self): + + fvp_m = {"log_verbosity": "notice"} + rc = handle_ycable_enable_disable_tel_notification(fvp_m, "Y_CABLE") + assert(rc == None) + + fvp_m = {"log_verbosity": "debug"} + rc = handle_ycable_enable_disable_tel_notification(fvp_m, "Y_CABLE") + assert(rc == None) diff --git a/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py b/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py index e1db911d1..245932d23 100644 --- a/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py +++ b/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py @@ -90,6 +90,7 @@ y_cable_port_instances = {} y_cable_port_locks = {} +disable_telemetry = False Y_CABLE_STATUS_NO_TOR_ACTIVE = 0 Y_CABLE_STATUS_TORA_ACTIVE = 1 @@ -1505,6 +1506,11 @@ def delete_ports_status_for_y_cable(): def check_identifier_presence_and_update_mux_info_entry(state_db, mux_tbl, asic_index, logical_port_name): + global disable_telemetry + + if disable_telemetry == True: + return + # Get the namespaces in the platform config_db, port_tbl = {}, {} namespaces = multi_asic.get_front_end_namespaces() @@ -3323,6 +3329,35 @@ def handle_hw_mux_cable_table_grpc_notification(fvp, hw_mux_cable_tbl, asic_inde helper_logger.log_info("Got a change event on port {} of table {} that does not contain state".format( port, swsscommon.APP_HW_MUX_CABLE_TABLE_NAME)) +def handle_ycable_enable_disable_tel_notification(fvp_m, key): + + global disable_telemetry + + if fvp_m: + + if key != "Y_CABLE": + return + + fvp_dict = dict(fvp_m) + if "log_verbosity" in fvp_dict: + # check if xcvrd got a probe command + probe_identifier = fvp_dict["log_verbosity"] + + if probe_identifier == "debug": + helper_logger.set_min_log_priority_debug() + + elif probe_identifier == "notice": + helper_logger.set_min_log_priority_notice() + if "disable_telemetry" in fvp_dict: + # check if xcvrd got a probe command + enable = fvp_dict["disable_telemetry"] + + helper_logger.log_notice("Y_CABLE_DEBUG: trying to enable/disable telemetry flag to {}".format(enable)) + if enable == "True": + disable_telemetry = True + + elif enable == "False": + disable_telemetry = False # Thread wrapper class to update y_cable status periodically class YCableTableUpdateTask(object): @@ -3727,22 +3762,10 @@ def task_cli_worker(self): if not key: break - helper_logger.log_notice("Y_CABLE_DEBUG: trying to enable/disable debug logs") if fvp_m: - - if key == "Y_CABLE": - continue - - fvp_dict = dict(fvp_m) - if "log_verbosity" in fvp_dict: - # check if xcvrd got a probe command - probe_identifier = fvp_dict["log_verbosity"] - - if probe_identifier == "debug": - helper_logger.set_min_log_priority_debug() - - elif probe_identifier == "notice": - helper_logger.set_min_log_priority_notice() + helper_logger.log_notice("Y_CABLE_DEBUG: trying to enable/disable debug logs") + handle_ycable_enable_disable_tel_notification(fvp_m, 'Y_CABLE') + break while True: # show muxcable hwmode state