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

support new platform api, thermal and sfp part #1

Closed
wants to merge 2 commits into from
Closed
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
18 changes: 14 additions & 4 deletions platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from sonic_platform.fan import Fan
from sonic_platform.fan import FAN_PATH
from sonic_platform.sfp import SFP
from sonic_platform.thermal import Thermal, initialize_thermals
from sonic_platform.watchdog import get_watchdog
from sonic_daemon_base.daemon_base import Logger
from eeprom import Eeprom
Expand Down Expand Up @@ -69,7 +70,7 @@

# magic code defnition for port number, qsfp port position of each hwsku
# port_position_tuple = (PORT_START, QSFP_PORT_START, PORT_END, PORT_IN_BLOCK, EEPROM_OFFSET)
hwsku_dict = {'ACS-MSN2700': 0, "LS-SN2700":0, 'ACS-MSN2740': 0, 'ACS-MSN2100': 1, 'ACS-MSN2410': 2, 'ACS-MSN2010': 3, 'ACS-MSN3700': 0, 'ACS-MSN3700C': 0, 'Mellanox-SN2700': 0, 'Mellanox-SN2700-D48C8': 0}
hwsku_dict_port = {'ACS-MSN2700': 0, "LS-SN2700":0, 'ACS-MSN2740': 0, 'ACS-MSN2100': 1, 'ACS-MSN2410': 2, 'ACS-MSN2010': 3, 'ACS-MSN3700': 0, 'ACS-MSN3700C': 0, 'Mellanox-SN2700': 0, 'Mellanox-SN2700-D48C8': 0}
port_position_tuple_list = [(0, 0, 31, 32, 1), (0, 0, 15, 16, 1), (0, 48, 55, 56, 1),(0, 18, 21, 22, 1)]

class Chassis(ChassisBase):
Expand Down Expand Up @@ -98,8 +99,11 @@ def __init__(self):
fan = Fan(index, index)
self._fan_list.append(fan)

# Initialize SKU name
self.sku = self._get_sku_name()

# Initialize SFP list
port_position_tuple = self._get_port_position_tuple_by_sku_name()
port_position_tuple = self._get_port_position_tuple_by_sku_name(self.sku)
self.PORT_START = port_position_tuple[0]
self.QSFP_PORT_START = port_position_tuple[1]
self.PORT_END = port_position_tuple[2]
Expand All @@ -112,6 +116,9 @@ def __init__(self):
sfp_module = SFP(index, 'SFP')
self._sfp_list.append(sfp_module)

# Initialize thermals
initialize_thermals(self.sku, self._thermal_list, self._psu_list)

# Initialize EEPROM
self.eeprom = Eeprom()

Expand All @@ -137,10 +144,13 @@ def _extract_num_of_fans_and_fan_drawers(self):

return num_of_fan, num_of_drawer

def _get_port_position_tuple_by_sku_name(self):
def _get_sku_name(self):
p = subprocess.Popen(GET_HWSKU_CMD, shell=True, stdout=subprocess.PIPE)
out, err = p.communicate()
position_tuple = port_position_tuple_list[hwsku_dict[out.rstrip('\n')]]
return out.rstrip('\n')

def _get_port_position_tuple_by_sku_name(self, sku):
position_tuple = port_position_tuple_list[hwsku_dict_port[self.sku]]
return position_tuple

def get_base_mac(self):
Expand Down
105 changes: 83 additions & 22 deletions platform/mellanox/mlnx-platform-api/sonic_platform/psu.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@

try:
from sonic_platform_base.psu_base import PsuBase
from sonic_daemon_base.daemon_base import Logger
from sonic_platform.fan import Fan
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

# Global logger class instance
SYSLOG_IDENTIFIER = "mlnx-psu"
logger = Logger(SYSLOG_IDENTIFIER)

psu_list = []

class Psu(PsuBase):
Expand All @@ -26,30 +31,53 @@ def __init__(self, psu_index):
# PSU is 1-based on Mellanox platform
self.index = psu_index + 1
psu_list.append(self.index)
self.psu_path = "/var/run/hw-management/thermal/"
self.psu_oper_status = "psu{}_pwr_status".format(self.index)
self.psu_presence = "psu{}_status".format(self.index)
if os.path.exists(os.path.join(self.psu_path, self.psu_presence)):
self.presence_file_exists = True
self.psu_path = "/var/run/hw-management/"
self.psu_oper_status = "thermal/psu{}_pwr_status".format(self.index)
psu_voltage = "power/psu{}_volt".format(self.index)
if os.path.exists(os.path.join(self.psu_path, psu_voltage)):
self.psu_voltage = psu_voltage
else:
self.psu_voltage = None
psu_curr = "power/psu{}_curr".format(self.index)
if os.path.exists(os.path.join(self.psu_path, psu_curr)):
self.psu_current = psu_curr
else:
self.psu_current = None
psu_power = "power/psu{}_power".format(self.index)
if os.path.exists(os.path.join(self.psu_path, psu_power)):
self.psu_power = psu_power
else:
self.psu_power = None
psu_presence = "thermal/psu{}_status".format(self.index)
if os.path.exists(os.path.join(self.psu_path, psu_presence)):
self.psu_presence = psu_presence
else:
self.presence_file_exists = False
self.psu_presence = None
fan = Fan(psu_index, psu_index, True)
if fan.get_presence():
self._fan = fan

def get_status(self):
def _read_generic_file(self, filename, len):
"""
Read a generic file, returns the contents of the file
"""
result = 0
try:
with open(filename, 'r') as fileobj:
result = int(fileobj.read())
except:
logger.log_info("Fail to read file {}, maybe it doesn't exist".format(filename))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest rewording it, "file {} doesn't exist."

result = 0
return result

def get_powergood_status(self):
"""
Retrieves the operational status of power supply unit (PSU) defined

Returns:
bool: True if PSU is operating properly, False if not
"""
status = 0
try:
with open(os.path.join(self.psu_path, self.psu_oper_status), 'r') as power_status:
status = int(power_status.read())
except (ValueError, IOError):
status = 0
status = self._read_generic_file(os.path.join(self.psu_path, self.psu_oper_status), 0)

return status == 1

Expand All @@ -60,15 +88,48 @@ def get_presence(self):
Returns:
bool: True if PSU is present, False if not
"""
status = 0
if self.presence_file_exists:
try:
with open(os.path.join(self.psu_path, self.psu_presence), 'r') as presence_status:
status = int(presence_status.read())
except (ValueError, IOError):
status = 0
if self.psu_presence is not None:
status = self._read_generic_file(os.path.join(self.psu_path, self.psu_presence), 0)
return status == 1
else:
status = self.index in psu_list
return True

return status == 1
def get_voltage(self):
"""
Retrieves current PSU voltage output

Returns:
A float number, the output voltage in volts,
e.g. 12.1
"""
if self.psu_voltage is not None:
voltage = self._read_generic_file(os.path.join(self.psu_path, self.psu_voltage), 0)
return float(voltage) / 1000
else:
return None

def get_current(self):
"""
Retrieves present electric current supplied by PSU

Returns:
A float number, the electric current in amperes, e.g 15.4
"""
if self.psu_current is not None:
amperes = self._read_generic_file(os.path.join(self.psu_path, self.psu_current), 0)
return float(amperes) / 1000
else:
return None

def get_power(self):
"""
Retrieves current energy supplied by PSU

Returns:
A float number, the power in watts, e.g. 302.6
"""
if self.psu_power is not None:
power = self._read_generic_file(os.path.join(self.psu_path, self.psu_power), 0)
return float(power) / 1000000
else:
return None
Loading