Skip to content

Commit

Permalink
fix review comments from review meeting
Browse files Browse the repository at this point in the history
  • Loading branch information
Junchao-Mellanox committed Apr 15, 2020
1 parent 9a1c052 commit ae23ba9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 137 deletions.
12 changes: 10 additions & 2 deletions platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
MLNX_NUM_PSU = 2

GET_HWSKU_CMD = "sonic-cfggen -d -v DEVICE_METADATA.localhost.hwsku"
GET_PLATFORM_CMD = "sonic-cfggen -d -v DEVICE_METADATA.localhost.platform"

EEPROM_CACHE_ROOT = '/var/cache/sonic/decode-syseeprom'
EEPROM_CACHE_FILE = 'syseeprom_cache'
Expand Down Expand Up @@ -59,6 +60,7 @@ def __init__(self):

# Initialize SKU name
self.sku_name = self._get_sku_name()
self.platform_name = self._get_platform_name()
mi = get_machine_info()
if mi is not None:
self.name = mi['onie_platform']
Expand All @@ -83,7 +85,7 @@ def initialize_psu(self):
# Initialize PSU list
self.psu_module = Psu
for index in range(MLNX_NUM_PSU):
psu = Psu(index, self.sku_name)
psu = Psu(index, self.platform_name)
self._psu_list.append(psu)


Expand All @@ -92,7 +94,7 @@ def initialize_fan(self):
from sonic_platform.fan import Fan
from .fan_drawer import RealDrawer, VirtualDrawer

fan_data = DEVICE_DATA[self.sku_name]['fans']
fan_data = DEVICE_DATA[self.platform_name]['fans']
drawer_num = fan_data['drawer_num']
drawer_type = fan_data['drawer_type']
fan_num_per_drawer = fan_data['fan_num_per_drawer']
Expand Down Expand Up @@ -237,6 +239,12 @@ def _get_sku_name(self):
return out.rstrip('\n')


def _get_platform_name(self):
p = subprocess.Popen(GET_PLATFORM_CMD, shell=True, stdout=subprocess.PIPE)
out, err = p.communicate()
return out.rstrip('\n')


