From ce3b6db4b60ca606ff0da2042d7edce6e8a7fcb5 Mon Sep 17 00:00:00 2001 From: vdahiya12 <67608553+vdahiya12@users.noreply.github.com> Date: Thu, 1 Sep 2022 17:49:53 -0700 Subject: [PATCH] [ycabled] fix insert events from xcvrd;cleanup some mux toggle logic (#287) Signed-off-by: vaibhav-dahiya vdahiya@microsoft.com This PR intends to help fix the surplus amount of insert/delete events that ycabled gets it is first spawned, it fixes the logic where an insert event is only handled the way it is collected by xcvrd one time only. Previously there was a known issue for spurious insert/delete events captured by ycabled on config reload, this PR fixes it This PR also cleans up some mux toggle blocking other txns logic. Description Motivation and Context How Has This Been Tested? Unit-tests and deploying changes on Testbed Additional Information (Optional) --- sonic-ycabled/tests/test_ycable.py | 10 ++++++++++ sonic-ycabled/ycable/ycable.py | 13 +++++++++---- .../ycable/ycable_utilities/y_cable_helper.py | 3 +++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/sonic-ycabled/tests/test_ycable.py b/sonic-ycabled/tests/test_ycable.py index a84a48c19bd2..be4b4f3959e0 100644 --- a/sonic-ycabled/tests/test_ycable.py +++ b/sonic-ycabled/tests/test_ycable.py @@ -294,6 +294,16 @@ def test_DaemonYcable_init_deinit_full(self): # TODO: fow now we only simply call ycable.init/deinit without any further check, it only makes sure that # ycable.init/deinit will not raise unexpected exception. In future, probably more check will be added + @patch('ycable.ycable_utilities.y_cable_helper.change_ports_status_for_y_cable_change_event', MagicMock(return_value=0)) + def test_handle_state_update_task(self): + + port = "Ethernet0" + fvp_dict = {} + y_cable_presence = False + stopping_event = None + rc = handle_state_update_task(port, fvp_dict, y_cable_presence, stopping_event) + assert(rc == None) + def wait_until(total_wait_time, interval, call_back, *args, **kwargs): wait_time = 0 diff --git a/sonic-ycabled/ycable/ycable.py b/sonic-ycabled/ycable/ycable.py index a020e2a3f5c3..0d62352c715b 100644 --- a/sonic-ycabled/ycable/ycable.py +++ b/sonic-ycabled/ycable/ycable.py @@ -80,6 +80,14 @@ def detect_port_in_error_status(logical_port_name, status_tbl): else: return False +def handle_state_update_task(port, fvp_dict, y_cable_presence, stopping_event): + + port_dict = {} + port_dict[port] = fvp_dict.get('status', None) + + y_cable_helper.change_ports_status_for_y_cable_change_event( + port_dict, y_cable_presence, stopping_event) + # # Helper classes =============================================================== # @@ -149,7 +157,6 @@ def task_worker(self, stopping_event, sfp_error_event, y_cable_presence): # Connect to STATE_DB and listen to ycable transceiver status update tables state_db, status_tbl= {}, {} - port_dict = {} sel = swsscommon.Select() @@ -195,10 +202,8 @@ def task_worker(self, stopping_event, sfp_error_event, y_cable_presence): if not fvp_dict: continue - port_dict[port] = fvp_dict.get('status', None) + handle_state_update_task(port, fvp_dict, y_cable_presence, stopping_event) - y_cable_helper.change_ports_status_for_y_cable_change_event( - port_dict, y_cable_presence, stopping_event) def task_run(self, sfp_error_event, y_cable_presence): if self.task_stopping_event.is_set(): diff --git a/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py b/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py index c037c22dcb3f..9cb099dfd832 100644 --- a/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py +++ b/sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py @@ -2274,6 +2274,9 @@ def handle_config_prbs_cmd_arg_tbl_notification(fvp, xcvrd_config_prbs_cmd_arg_t status = -1 helper_logger.log_warning("Failed to execute the disable prbs API for port {} due to {}".format(physical_port,repr(e))) elif config_prbs_mode == "reset": + + port_instance.mux_toggle_status = port_instance.MUX_TOGGLE_STATUS_NOT_INITIATED_OR_FINISHED + port_instance.download_firmware_status == port_instance.FIRMWARE_DOWNLOAD_STATUS_NOT_INITIATED_OR_FINISHED with y_cable_port_locks[physical_port]: try: status = port_instance.reset(target)