Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[device/celestica]: Fix failed test cases of Haliburton platform APIs #253

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
758 changes: 758 additions & 0 deletions device/celestica/x86_64-cel_e1031-r0/platform.json

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions device/celestica/x86_64-cel_e1031-r0/platform_components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"chassis": {
"E1031": {
"component": {
"BIOS": {},
"SMC_CPLD": {},
"MMC_CPLD": {}
}
}
}
}
112 changes: 79 additions & 33 deletions device/celestica/x86_64-cel_e1031-r0/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,92 +6,90 @@
#
#############################################################################


try:
import sys
from sonic_platform_base.sonic_sfp.sfputilhelper import SfpUtilHelper
from sonic_platform_base.chassis_base import ChassisBase
from sonic_py_common import device_info
from .common import Common
from .event import SfpEvent
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

NUM_FAN_TRAY = 3
NUM_FAN = 1
NUM_PSU = 2
NUM_THERMAL = 7
NUM_SFP = 52
NUM_SFP = 55
NUM_COMPONENT = 3
RESET_REGISTER = "0x112"
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"
HOST_CHK_CMD = "docker > /dev/null 2>&1"
STATUS_LED_PATH = "/sys/devices/platform/e1031.smc/master_led"


class Chassis(ChassisBase):
"""Platform-specific Chassis class"""

def __init__(self):
ChassisBase.__init__(self)

self._api_common = Common()
self.sfp_module_initialized = False
self.__initialize_eeprom()
self.is_host = self._api_common.is_host()
self._is_host = self._api_common.is_host()

if not self.is_host:
self.__initialize_fan()
self.__initialize_psu()
self.__initialize_thermals()
else:
self.__initialize_components()
self.__initialize_eeprom()
self.__initialize_fan()
self.__initialize_psu()
self.__initialize_thermals()
self.__initialize_components()

self._reboot_cause_path = HOST_REBOOT_CAUSE_PATH if self.__is_host(
) else PMON_REBOOT_CAUSE_PATH
self.sfp_module_initialized = False
self._reboot_cause_path = HOST_REBOOT_CAUSE_PATH if self._is_host else PMON_REBOOT_CAUSE_PATH

def __initialize_sfp(self):
sfputil_helper = SfpUtilHelper()
port_config_file_path = device_info.get_path_to_port_config_file()
sfputil_helper.read_porttab_mappings(port_config_file_path, 0)

from sonic_platform.sfp import Sfp
from .sfp import Sfp
for index in range(0, NUM_SFP):
name_idx = 0 if index+1 == NUM_SFP else index+1
sfp = Sfp(index, sfputil_helper.logical[name_idx])
sfp = Sfp(index, sfputil_helper.logical[index])
self._sfp_list.append(sfp)
self.sfp_module_initialized = True

def __initialize_psu(self):
from sonic_platform.psu import Psu
from .psu import Psu
for index in range(0, NUM_PSU):
psu = Psu(index)
self._psu_list.append(psu)

def __initialize_fan(self):
from sonic_platform.fan import Fan
for fant_index in range(0, NUM_FAN_TRAY):
for fan_index in range(0, NUM_FAN):
fan = Fan(fant_index, fan_index)
self._fan_list.append(fan)
from .fan_drawer import FanDrawer
for i in range(NUM_FAN_TRAY):
fandrawer = FanDrawer(i)
self._fan_drawer_list.append(fandrawer)
self._fan_list += fandrawer.get_all_fans()

def __initialize_thermals(self):
from sonic_platform.thermal import Thermal
from .thermal import Thermal
airflow = self.__get_air_flow()
for index in range(0, NUM_THERMAL):
thermal = Thermal(index, airflow)
self._thermal_list.append(thermal)

def __initialize_eeprom(self):
from sonic_platform.eeprom import Tlv
from .eeprom import Tlv
self._eeprom = Tlv()

def __initialize_components(self):
from sonic_platform.component import Component
from .component import Component
for index in range(0, NUM_COMPONENT):
component = Component(index)
self._component_list.append(component)

def __get_air_flow(self):
air_flow_path = '/usr/share/sonic/device/{}/fan_airflow'.format(
self._api_common.platform) if self.is_host else '/usr/share/sonic/platform/fan_airflow'
self._api_common.get_platform()) if self._is_host else '/usr/share/sonic/platform/fan_airflow'
air_flow = self._api_common.read_txt_file(air_flow_path)
return air_flow or 'B2F'

