From ce07586659a568844d68f9501a809ba7814ad267 Mon Sep 17 00:00:00 2001 From: Wirut Getbamrung Date: Thu, 29 Aug 2019 01:19:34 +0700 Subject: [PATCH] [platform/cel]: Add new API installer to pmon and base image (#3379) * [platform/cel]: Add new api installer * [device/celestica]: Update APIs to support both pmon and base image * [device/e1031]: update hwmon name --- .../x86_64-cel_e1031-r0/fancontrol-B2F | 2 +- .../sonic_platform/__init__.py | 2 + .../sonic_platform/chassis.py | 19 ++++-- .../x86_64-cel_e1031-r0/sonic_platform/fan.py | 1 + .../x86_64-cel_e1031-r0/sonic_platform/sfp.py | 48 ++++++--------- .../sonic_platform/thermal.py | 8 +-- .../sonic_platform/__init__.py | 2 + .../sonic_platform/chassis.py | 34 +++++++++-- .../sonic_platform/fan.py | 1 - .../sonic_platform/sfp.py | 61 +++++++++---------- .../sonic_platform/thermal.py | 16 +++-- .../debian/platform-modules-dx010.init | 2 + .../debian/platform-modules-dx010.install | 2 + .../debian/platform-modules-dx010.postinst | 3 + .../debian/platform-modules-haliburton.init | 2 + .../platform-modules-haliburton.install | 2 + .../platform-modules-haliburton.postinst | 4 +- .../sonic-platform-modules-cel/debian/rules | 3 + .../sonic-platform-modules-cel/dx010/setup.py | 34 +++++++++++ .../haliburton/setup.py | 34 +++++++++++ .../platform_api/platform_api_mgnt.sh | 41 +++++++++++++ 21 files changed, 230 insertions(+), 91 deletions(-) create mode 100644 platform/broadcom/sonic-platform-modules-cel/dx010/setup.py create mode 100644 platform/broadcom/sonic-platform-modules-cel/haliburton/setup.py create mode 100755 platform/broadcom/sonic-platform-modules-cel/services/platform_api/platform_api_mgnt.sh diff --git a/device/celestica/x86_64-cel_e1031-r0/fancontrol-B2F b/device/celestica/x86_64-cel_e1031-r0/fancontrol-B2F index cab392995bb5..883f3c0c899d 100644 --- a/device/celestica/x86_64-cel_e1031-r0/fancontrol-B2F +++ b/device/celestica/x86_64-cel_e1031-r0/fancontrol-B2F @@ -1,7 +1,7 @@ # Configuration file generated by pwmconfig, changes will be lost INTERVAL=2 DEVPATH=hwmon3=devices/pci0000:00/0000:00:13.0/i2c-0/i2c-8/i2c-23/23-004d hwmon2=devices/pci0000:00/0000:00:13.0/i2c-0/i2c-8/i2c-11/11-001a -DEVNAME=hwmon3=emc2305 hwmon2=max6697 +DEVNAME=hwmon3=emc2305 hwmon2=max6699 FCTEMPS=hwmon3/device/pwm1=hwmon2/temp1_input hwmon3/device/pwm2=hwmon2/temp1_input hwmon3/device/pwm4=hwmon2/temp1_input FCFANS=hwmon3/device/pwm1=hwmon3/device/fan1_input hwmon3/device/pwm2=hwmon3/device/fan2_input hwmon3/device/pwm4=hwmon3/device/fan4_input MINTEMP=hwmon3/device/pwm1=27 hwmon3/device/pwm2=27 hwmon3/device/pwm4=27 diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/__init__.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/__init__.py index e69de29bb2d1..d82f3749319c 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/__init__.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/__init__.py @@ -0,0 +1,2 @@ +__all__ = ["platform", "chassis"] +from sonic_platform import * diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py index a611be9d47dc..fde9afaa6f46 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py @@ -31,8 +31,10 @@ NUM_THERMAL = 7 NUM_SFP = 52 RESET_REGISTER = "0x112" -REBOOT_CAUSE_PATH = "/host/reboot-cause/previous-reboot-cause.txt" +HOST_REBOOT_CAUSE_PATH = "/host/reboot-cause/previous-reboot-cause.txt" +PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/previous-reboot-cause.txt" COMPONENT_NAME_LIST = ["SMC_CPLD", "MMC_CPLD", "BIOS"] +HOST_CHK_CMD = "docker > /dev/null 2>&1" class Chassis(ChassisBase): @@ -53,17 +55,23 @@ def __init__(self): sfp = Sfp(index) self._sfp_list.append(sfp) ChassisBase.__init__(self) + self._reboot_cause_path = HOST_REBOOT_CAUSE_PATH if self.__is_host( + ) else PMON_REBOOT_CAUSE_PATH self._component_name_list = COMPONENT_NAME_LIST self._watchdog = Watchdog() self._eeprom = Tlv() + def __is_host(self): + return os.system(HOST_CHK_CMD) == 0 + def __read_txt_file(self, file_path): try: with open(file_path, 'r') as fd: data = fd.read() return data.strip() except IOError: - raise IOError("Unable to open %s file !" % file_path) + pass + return None def get_base_mac(self): """ @@ -137,14 +145,15 @@ def get_reboot_cause(self): description = 'None' reboot_cause = self.REBOOT_CAUSE_HARDWARE_OTHER hw_reboot_cause = self.component.get_register_value(RESET_REGISTER) - sw_reboot_cause = self.__read_txt_file(REBOOT_CAUSE_PATH) + sw_reboot_cause = self.__read_txt_file( + self._reboot_cause_path) or "Unknown" - if sw_reboot_cause != "Unexpected reboot": + if hw_reboot_cause == "0x55": reboot_cause = self.REBOOT_CAUSE_NON_HARDWARE description = sw_reboot_cause elif hw_reboot_cause == "0x11": reboot_cause = self.REBOOT_CAUSE_POWER_LOSS - elif hw_reboot_cause == "0x33" or hw_reboot_cause == "0x55": + elif hw_reboot_cause == "0x33": reboot_cause = self.REBOOT_CAUSE_WATCHDOG else: reboot_cause = self.REBOOT_CAUSE_HARDWARE_OTHER diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/fan.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/fan.py index ad993ce24182..88e21b3e5ee9 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/fan.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/fan.py @@ -34,6 +34,7 @@ def __init__(self, fan_index): self.index = fan_index self.config_data = {} self.fan_speed = 0 + FanBase.__init__(self) # e1031 fan attributes # Single emc2305 chip located at i2c-23-4d diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py index 8379299569f5..c67e487e4cd4 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/sfp.py @@ -35,6 +35,7 @@ class Sfp(SfpBase, SfpUtilBase): } PRS_PATH = "/sys/devices/platform/e1031.smc/SFP/sfp_modabs" PLATFORM_ROOT_PATH = '/usr/share/sonic/device' + PMON_HWSKU_PATH = '/usr/share/sonic/hwsku' SFP_STATUS_CONTROL_OFFSET = 110 SFP_STATUS_CONTROL_WIDTH = 1 @@ -61,6 +62,9 @@ class Sfp(SfpBase, SfpUtilBase): SFP_EEPROM_TX_PWR_KEY = "TXPower" SFP_EEPROM_TX_BS_KEY = "TXBias" SFP_EEPROM_STATUS_CON_KEY = "StatusControl" + PLATFORM = "x86_64-cel_e1031-r0" + HWSKU = "Celestica-E1031-T48S4" + HOST_CHK_CMD = "docker > /dev/null 2>&1" @property def port_start(self): @@ -122,6 +126,9 @@ def __init__(self, sfp_index): self.index = sfp_index self.port_num = self.index + 1 + def __is_host(self): + return os.system(self.HOST_CHK_CMD) == 0 + def __get_sysfsfile_eeprom(self): sysfsfile_eeprom = None sysfs_sfp_i2c_client_eeprom_path = self.port_to_eeprom_mapping[self.port_num] @@ -129,33 +136,14 @@ def __get_sysfsfile_eeprom(self): sysfsfile_eeprom = open( sysfs_sfp_i2c_client_eeprom_path, mode="r+b", buffering=0) except IOError: - print("Error: reading sysfs file %s" % - sysfs_sfp_i2c_client_eeprom_path) + pass return sysfsfile_eeprom def __get_path_to_port_config_file(self): - # Get platform and hwsku - machine_info = sonic_device_util.get_machine_info() - platform = sonic_device_util.get_platform_info(machine_info) - config_db = ConfigDBConnector() - config_db.connect() - data = config_db.get_table('DEVICE_METADATA') - try: - hwsku = data['localhost']['hwsku'] - except KeyError: - hwsku = "Unknown" - - # Load platform module from source - platform_path = "/".join([self.PLATFORM_ROOT_PATH, platform]) - hwsku_path = "/".join([platform_path, hwsku]) - - # First check for the presence of the new 'port_config.ini' file - port_config_file_path = "/".join([hwsku_path, "port_config.ini"]) - if not os.path.isfile(port_config_file_path): - # port_config.ini doesn't exist. Try loading the legacy 'portmap.ini' file - port_config_file_path = "/".join([hwsku_path, "portmap.ini"]) - - return port_config_file_path + platform_path = "/".join([self.PLATFORM_ROOT_PATH, self.PLATFORM]) + hwsku_path = "/".join([platform_path, self.HWSKU] + ) if self.__is_host() else self.PMON_HWSKU_PATH + return "/".join([hwsku_path, "port_config.ini"]) def get_transceiver_info(self): """ @@ -405,7 +393,7 @@ def get_tx_bias(self): """ transceiver_dom_info_dict = self.get_transceiver_bulk_status() tx1_bs = transceiver_dom_info_dict.get("tx1bias", "N/A") - return [tx1_bs, "N/A", "N/A", "N/A"] + return [tx1_bs, "N/A", "N/A", "N/A"] if transceiver_dom_info_dict else [] def get_rx_power(self): """ @@ -417,7 +405,7 @@ def get_rx_power(self): """ transceiver_dom_info_dict = self.get_transceiver_bulk_status() rx1_pw = transceiver_dom_info_dict.get("rx1power", "N/A") - return [rx1_pw, "N/A", "N/A", "N/A"] + return [rx1_pw, "N/A", "N/A", "N/A"] if transceiver_dom_info_dict else [] def get_tx_power(self): """ @@ -429,7 +417,7 @@ def get_tx_power(self): """ transceiver_dom_info_dict = self.get_transceiver_bulk_status() tx1_pw = transceiver_dom_info_dict.get("tx1power", "N/A") - return [tx1_pw, "N/A", "N/A", "N/A"] + return [tx1_pw, "N/A", "N/A", "N/A"] if transceiver_dom_info_dict else [] def reset(self): """ @@ -452,7 +440,7 @@ def tx_disable(self, tx_disable): sysfsfile_eeprom = self.__get_sysfsfile_eeprom() status_control_raw = self._read_eeprom_specific_bytes( - sysfsfile_eeprom, self.SFP_STATUS_CONTROL_OFFSET, self.SFP_STATUS_CONTROL_WIDTH) + sysfsfile_eeprom, self.SFP_STATUS_CONTROL_OFFSET, self.SFP_STATUS_CONTROL_WIDTH) if sysfsfile_eeprom else None if status_control_raw is not None: tx_disable_bit = 0x80 if tx_disable else 0x7f status_control = int(status_control_raw[0], 16) @@ -551,7 +539,7 @@ def get_model(self): Returns: string: Model/part number of device """ - transceiver_dom_info_dict = self.get_transceiver_bulk_status() + transceiver_dom_info_dict = self.get_transceiver_info() return transceiver_dom_info_dict.get("modelname", "N/A") def get_serial(self): @@ -560,5 +548,5 @@ def get_serial(self): Returns: string: Serial number of device """ - transceiver_dom_info_dict = self.get_transceiver_bulk_status() + transceiver_dom_info_dict = self.get_transceiver_info() return transceiver_dom_info_dict.get("serialnum", "N/A") diff --git a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/thermal.py b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/thermal.py index a6d45dc41c93..6c37f3b7ce88 100644 --- a/device/celestica/x86_64-cel_e1031-r0/sonic_platform/thermal.py +++ b/device/celestica/x86_64-cel_e1031-r0/sonic_platform/thermal.py @@ -22,8 +22,8 @@ class Thermal(ThermalBase): """Platform-specific Thermal class""" THERMAL_NAME_LIST = [] - MAINBOARD_SS_PATH = "/sys/class/i2c-adapter/i2c-11/11-001a/hwmon/" - CPUBOARD_SS_PATH = "/sys/class/i2c-adapter/i2c-3/3-001a/hwmon/" + MAINBOARD_SS_PATH = "/sys/class/i2c-adapter/i2c-11/11-001a/hwmon/hwmon2" + CPUBOARD_SS_PATH = "/sys/class/i2c-adapter/i2c-3/3-001a/hwmon/hwmon1" SS_CONFIG_PATH = "/usr/share/sonic/device/x86_64-cel_e1031-r0/sensors.conf" def __init__(self, thermal_index): @@ -41,10 +41,8 @@ def __init__(self, thermal_index): self.THERMAL_NAME_LIST.append("CPU board temperature sensor : 2") # Set hwmon path - self.ss_index, self.ss_path = self.__get_ss_info(self.index) + self.ss_index, self.hwmon_path = self.__get_ss_info(self.index) self.ss_key = self.THERMAL_NAME_LIST[self.index] - self.hwmon_name = os.listdir(self.ss_path)[0] - self.hwmon_path = os.path.join(self.ss_path, self.hwmon_name) def __get_ss_info(self, index): if self.index <= 4: diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/__init__.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/__init__.py index e69de29bb2d1..d82f3749319c 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/__init__.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/__init__.py @@ -0,0 +1,2 @@ +__all__ = ["platform", "chassis"] +from sonic_platform import * diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py index 5e98cb3d3db8..91db08f4a61e 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/chassis.py @@ -31,8 +31,12 @@ NUM_THERMAL = 5 NUM_SFP = 32 RESET_REGISTER = "0x103" -REBOOT_CAUSE_PATH = "/host/reboot-cause/previous-reboot-cause.txt" +HOST_REBOOT_CAUSE_PATH = "/host/reboot-cause/" +PMON_REBOOT_CAUSE_PATH = "/usr/share/sonic/platform/api_files/reboot-cause/" +REBOOT_CAUSE_FILE = "reboot-cause.txt" +PREV_REBOOT_CAUSE_FILE = "previous-reboot-cause.txt" COMPONENT_NAME_LIST = ["CPLD1", "CPLD2", "CPLD3", "CPLD4", "BIOS"] +HOST_CHK_CMD = "docker > /dev/null 2>&1" class Chassis(ChassisBase): @@ -53,17 +57,22 @@ def __init__(self): sfp = Sfp(index) self._sfp_list.append(sfp) ChassisBase.__init__(self) + self._component_name_list = COMPONENT_NAME_LIST self._watchdog = Watchdog() self._eeprom = Tlv() + def __is_host(self): + return os.system(HOST_CHK_CMD) == 0 + def __read_txt_file(self, file_path): try: with open(file_path, 'r') as fd: data = fd.read() return data.strip() except IOError: - raise IOError("Unable to open %s file !" % file_path) + pass + return None def get_base_mac(self): """ @@ -136,14 +145,27 @@ def get_reboot_cause(self): self.component = Component("CPLD1") description = 'None' reboot_cause = self.REBOOT_CAUSE_HARDWARE_OTHER + + reboot_cause_path = (HOST_REBOOT_CAUSE_PATH + REBOOT_CAUSE_FILE) if self.__is_host( + ) else PMON_REBOOT_CAUSE_PATH + REBOOT_CAUSE_FILE + prev_reboot_cause_path = (HOST_REBOOT_CAUSE_PATH + PREV_REBOOT_CAUSE_FILE) if self.__is_host( + ) else PMON_REBOOT_CAUSE_PATH + PREV_REBOOT_CAUSE_FILE + hw_reboot_cause = self.component.get_register_value(RESET_REGISTER) - sw_reboot_cause = self.__read_txt_file(REBOOT_CAUSE_PATH) - if sw_reboot_cause != "Unexpected reboot": + sw_reboot_cause = self.__read_txt_file( + reboot_cause_path) or "Unknown" + prev_sw_reboot_cause = self.__read_txt_file( + prev_reboot_cause_path) or "Unknown" + + if sw_reboot_cause == "Unknown" and (prev_sw_reboot_cause == "Unknown" or prev_sw_reboot_cause == self.REBOOT_CAUSE_POWER_LOSS) and hw_reboot_cause == "0x11": + reboot_cause = self.REBOOT_CAUSE_POWER_LOSS + elif sw_reboot_cause != "Unknown" and hw_reboot_cause == "0x11": reboot_cause = self.REBOOT_CAUSE_NON_HARDWARE description = sw_reboot_cause - elif hw_reboot_cause == "0x11": - reboot_cause = self.REBOOT_CAUSE_POWER_LOSS + elif prev_reboot_cause_path != "Unknown" and hw_reboot_cause == "0x11": + reboot_cause = self.REBOOT_CAUSE_NON_HARDWARE + description = prev_sw_reboot_cause elif hw_reboot_cause == "0x22": reboot_cause = self.REBOOT_CAUSE_WATCHDOG, else: diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py index 99e86d0a6c64..86eda4cfbe11 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/fan.py @@ -17,7 +17,6 @@ except ImportError as e: raise ImportError(str(e) + "- required module not found") -CONFIG_DB_PATH = "/etc/sonic/config_db.json" EMC2305_PATH = "/sys/bus/i2c/drivers/emc2305/" SYS_GPIO_DIR = "/sys/class/gpio" EMC2305_MAX_PWM = 255 diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py index 6d019d7854ec..9275776e0ea8 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/sfp.py @@ -18,7 +18,7 @@ from swsssdk import ConfigDBConnector from sonic_platform_base.sfp_base import SfpBase from sonic_platform_base.sonic_sfp.sfputilbase import SfpUtilBase - from sonic_platform_base.sonic_sfp.sfputilbase import sff8436Dom + from sonic_platform_base.sonic_sfp.sff8436 import sff8436Dom except ImportError as e: raise ImportError(str(e) + "- required module not found") @@ -61,7 +61,11 @@ class Sfp(SfpBase, SfpUtilBase): RESET_PATH = "/sys/devices/platform/dx010_cpld/qsfp_reset" LP_PATH = "/sys/devices/platform/dx010_cpld/qsfp_lpmode" PRS_PATH = "/sys/devices/platform/dx010_cpld/qsfp_modprs" - PLATFORM_ROOT_PATH = '/usr/share/sonic/device' + PLATFORM_ROOT_PATH = "/usr/share/sonic/device" + PMON_HWSKU_PATH = "/usr/share/sonic/hwsku" + PLATFORM = "x86_64-cel_seastone-r0" + HWSKU = "Seastone-DX010" + HOST_CHK_CMD = "docker > /dev/null 2>&1" _port_to_eeprom_mapping = {} @@ -170,37 +174,28 @@ def __init__(self, sfp_index): (x - 1) + 26) else: self._port_to_eeprom_mapping[x] = eeprom_path.format(x + 26) - self.read_porttab_mappings(self.__get_path_to_port_config_file()) + + self.__read_porttab() SfpUtilBase.__init__(self) # Init index self.index = sfp_index self.port_num = self.index + 1 - def __get_path_to_port_config_file(self): - # Get platform and hwsku - machine_info = sonic_device_util.get_machine_info() - platform = sonic_device_util.get_platform_info(machine_info) - config_db = ConfigDBConnector() - config_db.connect() - data = config_db.get_table('DEVICE_METADATA') - + def __read_porttab(self): try: - hwsku = data['localhost']['hwsku'] - except KeyError: - hwsku = "Unknown" - - # Load platform module from source - platform_path = "/".join([self.PLATFORM_ROOT_PATH, platform]) - hwsku_path = "/".join([platform_path, hwsku]) + self.read_porttab_mappings(self.__get_path_to_port_config_file()) + except: + pass - # First check for the presence of the new 'port_config.ini' file - port_config_file_path = "/".join([hwsku_path, "port_config.ini"]) - if not os.path.isfile(port_config_file_path): - # port_config.ini doesn't exist. Try loading the legacy 'portmap.ini' file - port_config_file_path = "/".join([hwsku_path, "portmap.ini"]) + def __is_host(self): + return os.system(self.HOST_CHK_CMD) == 0 - return port_config_file_path + def __get_path_to_port_config_file(self): + platform_path = "/".join([self.PLATFORM_ROOT_PATH, self.PLATFORM]) + hwsku_path = "/".join([platform_path, self.HWSKU] + ) if self.__is_host() else self.PMON_HWSKU_PATH + return "/".join([hwsku_path, "port_config.ini"]) def __read_eeprom_specific_bytes(self, offset, num_bytes): sysfsfile_eeprom = None @@ -382,7 +377,7 @@ def get_rx_los(self): """ rx_los_list = [] dom_channel_monitor_raw = self.__read_eeprom_specific_bytes( - self.QSFP_CHANNL_RX_LOS_STATUS_OFFSET, self.QSFP_CHANNL_RX_LOS_STATUS_WIDTH) + self.QSFP_CHANNL_RX_LOS_STATUS_OFFSET, self.QSFP_CHANNL_RX_LOS_STATUS_WIDTH) if self.get_presence() else None if dom_channel_monitor_raw is not None: rx_los_data = int(dom_channel_monitor_raw[0], 16) rx_los_list.append(rx_los_data & 0x01 != 0) @@ -400,7 +395,7 @@ def get_tx_fault(self): """ tx_fault_list = [] dom_channel_monitor_raw = self.__read_eeprom_specific_bytes( - self.QSFP_CHANNL_TX_FAULT_STATUS_OFFSET, self.QSFP_CHANNL_TX_FAULT_STATUS_WIDTH) + self.QSFP_CHANNL_TX_FAULT_STATUS_OFFSET, self.QSFP_CHANNL_TX_FAULT_STATUS_WIDTH) if self.get_presence() else None if dom_channel_monitor_raw is not None: tx_fault_data = int(dom_channel_monitor_raw[0], 16) tx_fault_list.append(tx_fault_data & 0x01 != 0) @@ -422,7 +417,7 @@ def get_tx_disable(self): return False dom_control_raw = self.__read_eeprom_specific_bytes( - self.QSFP_CONTROL_OFFSET, self.QSFP_CONTROL_WIDTH) + self.QSFP_CONTROL_OFFSET, self.QSFP_CONTROL_WIDTH) if self.get_presence() else None if dom_control_raw is not None: dom_control_data = sfpd_obj.parse_control_bytes(dom_control_raw, 0) tx_disable_list.append( @@ -476,7 +471,7 @@ def get_power_override(self): return False dom_control_raw = self.__read_eeprom_specific_bytes( - self.QSFP_CONTROL_OFFSET, self.QSFP_CONTROL_WIDTH) + self.QSFP_CONTROL_OFFSET, self.QSFP_CONTROL_WIDTH) if self.get_presence() else None if dom_control_raw is not None: dom_control_data = sfpd_obj.parse_control_bytes(dom_control_raw, 0) power_override = ( @@ -515,7 +510,7 @@ def get_tx_bias(self): tx2_bs = transceiver_dom_info_dict.get("tx2bias", "N/A") tx3_bs = transceiver_dom_info_dict.get("tx3bias", "N/A") tx4_bs = transceiver_dom_info_dict.get("tx4bias", "N/A") - return [tx1_bs, tx2_bs, tx3_bs, tx4_bs] + return [tx1_bs, tx2_bs, tx3_bs, tx4_bs] if transceiver_dom_info_dict else [] def get_rx_power(self): """ @@ -530,7 +525,7 @@ def get_rx_power(self): rx2_pw = transceiver_dom_info_dict.get("rx2power", "N/A") rx3_pw = transceiver_dom_info_dict.get("rx3power", "N/A") rx4_pw = transceiver_dom_info_dict.get("rx4power", "N/A") - return [rx1_pw, rx2_pw, rx3_pw, rx4_pw] + return [rx1_pw, rx2_pw, rx3_pw, rx4_pw] if transceiver_dom_info_dict else [] def get_tx_power(self): """ @@ -545,7 +540,7 @@ def get_tx_power(self): tx2_pw = transceiver_dom_info_dict.get("tx2power", "N/A") tx3_pw = transceiver_dom_info_dict.get("tx3power", "N/A") tx4_pw = transceiver_dom_info_dict.get("tx4power", "N/A") - return [tx1_pw, tx2_pw, tx3_pw, tx4_pw] + return [tx1_pw, tx2_pw, tx3_pw, tx4_pw] if transceiver_dom_info_dict else [] def reset(self): """ @@ -754,7 +749,7 @@ def get_model(self): Returns: string: Model/part number of device """ - transceiver_dom_info_dict = self.get_transceiver_bulk_status() + transceiver_dom_info_dict = self.get_transceiver_info() return transceiver_dom_info_dict.get("modelname", "N/A") def get_serial(self): @@ -763,5 +758,5 @@ def get_serial(self): Returns: string: Serial number of device """ - transceiver_dom_info_dict = self.get_transceiver_bulk_status() + transceiver_dom_info_dict = self.get_transceiver_info() return transceiver_dom_info_dict.get("serialnum", "N/A") diff --git a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/thermal.py b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/thermal.py index 43390dce8302..1e0a2c4b5645 100644 --- a/device/celestica/x86_64-cel_seastone-r0/sonic_platform/thermal.py +++ b/device/celestica/x86_64-cel_seastone-r0/sonic_platform/thermal.py @@ -37,18 +37,16 @@ def __init__(self, thermal_index): # Set hwmon path i2c_path = { - 0: "i2c-5/5-0048", # u4 system-inlet - 1: "i2c-6/6-0049", # u2 system-inlet - 2: "i2c-7/7-004a", # u44 bmc56960-on-board - 3: "i2c-14/14-0048", # u9200 cpu-on-board - 4: "i2c-15/15-004e" # u9201 system-outlet + 0: "i2c-5/5-0048/hwmon/hwmon1", # u4 system-inlet + 1: "i2c-6/6-0049/hwmon/hwmon2", # u2 system-inlet + 2: "i2c-7/7-004a/hwmon/hwmon3", # u44 bmc56960-on-board + 3: "i2c-14/14-0048/hwmon/hwmon4", # u9200 cpu-on-board + 4: "i2c-15/15-004e/hwmon/hwmon5" # u9201 system-outlet }.get(self.index, None) - self.ss_path = "{}/{}/hwmon".format(self.I2C_ADAPTER_PATH, i2c_path) + self.hwmon_path = "{}/{}".format(self.I2C_ADAPTER_PATH, i2c_path) self.ss_key = self.THERMAL_NAME_LIST[self.index] self.ss_index = 1 - self.hwmon_name = os.listdir(self.ss_path)[0] - self.hwmon_path = os.path.join(self.ss_path, self.hwmon_name) def __read_txt_file(self, file_path): try: @@ -56,7 +54,7 @@ def __read_txt_file(self, file_path): data = fd.read() return data.strip() except IOError: - raise IOError("Unable to open %s file !" % file_path) + pass def __get_temp(self, temp_file): temp_file_path = os.path.join(self.hwmon_path, temp_file) diff --git a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.init b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.init index 99d0aab3fd61..1e124565a41d 100644 --- a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.init +++ b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.init @@ -141,6 +141,8 @@ start) sleep 0.1 done + /bin/sh /usr/local/bin/platform_api_mgnt.sh init + echo "done." ;; diff --git a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.install b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.install index b25d47022b08..8570fa1eae84 100644 --- a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.install +++ b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.install @@ -1,3 +1,5 @@ dx010/scripts/dx010_check_qsfp.sh usr/local/bin dx010/cfg/dx010-modules.conf etc/modules-load.d dx010/systemd/platform-modules-dx010.service lib/systemd/system +dx010/modules/sonic_platform-1.0-py2-none-any.whl usr/share/sonic/device/x86_64-cel_seastone-r0 +services/platform_api/platform_api_mgnt.sh usr/local/bin diff --git a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.postinst b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.postinst index baff704171c7..15243c935ca3 100644 --- a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.postinst +++ b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-dx010.postinst @@ -1,3 +1,6 @@ depmod -a systemctl enable platform-modules-dx010.service systemctl start platform-modules-dx010.service + +/usr/local/bin/platform_api_mgnt.sh install + diff --git a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.init b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.init index 6c2d4483ac9d..1dc0ea5cfeeb 100644 --- a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.init +++ b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.init @@ -69,6 +69,8 @@ start) echo "both" > /sys/devices/platform/e1031.smc/SFP/modabs_trig echo 0 > /sys/devices/platform/e1031.smc/SFP/modabs_mask + /bin/sh /usr/local/bin/platform_api_mgnt.sh init + echo "done." ;; diff --git a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.install b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.install index 312e9c78a5e7..df78b7a34ea4 100644 --- a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.install +++ b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.install @@ -3,3 +3,5 @@ haliburton/systemd/platform-modules-haliburton.service lib/systemd/system haliburton/script/fancontrol.sh etc/init.d services/fancontrol/fancontrol.service lib/systemd/system services/fancontrol/fancontrol usr/local/bin +haliburton/modules/sonic_platform-1.0-py2-none-any.whl usr/share/sonic/device/x86_64-cel_e1031-r0 +services/platform_api/platform_api_mgnt.sh usr/local/bin diff --git a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.postinst b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.postinst index ac05d40d702f..e62799bd591c 100644 --- a/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.postinst +++ b/platform/broadcom/sonic-platform-modules-cel/debian/platform-modules-haliburton.postinst @@ -3,4 +3,6 @@ systemctl enable platform-modules-haliburton.service systemctl enable fancontrol.service systemctl start platform-modules-haliburton.service -systemctl start fancontrol.service \ No newline at end of file +systemctl start fancontrol.service + +/usr/local/bin/platform_api_mgnt.sh install diff --git a/platform/broadcom/sonic-platform-modules-cel/debian/rules b/platform/broadcom/sonic-platform-modules-cel/debian/rules index 5086302b70b2..6f35290bce26 100755 --- a/platform/broadcom/sonic-platform-modules-cel/debian/rules +++ b/platform/broadcom/sonic-platform-modules-cel/debian/rules @@ -13,6 +13,9 @@ MODULE_DIRS:= dx010 haliburton override_dh_auto_build: (for mod in $(MODULE_DIRS); do \ make -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules; \ + cd $(MOD_SRC_DIR)/$${mod}; \ + python2.7 setup.py bdist_wheel -d $(MOD_SRC_DIR)/$${mod}/modules; \ + cd $(MOD_SRC_DIR); \ done) override_dh_auto_install: diff --git a/platform/broadcom/sonic-platform-modules-cel/dx010/setup.py b/platform/broadcom/sonic-platform-modules-cel/dx010/setup.py new file mode 100644 index 000000000000..8183788184a7 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-cel/dx010/setup.py @@ -0,0 +1,34 @@ +from setuptools import setup + +DEVICE_NAME = 'celestica' +HW_SKU = 'x86_64-cel_seastone-r0' + +setup( + name='sonic-platform', + version='1.0', + description='SONiC platform API implementation on Celestica Platforms', + license='Apache 2.0', + author='SONiC Team', + author_email='linuxnetdev@microsoft.com', + url='https://github.com/Azure/sonic-buildimage', + maintainer='Wirut Getbamrung', + maintainer_email='wgetbumr@celestica.com', + packages=[ + 'sonic_platform', + ], + package_dir={ + 'sonic_platform': '../../../../device/{}/{}/sonic_platform'.format(DEVICE_NAME, HW_SKU)}, + classifiers=[ + 'Development Status :: 3 - Alpha', + 'Environment :: Plugins', + 'Intended Audience :: Developers', + 'Intended Audience :: Information Technology', + 'Intended Audience :: System Administrators', + 'License :: OSI Approved :: Apache Software License', + 'Natural Language :: English', + 'Operating System :: POSIX :: Linux', + 'Programming Language :: Python :: 2.7', + 'Topic :: Utilities', + ], + keywords='sonic SONiC platform PLATFORM', +) diff --git a/platform/broadcom/sonic-platform-modules-cel/haliburton/setup.py b/platform/broadcom/sonic-platform-modules-cel/haliburton/setup.py new file mode 100644 index 000000000000..17056855106e --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-cel/haliburton/setup.py @@ -0,0 +1,34 @@ +from setuptools import setup + +DEVICE_NAME = 'celestica' +HW_SKU = 'x86_64-cel_e1031-r0' + +setup( + name='sonic-platform', + version='1.0', + description='SONiC platform API implementation on Celestica Platforms', + license='Apache 2.0', + author='SONiC Team', + author_email='linuxnetdev@microsoft.com', + url='https://github.com/Azure/sonic-buildimage', + maintainer='Wirut Getbamrung', + maintainer_email='wgetbumr@celestica.com', + packages=[ + 'sonic_platform', + ], + package_dir={ + 'sonic_platform': '../../../../device/{}/{}/sonic_platform'.format(DEVICE_NAME, HW_SKU)}, + classifiers=[ + 'Development Status :: 3 - Alpha', + 'Environment :: Plugins', + 'Intended Audience :: Developers', + 'Intended Audience :: Information Technology', + 'Intended Audience :: System Administrators', + 'License :: OSI Approved :: Apache Software License', + 'Natural Language :: English', + 'Operating System :: POSIX :: Linux', + 'Programming Language :: Python :: 2.7', + 'Topic :: Utilities', + ], + keywords='sonic SONiC platform PLATFORM', +) diff --git a/platform/broadcom/sonic-platform-modules-cel/services/platform_api/platform_api_mgnt.sh b/platform/broadcom/sonic-platform-modules-cel/services/platform_api/platform_api_mgnt.sh new file mode 100755 index 000000000000..e1d330357894 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-cel/services/platform_api/platform_api_mgnt.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +PREV_REBOOT_CAUSE="/host/reboot-cause/" +DEVICE="/usr/share/sonic/device" +PLATFORM=$(/usr/local/bin/sonic-cfggen -H -v DEVICE_METADATA.localhost.platform) +FILES=$DEVICE/$PLATFORM/api_files + +install() { + # Install sonic-platform package + if [ -e $DEVICE/$PLATFORM/sonic_platform-1.0-py2-none-any.whl ]; then + pip install $DEVICE/$PLATFORM/sonic_platform-1.0-py2-none-any.whl + fi +} + +init() { + # mount needed files for sonic-platform package + mkdir -p $FILES + + mkdir -p $FILES/reboot-cause + mount -B $PREV_REBOOT_CAUSE $FILES/reboot-cause +} + +deinit() { + # deinit sonic-platform package + umount -f $PREV_REBOOT_CAUSE $FILES/reboot-cause >/dev/null 2>/dev/null +} + +uninstall() { + # Uninstall sonic-platform package + pip uninstall -y sonic-platform >/dev/null 2>/dev/null +} + +case "$1" in +install | uninstall | init | deinit) + $1 + ;; +*) + echo "Usage: $0 {install|uninstall|init|deinit}" + exit 1 + ;; +esac