From 75c055e0c1edd2f2498bf375d659637891628374 Mon Sep 17 00:00:00 2001 From: Kebo Liu Date: Sat, 3 Sep 2022 01:17:49 +0800 Subject: [PATCH] [CMIS] 'get_transceiver_info' should return 'None' when CMIS cable EEPROM is not ready (#305) * get_transceiver_info should return None when cmis cable eeprom is not ready Signed-off-by: Kebo Liu * Add more comments to describe the change Signed-off-by: Kebo Liu Signed-off-by: Kebo Liu --- sonic_platform_base/sonic_xcvr/api/public/cmis.py | 11 ++++++++++- tests/sonic_xcvr/test_cmis.py | 4 ++++ 2 files changed, 14 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..7f31a0345 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/cmis.py +++ b/sonic_platform_base/sonic_xcvr/api/public/cmis.py @@ -164,7 +164,16 @@ 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 + + # 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: + 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",[