From c84372dc6b6299088e8beeecdcecd5e590657aeb Mon Sep 17 00:00:00 2001 From: Kebo Liu Date: Wed, 31 Aug 2022 14:14:16 +0800 Subject: [PATCH 1/2] get_transceiver_info should return None when cmis cable eeprom is not ready Signed-off-by: Kebo Liu --- sonic_platform_base/sonic_xcvr/api/public/cmis.py | 5 ++++- tests/sonic_xcvr/test_cmis.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sonic_platform_base/sonic_xcvr/api/public/cmis.py b/sonic_platform_base/sonic_xcvr/api/public/cmis.py index 37a5b9e89..c6ac0f049 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/cmis.py +++ b/sonic_platform_base/sonic_xcvr/api/public/cmis.py @@ -164,7 +164,10 @@ def get_transceiver_info(self): xcvr_info['active_firmware'] = self.get_module_active_firmware() xcvr_info['inactive_firmware'] = self.get_module_inactive_firmware() xcvr_info['specification_compliance'] = self.get_module_media_type() - return xcvr_info + if None in xcvr_info.values(): + return None + else: + return xcvr_info def get_transceiver_bulk_status(self): rx_los = self.get_rx_los() diff --git a/tests/sonic_xcvr/test_cmis.py b/tests/sonic_xcvr/test_cmis.py index f61a29832..a174eb50f 100644 --- a/tests/sonic_xcvr/test_cmis.py +++ b/tests/sonic_xcvr/test_cmis.py @@ -1157,6 +1157,10 @@ def test_get_transceiver_info(self, mock_response, expected): self.api.is_flat_memory.return_value = False result = self.api.get_transceiver_info() assert result == expected + # Test negative path + self.api.get_cmis_rev.return_value = None + result = self.api.get_transceiver_info() + assert result == None @pytest.mark.parametrize("mock_response, expected",[ From 2a0d389dfff05b096759997165af35388a8840df Mon Sep 17 00:00:00 2001 From: Kebo Liu Date: Thu, 1 Sep 2022 18:29:59 +0800 Subject: [PATCH 2/2] Add more comments to describe the change Signed-off-by: Kebo Liu --- sonic_platform_base/sonic_xcvr/api/public/cmis.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sonic_platform_base/sonic_xcvr/api/public/cmis.py b/sonic_platform_base/sonic_xcvr/api/public/cmis.py index c6ac0f049..7f31a0345 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/cmis.py +++ b/sonic_platform_base/sonic_xcvr/api/public/cmis.py @@ -164,6 +164,12 @@ def get_transceiver_info(self): xcvr_info['active_firmware'] = self.get_module_active_firmware() xcvr_info['inactive_firmware'] = self.get_module_inactive_firmware() xcvr_info['specification_compliance'] = self.get_module_media_type() + + # In normal case will get a valid value for each of the fields. If get a 'None' value + # means there was a failure while reading the EEPROM, either because the EEPROM was + # not ready yet or experincing some other issues. It shouldn't return a dict with a + # wrong field value, instead should return a 'None' to indicate to XCVRD that retry is + # needed. if None in xcvr_info.values(): return None else: