From e474335f9efd0cfaa20ee5832c116264547c18c0 Mon Sep 17 00:00:00 2001 From: vdahiya12 <67608553+vdahiya12@users.noreply.github.com> Date: Wed, 30 Nov 2022 09:57:19 -0800 Subject: [PATCH] [ycabled] fix minor appl_db retrieving logic for update (#319) Signed-off-by: vaibhav-dahiya vdahiya@microsoft.com This PR fixes the app DB access fix logic by updating the values causing some failures for ycabled's response for mux probe from linkmgrd. This PR essentially fixes that logic, calling the correct method to access the app DB self.appl_db -> self.table_helper.get_appl_db() Description Motivation and Context How Has This Been Tested? UT and deploying changes to kvm Additional Information (Optional) --- sonic-ycabled/tests/test_y_cable_helper.py | 22 +++++++++++ .../ycable/ycable_utilities/y_cable_helper.py | 38 ++++++++++++------- 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/sonic-ycabled/tests/test_y_cable_helper.py b/sonic-ycabled/tests/test_y_cable_helper.py index 752f99129..43226d33b 100644 --- a/sonic-ycabled/tests/test_y_cable_helper.py +++ b/sonic-ycabled/tests/test_y_cable_helper.py @@ -5798,3 +5798,25 @@ def test_apply_grpc_secrets_configuration(self, open): patched_util.return_value = parsed_data rc = apply_grpc_secrets_configuration(None) assert(rc == None) + + + + def test_handle_ycable_active_standby_probe_notification(self): + + test_db = "TEST_DB" + status = True + port_m = "Ethernet0" + fvp_m = [('command', "probe"), ('read_side', 1), ('cable_type','active-standby'), ('soc_ipv4','192.168.0.1')] + fvp_dict = {"command": "probe"} + hw_mux_cable_tbl = {} + y_cable_response_tbl = {} + asic_index = 0 + hw_mux_cable_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + y_cable_response_tbl[asic_index] = swsscommon.Table( + test_db[asic_index], "PORT_INFO_TABLE") + hw_mux_cable_tbl[asic_index].get.return_value = (status, fvp_m) + + rc = handle_ycable_active_standby_probe_notification("active-standby", fvp_dict, test_db, hw_mux_cable_tbl, port_m, asic_index, y_cable_response_tbl) + assert(rc == True) + diff --git a/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py b/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py index cd6a1a667..1e03633c5 100644 --- a/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py +++ b/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py @@ -3411,6 +3411,29 @@ 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_active_standby_probe_notification(cable_type, fvp_dict, appl_db, hw_mux_cable_tbl, port_m, asic_index, y_cable_response_tbl): + + if cable_type == 'active-standby' and "command" in fvp_dict: + + # check if xcvrd got a probe command + probe_identifier = fvp_dict["command"] + + if probe_identifier == "probe": + + (status, fv) = hw_mux_cable_tbl[asic_index].get(port_m) + + if status is False: + helper_logger.log_warning("Could not retreive fieldvalue pairs for {}, inside state_db table {}".format( + port_m, hw_mux_cable_tbl[asic_index].getTableName())) + return False + + mux_port_dict = dict(fv) + read_side = mux_port_dict.get("read_side") + update_appdb_port_mux_cable_response_table(port_m, asic_index, appl_db, int(read_side), y_cable_response_tbl) + + return True + def handle_ycable_enable_disable_tel_notification(fvp_m, key): global disable_telemetry @@ -3576,21 +3599,8 @@ def task_worker(self): (status, cable_type) = check_mux_cable_port_type(port_m, self.table_helper.get_port_tbl(), asic_index) if status: + handle_ycable_active_standby_probe_notification(cable_type, fvp_dict, self.table_helper.get_appl_db(), self.table_helper.get_hw_mux_cable_tbl(), port_m, asic_index, self.table_helper.get_y_cable_response_tbl()) - if cable_type == 'active-standby' and "command" in fvp_dict: - - # check if xcvrd got a probe command - probe_identifier = fvp_dict["command"] - - if probe_identifier == "probe": - (status, fv) = self.table_helper.get_hw_mux_cable_tbl()[asic_index].get(port_m) - if status is False: - helper_logger.log_warning("Could not retreive fieldvalue pairs for {}, inside state_db table {}".format( - port_m, self.table_helper.get_hw_mux_cable_tbl()[asic_index].getTableName())) - continue - mux_port_dict = dict(fv) - read_side = mux_port_dict.get("read_side") - update_appdb_port_mux_cable_response_table(port_m, asic_index, self.appl_db, int(read_side), self.table_helper.get_y_cable_response_tbl()) while True: (port_m, op_m, fvp_m) = self.table_helper.get_fwd_state_command_tbl()[asic_index].pop()