From 6f63238c1a1b6c6b317ddc1a353c034a50cf2c8e Mon Sep 17 00:00:00 2001 From: roger530_ho Date: Tue, 7 Jan 2025 11:34:35 +0800 Subject: [PATCH] Fix the failed test cases for sonic-mgmt. --- .../x86_64-accton_as9817_32d-r0/platform.json | 7 + .../x86_64-accton_as9817_32o-r0/platform.json | 7 + .../sonic_platform/sfp.py | 176 +++++++++++++++--- 3 files changed, 163 insertions(+), 27 deletions(-) diff --git a/device/accton/x86_64-accton_as9817_32d-r0/platform.json b/device/accton/x86_64-accton_as9817_32d-r0/platform.json index 16e71013c..7af3eec96 100644 --- a/device/accton/x86_64-accton_as9817_32d-r0/platform.json +++ b/device/accton/x86_64-accton_as9817_32d-r0/platform.json @@ -174,6 +174,7 @@ "status_led": { "controllable": false }, + "max_consumed_power": false, "num_fans" : 2, "fans": [ { @@ -203,6 +204,7 @@ "status_led": { "controllable": false }, + "max_consumed_power": false, "num_fans" : 2, "fans": [ { @@ -232,6 +234,7 @@ "status_led": { "controllable": false }, + "max_consumed_power": false, "num_fans" : 2, "fans": [ { @@ -261,6 +264,7 @@ "status_led": { "controllable": false }, + "max_consumed_power": false, "num_fans" : 2, "fans": [ { @@ -290,6 +294,7 @@ "status_led": { "controllable": false }, + "max_consumed_power": false, "num_fans" : 2, "fans": [ { @@ -319,6 +324,7 @@ "status_led": { "controllable": false }, + "max_consumed_power": false, "num_fans" : 2, "fans": [ { @@ -348,6 +354,7 @@ "status_led": { "controllable": false }, + "max_consumed_power": false, "num_fans" : 2, "fans": [ { diff --git a/device/accton/x86_64-accton_as9817_32o-r0/platform.json b/device/accton/x86_64-accton_as9817_32o-r0/platform.json index e7a0efaba..a2a1c7940 100644 --- a/device/accton/x86_64-accton_as9817_32o-r0/platform.json +++ b/device/accton/x86_64-accton_as9817_32o-r0/platform.json @@ -174,6 +174,7 @@ "status_led": { "controllable": false }, + "max_consumed_power": false, "num_fans" : 2, "fans": [ { @@ -203,6 +204,7 @@ "status_led": { "controllable": false }, + "max_consumed_power": false, "num_fans" : 2, "fans": [ { @@ -232,6 +234,7 @@ "status_led": { "controllable": false }, + "max_consumed_power": false, "num_fans" : 2, "fans": [ { @@ -261,6 +264,7 @@ "status_led": { "controllable": false }, + "max_consumed_power": false, "num_fans" : 2, "fans": [ { @@ -290,6 +294,7 @@ "status_led": { "controllable": false }, + "max_consumed_power": false, "num_fans" : 2, "fans": [ { @@ -319,6 +324,7 @@ "status_led": { "controllable": false }, + "max_consumed_power": false, "num_fans" : 2, "fans": [ { @@ -348,6 +354,7 @@ "status_led": { "controllable": false }, + "max_consumed_power": false, "num_fans" : 2, "fans": [ { diff --git a/device/accton/x86_64-accton_as9817_32o-r0/sonic_platform/sfp.py b/device/accton/x86_64-accton_as9817_32o-r0/sonic_platform/sfp.py index 16e35b4e1..1bbf01465 100644 --- a/device/accton/x86_64-accton_as9817_32o-r0/sonic_platform/sfp.py +++ b/device/accton/x86_64-accton_as9817_32o-r0/sonic_platform/sfp.py @@ -276,6 +276,147 @@ def update_sfp_type(self): return ret + def validate_eeprom_sfp(self): + checksum_test = 0 + eeprom_raw = self.read_eeprom(0, 96) + if eeprom_raw is None: + return False + + for i in range(0, 63): + checksum_test = (checksum_test + eeprom_raw[i]) & 0xFF + else: + if checksum_test != eeprom_raw[63]: + return False + + checksum_test = 0 + for i in range(64, 95): + checksum_test = (checksum_test + eeprom_raw[i]) & 0xFF + else: + if checksum_test != eeprom_raw[95]: + return False + + api = self.get_xcvr_api() + if api is None: + return False + + if api.is_flat_memory(): + return True + + checksum_test = 0 + eeprom_raw = self.read_eeprom(384, 96) + if eeprom_raw is None: + return False + + for i in range(0, 95): + checksum_test = (checksum_test + eeprom_raw[i]) & 0xFF + else: + if checksum_test != eeprom_raw[95]: + return False + + return True + + def validate_eeprom_qsfp(self): + checksum_test = 0 + eeprom_raw = self.read_eeprom(128, 96) + if eeprom_raw is None: + return None + + for i in range(0, 63): + checksum_test = (checksum_test + eeprom_raw[i]) & 0xFF + else: + if checksum_test != eeprom_raw[63]: + return False + + checksum_test = 0 + for i in range(64, 95): + checksum_test = (checksum_test + eeprom_raw[i]) & 0xFF + else: + if checksum_test != eeprom_raw[95]: + return False + + api = self.get_xcvr_api() + if api is None: + return False + + if api.is_flat_memory(): + return True + + return True + + def validate_eeprom_cmis(self): + checksum_test = 0 + eeprom_raw = self.read_eeprom(128, 95) + if eeprom_raw is None: + return None + + for i in range(0, 94): + checksum_test = (checksum_test + eeprom_raw[i]) & 0xFF + else: + if checksum_test != eeprom_raw[94]: + return False + + api = self.get_xcvr_api() + if api is None: + return False + + if api.is_flat_memory(): + return True + + checksum_test = 0 + eeprom_raw = self.read_eeprom(258, 126) + if eeprom_raw is None: + return None + + for i in range(0, 125): + checksum_test = (checksum_test + eeprom_raw[i]) & 0xFF + else: + if checksum_test != eeprom_raw[125]: + return False + + checksum_test = 0 + eeprom_raw = self.read_eeprom(384, 128) + if eeprom_raw is None: + return None + + for i in range(0, 127): + checksum_test = (checksum_test + eeprom_raw[i]) & 0xFF + else: + if checksum_test != eeprom_raw[127]: + return False + + # CMIS_5.0 starts to support the checksum of page 04h + cmis_rev = float(api.get_cmis_rev()) + if cmis_rev >= 5.0: + checksum_test = 0 + eeprom_raw = self.read_eeprom(640, 128) + if eeprom_raw is None: + return None + + for i in range(0, 127): + checksum_test = (checksum_test + eeprom_raw[i]) & 0xFF + else: + if checksum_test != eeprom_raw[127]: + return False + + return True + + def validate_eeprom(self): + id_byte_raw = self.read_eeprom(0, 1) + if id_byte_raw is None: + return False + + id = id_byte_raw[0] + if id in self.QSFP_TYPE_CODE_LIST: + return self.validate_eeprom_qsfp() + elif id in self.SFP_TYPE_CODE_LIST: + return self.validate_eeprom_sfp() + elif id in self.QSFP_DD_TYPE_CODE_LIST: + return self.validate_eeprom_cmis() + elif id in self.OSFP_TYPE_CODE_LIST: + return self.validate_eeprom_cmis() + else: + return False + def validate_temperature(self): temperature = self.get_temperature() if temperature is None: @@ -299,8 +440,8 @@ def __get_error_description(self): err_stat = self.SFP_STATUS_BIT_INSERTED - err_eeprom = self.get_checksum_error() - if err_eeprom != "": + status = self.validate_eeprom() + if status is not True: err_stat = (err_stat | self.SFP_ERROR_BIT_BAD_EEPROM) status = self.validate_temperature() @@ -317,10 +458,7 @@ def __get_error_description(self): if cnt > 0: err_desc = err_desc + "|" cnt = cnt + 1 - if key == self.SFP_ERROR_BIT_BAD_EEPROM: - err_desc = err_desc + err_eeprom - else: - err_desc = err_desc + self.SFP_ERROR_BIT_TO_DESCRIPTION_DICT[key] + err_desc = err_desc + self.SFP_ERROR_BIT_TO_DESCRIPTION_DICT[key] return err_desc @@ -336,26 +474,10 @@ def get_error_description(self): if not self.get_presence(): return self.SFP_STATUS_UNPLUGGED - api = self.get_xcvr_api() - if api == None: - return self.SFP_ERROR_BIT_TO_DESCRIPTION_DICT[self.SFP_ERROR_BIT_BAD_EEPROM] - try: - optoe_state = super().get_error_description() + state = super().get_error_description() + if state is None: + return self.SFP_STATUS_OK + return state except NotImplementedError: - optoe_state = None - - state = self.__get_error_description() - if state == self.SFP_STATUS_OK: - if optoe_state == None: - err_desc = self.SFP_STATUS_OK - else: - err_desc = optoe_state - else: - if optoe_state == None: - err_desc = state - else: - err_desc = optoe_state + "|" + state - - return err_desc - + return self.__get_error_description()