Expand Down Expand Up @@ -154,7 +152,6 @@ def get_reboot_cause(self):
else:
reboot_cause = self.REBOOT_CAUSE_NON_HARDWARE
description = 'Unknown reason'

return (reboot_cause, description)

def get_watchdog(self):
Expand Down Expand Up @@ -247,8 +244,8 @@ def get_sfp(self, index):
# The index will start from 1
sfp = self._sfp_list[index-1]
except IndexError:
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
index, len(self._sfp_list)))
print("SFP index {} out of range (1-{})\n".format(
index, len(self._sfp_list)))
return sfp

##############################################################
Expand All @@ -269,13 +266,13 @@ def get_name(self):
Returns:
string: The name of the device
"""
return self._api_common.hwsku
return self._api_common.get_hwsku()

def get_presence(self):
"""
Retrieves the presence of the PSU
Retrieves the presence of the Chassis
Returns:
bool: True if PSU is present, False if not
bool: True if Chassis is present, False if not
"""
return True

Expand Down Expand Up @@ -303,3 +300,52 @@ def get_status(self):
"""
return True

def get_position_in_parent(self):
"""
Retrieves 1-based relative physical position in parent device. If the agent cannot determine the parent-relative position
for some reason, or if the associated value of entPhysicalContainedIn is '0', then the value '-1' is returned
Returns:
integer: The 1-based relative physical position in parent device or -1 if cannot determine the position
"""
return -1

def is_replaceable(self):
"""
Indicate whether this device is replaceable.
Returns:
bool: True if it is replaceable.
"""
return False

def set_status_led(self, color):
"""
Sets the state of the PSU status LED
Args:
color: A string representing the color with which to set the PSU status LED
Note: Only support green and off
Returns:
bool: True if status LED state is set successfully, False if not
"""

status_str = {
self.STATUS_LED_COLOR_GREEN: 'green',
self.STATUS_LED_COLOR_AMBER: 'amber',
self.STATUS_LED_COLOR_OFF: 'off'
}.get(color, 'off')

return self._api_common.write_txt_file(STATUS_LED_PATH, status_str)

def get_status_led(self):
"""
Gets the state of the PSU status LED
Returns:
A string, one of the predefined STATUS_LED_COLOR_* strings above
"""
status = self._api_common.read_txt_file(STATUS_LED_PATH)
status_str = {
'on': self.STATUS_LED_COLOR_GREEN,
'amber': self.STATUS_LED_COLOR_AMBER,
'off': self.STATUS_LED_COLOR_OFF
}.get(status, None)

return status_str
39 changes: 34 additions & 5 deletions device/celestica/x86_64-cel_e1031-r0/sonic_platform/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@ class Common:

def __init__(self, conf=None):
self._main_conf = conf
(self.platform, self.hwsku) = device_info.get_platform_and_hwsku()
self.platform = None
self.hwsku = None

def get_platform(self):
(self.platform, self.hwsku) = device_info.get_platform_and_hwsku(
) if not self.platform else (self.platform, self.hwsku)
return self.platform

def get_hwsku(self):
(self.platform, self.hwsku) = device_info.get_platform_and_hwsku(
) if not self.hwsku else (self.platform, self.hwsku)
return self.hwsku

def run_command(self, command):
status = False
Expand All @@ -38,7 +49,7 @@ def run_command(self, command):
p = subprocess.Popen(
command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()
if err == '':
if p.returncode == 0:
status, output = True, raw_data.strip()
except Exception:
pass
Expand Down Expand Up @@ -152,10 +163,28 @@ def get_reg(self, path, reg_addr):
status, output = self.run_command(cmd)
return output if status else None

def set_reg(self, path, reg_addr, value):
cmd = "echo {0} {1} > {2}".format(reg_addr, value, path)
status, output = self.run_command(cmd)
return output if status else None

def read_txt_file(self, path):
with open(path, 'r') as f:
output = f.readline()
return output.strip('\n')
try:
with open(path, 'r') as f:
output = f.readline()
return output.strip('\n')
except Exception:
pass
return ''

def read_one_line_file(self, file_path):
try:
with open(file_path, 'r') as fd:
data = fd.readline()
return data.strip()
except IOError:
pass
return ''

def write_txt_file(self, file_path, value):
try:
Expand Down
Loading