def _get_port_position_tuple_by_sku_name(self):
position_tuple = port_position_tuple_list[hwsku_dict_port[self.sku_name]]
return position_tuple
Expand Down
147 changes: 31 additions & 116 deletions platform/mellanox/mlnx-platform-api/sonic_platform/device_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DEVICE_DATA = {
'ACS-MSN2700': {
'x86_64-mlnx_msn2700-r0': {
'thermal': {
'minimum_table': {
"p2c_trust": {"-127:40":13, "41:120":15},
Expand All @@ -24,32 +24,7 @@
'led_num': 1
}
},
'LS-SN2700': {
'thermal': {
'minimum_table': {
"p2c_trust": {"-127:40":13, "41:120":15},
"p2c_untrust": {"-127:25":13, "26:30":14 , "31:35":15, "36:120":16},
"c2p_trust": {"-127:20":13, "21:25":14 , "26:30":15, "31:120":16},
"c2p_untrust": {"-127:20":13, "21:25":14 , "26:30":15, "31:120":16},
"unk_trust": {"-127:20":13, "21:25":14 , "26:30":15, "31:120":16},
"unk_untrust": {"-127:20":13, "21:25":14 , "26:30":15, "31:120":16}
}
},
'fans': {
'drawer_num': 4,
'drawer_type': 'real',
'fan_num_per_drawer': 2,
'support_fan_direction': False,
'hot_swappable': True
},
'psus': {
'psu_num': 2,
'fan_num_per_psu': 1,
'hot_swappable': True,
'led_num': 1
}
},
'ACS-MSN2740': {
'x86_64-mlnx_msn2740-r0': {
'thermal': {
'minimum_table': {
"p2c_trust": {"-127:120":13},
Expand All @@ -74,57 +49,32 @@
'led_num': 1
}
},
'ACS-MSN2410': {
'x86_64-mlnx_msn2100-r0': {
'thermal': {
'minimum_table': {
"p2c_trust": {"-127:40":13, "41:120":15},
"p2c_untrust": {"-127:25":13, "26:30":14 , "31:35":15, "36:120":16},
"c2p_trust": {"-127:20":13, "21:25":14 , "26:30":15, "31:120":16},
"c2p_untrust": {"-127:20":13, "21:25":14 , "26:30":15, "31:120":16},
"unk_trust": {"-127:20":13, "21:25":14 , "26:30":15, "31:120":16},
"unk_untrust": {"-127:20":13, "21:25":14 , "26:30":15, "31:120":16}
}
},
'fans': {
'drawer_num': 4,
'drawer_type': 'real',
'fan_num_per_drawer': 2,
'support_fan_direction': False,
'hot_swappable': True
},
'psus': {
'psu_num': 2,
'fan_num_per_psu': 1,
'hot_swappable': True,
'led_num': 1
}
},
'Mellanox-SN2700': {
'thermal': {
'minimum_table': {
"p2c_trust": {"-127:40":13, "41:120":15},
"p2c_untrust": {"-127:25":13, "26:30":14 , "31:35":15, "36:120":16},
"c2p_trust": {"-127:20":13, "21:25":14 , "26:30":15, "31:120":16},
"c2p_untrust": {"-127:20":13, "21:25":14 , "26:30":15, "31:120":16},
"unk_trust": {"-127:20":13, "21:25":14 , "26:30":15, "31:120":16},
"unk_untrust": {"-127:20":13, "21:25":14 , "26:30":15, "31:120":16}
"p2c_trust": {"-127:120":12},
"p2c_untrust": {"-127:15":12, "16:25":13, "26:30":14, "31:35":15, "36:120":16},
"c2p_trust": {"-127:40":12, "41:120":13},
"c2p_untrust": {"-127:40":12, "41:120":13},
"unk_trust": {"-127:40":12, "41:120":13},
"unk_untrust": {"-127:15":12, "16:25":13, "26:30":14, "31:35":15, "36:120":16}
}
},
'fans': {
'drawer_num': 4,
'drawer_type': 'real',
'fan_num_per_drawer': 2,
'drawer_num': 1,
'drawer_type': 'virtual',
'fan_num_per_drawer': 4,
'support_fan_direction': False,
'hot_swappable': True
'hot_swappable': False
},
'psus': {
'psu_num': 2,
'fan_num_per_psu': 1,
'hot_swappable': True,
'led_num': 1
'hot_swappable': False,
'led_num': 2
}
},
'Mellanox-SN2700-D48C8': {
'x86_64-mlnx_msn2410-r0': {
'thermal': {
'minimum_table': {
"p2c_trust": {"-127:40":13, "41:120":15},
Expand All @@ -149,32 +99,7 @@
'led_num': 1
}
},
'ACS-MSN2100': {
'thermal': {
'minimum_table': {
"p2c_trust": {"-127:120":12},
"p2c_untrust": {"-127:15":12, "16:25":13, "26:30":14, "31:35":15, "36:120":16},
"c2p_trust": {"-127:40":12, "41:120":13},
"c2p_untrust": {"-127:40":12, "41:120":13},
"unk_trust": {"-127:40":12, "41:120":13},
"unk_untrust": {"-127:15":12, "16:25":13, "26:30":14, "31:35":15, "36:120":16}
}
},
'fans': {
'drawer_num': 1,
'drawer_type': 'virtual',
'fan_num_per_drawer': 4,
'support_fan_direction': False,
'hot_swappable': False
},
'psus': {
'psu_num': 2,
'fan_num_per_psu': 1,
'hot_swappable': False,
'led_num': 2
}
},
'ACS-MSN2010': {
'x86_64-mlnx_msn2010-r0': {
'thermal': {
'minimum_table': {
"p2c_trust": {"-127:120":12},
Expand All @@ -199,7 +124,7 @@
'led_num': 2
}
},
'ACS-MSN3700': {
'x86_64-mlnx_msn3700-r0': {
'thermal': {
'minimum_table': {
"p2c_trust": {"-127:25":12, "26:40":13 , "41:120":14},
Expand All @@ -224,21 +149,21 @@
'led_num': 1
}
},
'ACS-MSN3800': {
'x86_64-mlnx_msn3700c-r0': {
'thermal': {
'minimum_table': {
"p2c_trust": {"-127:35":12, "36:120":13},
"p2c_untrust": {"-127:0":12, "1:10":13 , "11:15":14, "16:20":15, "21:35":16, "36:120":17},
"c2p_trust": {"-127:30":12, "31:40":13 , "41:120":14},
"c2p_untrust": {"-127:20":12, "21:30":13 , "31:35":14, "36:40":15, "41:120":16},
"unk_trust": {"-127:30":12, "31:40":13 , "41:120":14},
"unk_untrust": {"-127:0":12, "1:10":13 , "11:15":14, "16:20":15, "21:35":16, "36:120":17},
"p2c_trust": {"-127:25":12, "26:40":13 , "41:120":14},
"p2c_untrust": {"-127:15":12, "16:30":13 , "31:35":14, "36:40":15, "41:120":16},
"c2p_trust": {"-127:25":12, "26:40":13 , "41:120":14},
"c2p_untrust": {"-127:25":12, "26:40":13 , "41:120":14},
"unk_trust": {"-127:25":12, "26:40":13 , "41:120":14},
"unk_untrust": {"-127:15":12, "16:30":13 , "31:35":14, "36:40":15, "41:120":16},
}
},
'fans': {
'drawer_num': 3,
'drawer_num': 4,
'drawer_type': 'real',
'fan_num_per_drawer': 1,
'fan_num_per_drawer': 2,
'support_fan_direction': True,
'hot_swappable': True
},
Expand All @@ -249,7 +174,7 @@
'led_num': 1
}
},
'Mellanox-SN3800-D112C8': {
'x86_64-mlnx_msn3800-r0': {
'thermal': {
'minimum_table': {
"p2c_trust": {"-127:35":12, "36:120":13},
Expand All @@ -274,19 +199,9 @@
'led_num': 1
}
},
'ACS-MSN3700C': {
'thermal': {
'minimum_table': {
"p2c_trust": {"-127:25":12, "26:40":13 , "41:120":14},
"p2c_untrust": {"-127:15":12, "16:30":13 , "31:35":14, "36:40":15, "41:120":16},
"c2p_trust": {"-127:25":12, "26:40":13 , "41:120":14},
"c2p_untrust": {"-127:25":12, "26:40":13 , "41:120":14},
"unk_trust": {"-127:25":12, "26:40":13 , "41:120":14},
"unk_untrust": {"-127:15":12, "16:30":13 , "31:35":14, "36:40":15, "41:120":16},
}
},
'x86_64-mlnx_msn4700-r0': {
'fans': {
'drawer_num': 4,
'drawer_num': 6,
'drawer_type': 'real',
'fan_num_per_drawer': 2,
'support_fan_direction': True,
Expand All @@ -298,5 +213,5 @@
'hot_swappable': True,
'led_num': 1
}
},
}
}
6 changes: 3 additions & 3 deletions platform/mellanox/mlnx-platform-api/sonic_platform/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

try:
from sonic_platform_base.fan_base import FanBase
from .led import FanLed, VirtualLed
from .led import FanLed, ComponentFaultyIndicator
except ImportError as e:
raise ImportError (str(e) + "- required module not found")

Expand All @@ -34,10 +34,10 @@ def __init__(self, fan_index, fan_drawer, psu_fan = False):

self.is_psu_fan = psu_fan
if self.fan_drawer:
self.led = VirtualLed(self.fan_drawer.get_led())
self.led = ComponentFaultyIndicator(self.fan_drawer.get_led())
elif self.is_psu_fan:
from .psu import Psu
self.led = VirtualLed(Psu.get_shared_led())
self.led = ComponentFaultyIndicator(Psu.get_shared_led())
else:
self.led = FanLed(self.index)

Expand Down
2 changes: 1 addition & 1 deletion platform/mellanox/mlnx-platform-api/sonic_platform/led.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def get_status(self):
return self._led.get_status()


class VirtualLed(object):
class ComponentFaultyIndicator(object):
def __init__(self, shared_led):
self._color = Led.STATUS_LED_COLOR_GREEN
self._shared_led = shared_led
Expand Down
26 changes: 13 additions & 13 deletions platform/mellanox/mlnx-platform-api/sonic_platform/psu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sonic_platform_base.psu_base import PsuBase
from sonic_daemon_base.daemon_base import Logger
from sonic_platform.fan import Fan
from .led import PsuLed, SharedLed, VirtualLed
from .led import PsuLed, SharedLed, ComponentFaultyIndicator
from .device_data import DEVICE_DATA
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
Expand All @@ -28,9 +28,9 @@
PSU_VOLTAGE = "voltage"
PSU_POWER = "power"

# in most SKUs the file psuX_curr, psuX_volt and psuX_power contain current, voltage and power data respectively.
# in most platforms the file psuX_curr, psuX_volt and psuX_power contain current, voltage and power data respectively.
# but there are exceptions which will be handled by the following dictionary
hwsku_dict_psu = {'ACS-MSN3700': 1, 'ACS-MSN3700C': 1, 'ACS-MSN3800': 1, 'Mellanox-SN3800-D112C8': 1, 'ACS-MSN4700': 1}
platform_dict_psu = {'x86_64-mlnx_msn3700-r0': 1, 'x86_64-mlnx_msn3700c-r0': 1, 'x86_64-mlnx_msn3800-r0': 1, 'x86_64-mlnx_msn4700-r0': 1}
psu_profile_list = [
# default filename convention
{
Expand All @@ -51,33 +51,33 @@ class Psu(PsuBase):

shared_led = None

def __init__(self, psu_index, sku):
def __init__(self, psu_index, platform):
global psu_list
PsuBase.__init__(self)
# PSU is 1-based on Mellanox platform
self.index = psu_index + 1
psu_list.append(self.index)
self.psu_path = "/var/run/hw-management/"
psu_oper_status = "thermal/psu{}_pwr_status".format(self.index)
#psu_oper_status should always be present for all SKUs
#psu_oper_status should always be present for all platforms
self.psu_oper_status = os.path.join(self.psu_path, psu_oper_status)
self._name = "PSU{}".format(psu_index + 1)

if sku in hwsku_dict_psu:
filemap = psu_profile_list[hwsku_dict_psu[sku]]
if platform in platform_dict_psu:
filemap = psu_profile_list[platform_dict_psu[platform]]
else:
filemap = psu_profile_list[0]

self.psu_data = DEVICE_DATA[sku]['psus']
self.psu_data = DEVICE_DATA[platform]['psus']

if not self.psu_data['hot_swappable']:
self.always_presence = True
self.always_present = True
self.psu_voltage = None
self.psu_current = None
self.psu_power = None
self.psu_presence = None
else:
self.always_presence = False
self.always_present = False
psu_voltage = filemap[PSU_VOLTAGE].format(self.index)
psu_voltage = os.path.join(self.psu_path, psu_voltage)
self.psu_voltage = psu_voltage
Expand All @@ -100,7 +100,7 @@ def __init__(self, psu_index, sku):
self._fan_list.append(fan)

if self.psu_data['led_num'] == 1:
self.led = VirtualLed(Psu.get_shared_led())
self.led = ComponentFaultyIndicator(Psu.get_shared_led())
else: # 2010/2100
self.led = PsuLed(self.index)

Expand Down Expand Up @@ -141,8 +141,8 @@ def get_presence(self):
Returns:
bool: True if PSU is present, False if not
"""
if self.always_presence:
return self.always_presence
if self.always_present:
return self.always_present
else:
status = self._read_generic_file(self.psu_presence, 0)
return status == 1
Expand Down
Loading

0 comments on commit ae23ba9

Please sign in to comment.