From 309a5fbb4c3d08fe13d74a16bb1d53bdc5c06cbf Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox <57339448+Junchao-Mellanox@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:52:39 +0800 Subject: [PATCH] Make is_flat_memory more robust (#491) - Description Currently, is_flat_memory could return 3 different values: True when the module is flat memory False when the module is not flat memory None when the EEPROM read returns None or empty bytearray When it returns None, we should not assume that the module is NOT a flat memory. Instead, it would be safer to treat it as a flat memory. - Motivation and Context This PR is to make is_flat_memory only returns two state, True or False. And if EEPROM reading returns None or empty bytearray, we should treat the module as a flat memory. - How Has This Been Tested? Manual test --- sonic_platform_base/sonic_xcvr/api/public/cmis.py | 2 +- sonic_platform_base/sonic_xcvr/api/public/sff8436.py | 2 +- sonic_platform_base/sonic_xcvr/api/public/sff8472.py | 2 +- sonic_platform_base/sonic_xcvr/api/public/sff8636.py | 2 +- sonic_platform_base/sonic_xcvr/api/xcvr_api.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sonic_platform_base/sonic_xcvr/api/public/cmis.py b/sonic_platform_base/sonic_xcvr/api/public/cmis.py index af4328afe..e6aa465d5 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/cmis.py +++ b/sonic_platform_base/sonic_xcvr/api/public/cmis.py @@ -368,7 +368,7 @@ def get_voltage(self): return float("{:.3f}".format(voltage)) def is_flat_memory(self): - return self.xcvr_eeprom.read(consts.FLAT_MEM_FIELD) + return self.xcvr_eeprom.read(consts.FLAT_MEM_FIELD) is not False def get_temperature_support(self): return not self.is_flat_memory() diff --git a/sonic_platform_base/sonic_xcvr/api/public/sff8436.py b/sonic_platform_base/sonic_xcvr/api/public/sff8436.py index 4336cf6f0..c9a17de74 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/sff8436.py +++ b/sonic_platform_base/sonic_xcvr/api/public/sff8436.py @@ -273,7 +273,7 @@ def set_power_override(self, power_override, power_set): return ret def is_flat_memory(self): - return self.xcvr_eeprom.read(consts.FLAT_MEM_FIELD) + return self.xcvr_eeprom.read(consts.FLAT_MEM_FIELD) is not False def get_tx_power_support(self): return False diff --git a/sonic_platform_base/sonic_xcvr/api/public/sff8472.py b/sonic_platform_base/sonic_xcvr/api/public/sff8472.py index 9fe40a16e..fbb91262d 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/sff8472.py +++ b/sonic_platform_base/sonic_xcvr/api/public/sff8472.py @@ -261,7 +261,7 @@ def tx_disable_channel(self, channel, disable): return self.tx_disable(disable) if channel != 0 else True def is_flat_memory(self): - return not self.xcvr_eeprom.read(consts.PAGING_SUPPORT_FIELD) + return not self.xcvr_eeprom.read(consts.PAGING_SUPPORT_FIELD) is not False def get_temperature_support(self): return self.xcvr_eeprom.read(consts.DDM_SUPPORT_FIELD) diff --git a/sonic_platform_base/sonic_xcvr/api/public/sff8636.py b/sonic_platform_base/sonic_xcvr/api/public/sff8636.py index f59163a6c..6d138e01d 100644 --- a/sonic_platform_base/sonic_xcvr/api/public/sff8636.py +++ b/sonic_platform_base/sonic_xcvr/api/public/sff8636.py @@ -299,7 +299,7 @@ def set_power_override(self, power_override, power_set): return ret def is_flat_memory(self): - return self.xcvr_eeprom.read(consts.FLAT_MEM_FIELD) + return self.xcvr_eeprom.read(consts.FLAT_MEM_FIELD) is not False def get_tx_power_support(self): if self.is_copper(): diff --git a/sonic_platform_base/sonic_xcvr/api/xcvr_api.py b/sonic_platform_base/sonic_xcvr/api/xcvr_api.py index d1915a952..c49bf64f9 100644 --- a/sonic_platform_base/sonic_xcvr/api/xcvr_api.py +++ b/sonic_platform_base/sonic_xcvr/api/xcvr_api.py @@ -493,7 +493,7 @@ def is_flat_memory(self): Returns: A Boolean, True if flat memory, False if paging is implemented - If there is an issue with reading the xcvr, None should be returned. + If there is an issue with reading the xcvr, True should be returned. """ raise NotImplementedError