diff --git a/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/fan.py b/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/fan.py index e38f96d6f0..cf698bf6d0 100644 --- a/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/fan.py +++ b/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/fan.py @@ -28,6 +28,9 @@ PSU_I2C_MAPPING = { }, } +FAN_NAME_LIST = ["FAN-1F", "FAN-1R", "FAN-2F", "FAN-2R", + "FAN-3F", "FAN-3R", "FAN-4F", "FAN-4R", + "FAN-5F", "FAN-5R"] class Fan(FanBase): """Platform-specific Fan class""" @@ -44,7 +47,7 @@ class Fan(FanBase): self.psu_hwmon_path = PSU_HWMON_I2C_PATH.format( self.psu_i2c_num, self.psu_i2c_addr) - FanBase.__init__(self) + FanBase.__init__(self) def get_direction(self): @@ -57,10 +60,10 @@ class Fan(FanBase): if not self.is_psu_fan: - dir_str = "{}{}{}".format(CPLD_I2C_PATH, self.fan_tray_index, '_direction') + dir_str = "{}{}{}".format(CPLD_I2C_PATH, self.fan_tray_index+1, '_direction') val=self._api_helper.read_txt_file(dir_str) if val is not None: - if val==0: + if int(val, 10)==0: direction=self.FAN_DIRECTION_EXHAUST else: direction=self.FAN_DIRECTION_INTAKE @@ -70,7 +73,7 @@ class Fan(FanBase): dir_str = "{}{}".format(self.psu_hwmon_path,'psu_fan_dir') val=self._api_helper.read_txt_file(dir_str) - + if val is not None: if val=='F2B': direction=self.FAN_DIRECTION_EXHAUST @@ -159,6 +162,33 @@ class Fan(FanBase): """ return False #Not supported + def get_status_led(self): + """ + Gets the state of the fan status LED + Returns: + A string, one of the predefined STATUS_LED_COLOR_* strings above + """ + status=self.get_presence() + if status is None: + return self.STATUS_LED_COLOR_OFF + + return { + 1: self.STATUS_LED_COLOR_GREEN, + 0: self.STATUS_LED_COLOR_RED + }.get(status, self.STATUS_LED_COLOR_OFF) + + def get_name(self): + """ + Retrieves the name of the device + Returns: + string: The name of the device + """ + fan_name = FAN_NAME_LIST[self.fan_tray_index*2 + self.fan_index] \ + if not self.is_psu_fan \ + else "PSU-{} FAN-{}".format(self.psu_index+1, self.fan_index+1) + + return fan_name + def get_presence(self): """ Retrieves the presence of the FAN @@ -177,3 +207,41 @@ class Fan(FanBase): else: return True + def get_status(self): + """ + Retrieves the operational status of the device + Returns: + A boolean value, True if device is operating properly, False if not + """ + if self.is_psu_fan: + psu_fan_path= "{}{}".format(self.psu_hwmon_path, 'psu_fan1_fault') + val=self._api_helper.read_txt_file(psu_fan_path) + if val is not None: + return int(val, 10)==0 + else: + return False + else: + path = "{}{}{}".format(CPLD_I2C_PATH, self.fan_index+1, '_fault') + val=self._api_helper.read_txt_file(path) + if val is not None: + return int(val, 10)==0 + else: + return False + + + def get_model(self): + """ + Retrieves the model number (or part number) of the device + Returns: + string: Model/part number of device + """ + + return "N/A" + + def get_serial(self): + """ + Retrieves the serial number of the device + Returns: + string: Serial number of device + """ + return "N/A" diff --git a/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/psu.py b/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/psu.py index 78c91df8a8..dd60589206 100644 --- a/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/psu.py +++ b/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/psu.py @@ -104,7 +104,7 @@ class Psu(PsuBase): return float(val)/1000 else: return 0 - + def get_powergood_status(self): """ Retrieves the powergood status of PSU @@ -123,7 +123,7 @@ class Psu(PsuBase): Returns: bool: True if status LED state is set successfully, False if not """ - + return False #Controlled by HW def get_status_led(self): @@ -133,14 +133,13 @@ class Psu(PsuBase): A string, one of the predefined STATUS_LED_COLOR_* strings above """ status=self.get_status() - if not status: - return self.STATUS_LED_COLOR_RED - - if status==1: - return self.STATUS_LED_COLOR_GREEN - else: - return self.STATUS_LED_COLOR_RED + if status is None: + return self.STATUS_LED_COLOR_OFF + return { + 1: self.STATUS_LED_COLOR_GREEN, + 0: self.STATUS_LED_COLOR_RED + }.get(status, self.STATUS_LED_COLOR_OFF) def get_temperature(self): """ @@ -235,7 +234,8 @@ class Psu(PsuBase): """ model_path="{}{}".format(self.cpld_path, 'psu_model_name') model=self._api_helper.read_txt_file(model_path) - if not model: + + if model is None: return "N/A" return model @@ -247,6 +247,7 @@ class Psu(PsuBase): """ serial_path="{}{}".format(self.cpld_path, 'psu_serial_numer') serial=self._api_helper.read_txt_file(serial_path) - if not serial: + + if serial is None: return "N/A" return serial diff --git a/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/sfp.py b/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/sfp.py index 24f91c3b7b..4ea043f3d4 100644 --- a/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/sfp.py +++ b/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/sfp.py @@ -18,6 +18,7 @@ try: from sonic_platform_base.sonic_sfp.sff8436 import sff8436InterfaceId from sonic_platform_base.sonic_sfp.sff8472 import sff8472Dom from sonic_platform_base.sonic_sfp.sff8472 import sff8472InterfaceId + #from sonic_platform_base.sonic_sfp.sff8472 import sffbase from sonic_platform_base.sonic_sfp.sfputilhelper import SfpUtilHelper from .helper import APIHelper except ImportError as e: @@ -241,14 +242,6 @@ class Sfp(SfpBase): else: return 'N/A' - def __write_txt_file(self, file_path, value): - try: - with open(file_path, 'w') as fd: - fd.write(str(value)) - except Exception: - return False - return True - def __is_host(self): return os.system(self.HOST_CHK_CMD) == 0 @@ -1006,11 +999,11 @@ class Sfp(SfpBase): cpld_i = self.__get_cpld_num(self.port_num) cpld_path = self._cpld_mapping[cpld_i] reset_path = "{}{}{}{}".format(CPLD_I2C_PATH, cpld_path, '/module_reset_', self.port_num) - ret = self.__write_txt_file(reset_path, 1) + ret = self._api_helper.write_txt_file(reset_path, 1) if ret is not True: time.sleep(0.01) - ret = self.__write_txt_file(reset_path, 0) + ret = self.self._api_helper.write_txt_file(reset_path, 0) time.sleep(0.2) return ret else: @@ -1030,7 +1023,7 @@ class Sfp(SfpBase): cpld_i = self.__get_cpld_num(self.port_num) cpld_path = self._cpld_mapping[cpld_i] tx_path = "{}{}{}{}".format(CPLD_I2C_PATH, cpld_path, '/module_tx_disable_', self.port_num) - ret = self.__write_txt_file(tx_path, 1 if tx_disable else 0) + ret = self._api_helper.write_txt_file(tx_path, 1 if tx_disable else 0) if ret is not None: time.sleep(0.01) diff --git a/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/thermal.py b/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/thermal.py index d5269ec2b1..46458d02a1 100644 --- a/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/thermal.py +++ b/device/accton/x86_64-accton_as5835_54x-r0/sonic_platform/thermal.py @@ -44,7 +44,7 @@ class Thermal(ThermalBase): self.ss_index = 1 def __read_txt_file(self, file_path): - for filename in glob.glob(file_path): + for filename in glob.glob(file_path): try: with open(filename, 'r') as fd: data =fd.readline().rstrip()