Skip to content

Commit

Permalink
Changed HW Revision to be parsed from vpd_data instead of SMBIOS/DMI …
Browse files Browse the repository at this point in the history
…type 2 info
  • Loading branch information
skr31 committed May 19, 2024
1 parent 1b0e407 commit f6496fc
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 19 deletions.
30 changes: 16 additions & 14 deletions platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@

RJ45_TYPE = "RJ45"

VPD_DATA_FILE = "/var/run/hw-management/eeprom/vpd_data"
REVISION = "REV"

DMI_FILE = '/sys/firmware/dmi/entries/2-0/raw'
DMI_HEADER_LEN = 15
DMI_PRODUCT_NAME = "Product Name"
Expand Down Expand Up @@ -87,8 +90,8 @@ class Chassis(ChassisBase):
def __init__(self):
super(Chassis, self).__init__()

# Initialize DMI data
self.dmi_data = None
# Initialize vpd data
self.vpd_data = None

# move the initialization of each components to their dedicated initializer
# which will be called from platform
Expand Down Expand Up @@ -933,12 +936,12 @@ def get_revision(self):
Returns:
string: Revision value of device
"""
if self.dmi_data is None:
self.dmi_data = self._parse_dmi(DMI_FILE)
if self.vpd_data is None:
self.vpd_data = self._parse_vpd_data(VPD_DATA_FILE)

return self.dmi_data.get(DMI_VERSION, "N/A")
return self.vpd_data.get(REVISION, "N/A")

def _parse_dmi(self, filename):
def _parse_vpd_data(self, filename):
"""
Read DMI data chassis data and returns a dictionary of values
Expand All @@ -950,15 +953,14 @@ def _parse_dmi(self, filename):
if not os.access(filename, os.R_OK):
return result

with open(filename, "rb") as fileobj:
data = fileobj.read()

body = data[DMI_HEADER_LEN:]
records = body.split(b'\x00')

for k, v in DMI_TABLE_MAP.items():
result[k] = records[v].decode("utf-8")
with open(filename, "r") as vpd_file:
data = vpd_file.readlines()

for line in data:
field,value = line.split(": ")
value = value.strip()
result[field] = value

except Exception as e:
logger.log_error("Fail to decode DMI {} due to {}".format(filename, repr(e)))

Expand Down
Binary file removed platform/mellanox/mlnx-platform-api/tests/dmi_file
Binary file not shown.
10 changes: 5 additions & 5 deletions platform/mellanox/mlnx-platform-api/tests/test_chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def test_module(self):
assert len(module_list) == 3
assert chassis.module_initialized_count == 3

def test_revision_permission(self):
"""def test_revision_permission(self):
old_dmi_file = sonic_platform.chassis.DMI_FILE
#Override the dmi file
sonic_platform.chassis.DMI_FILE = "/tmp/dmi_file"
Expand All @@ -335,7 +335,7 @@ def test_revision_permission(self):
rev = chassis.get_revision()
sonic_platform.chassis.DMI_FILE = old_dmi_file
subprocess.call(["rm", "-f", new_dmi_file])
assert rev == "N/A"
assert rev == "N/A" """

def test_get_port_or_cage_type(self):
chassis = Chassis()
Expand All @@ -351,7 +351,7 @@ def test_get_port_or_cage_type(self):

assert exceptionRaised

def test_parse_dmi(self):
def test_parse_vpd(self):
chassis = Chassis()
content = chassis._parse_dmi(os.path.join(test_path, 'dmi_file'))
assert content.get('Version') == 'A4'
content = chassis._parse_vpd_data(os.path.join(test_path, 'vpd_data_file'))
assert content.get('REV') == 'A7'
51 changes: 51 additions & 0 deletions platform/mellanox/mlnx-platform-api/tests/vpd_data_file
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Part Number: MSN4700-WS2FO
Serial Number: MT2022X08597
Base MAC Address: 1c34da1d4200
Manufacture Date: 07/02/2020 02:38:26
MAC Addresses: 254
SN: MT2022X08597
PN: MSN4700-WS2FO
REV: A7
MFG_DATE: 8561348
PROD_NAME: Leopard Eth 400
HW_MGT_ID: 122
HW_MGT_REV: 0
SW_MGT_ID: 4700
SYS_DISPLAY: MSN4700
MAX_POWER: 0
CRIT_AMB_TEMP: 0
CRIT_IC_TEMP: 0
ALERT_AMB_TEMP: 0
ALERT_IC_TEMP: 0
FAN_DIR: 0
LENGTH: 0
WIDTH: 0
LED: 0
GUID_TYPE: 0xd
BASE_MAC_1: 1C:34:DA:1D:42:00
MAC_RANGE_1: 0xfe00
BASE_GUID_1: 1C:34:DA:03:00:1D:42:00
FEATURE_EN_0: 0
FEATURE_EN_1: 70
FEATURE_EN_2: 0
FEATURE_EN_3: 0
FEATURE_EN_4: 8
FEATURE_EN_5: 0
FEATURE_EN_6: 7
FEATURE_EN_7: 7
FEATURE_EN_8: 7
FEATURE_EN_9: 7
FEATURE_EN_10: 0
FEATURE_EN_11: 0
NUM_SCHEME: 0
EN_PORTS_NUM: 32
PORTS_INC_SCHEME: 0
PORTS_INC_ORDER_0: 0
PORTS_INC_ORDER_1: 0
PORTS_INC_ORDER_2: 0
PORTS_INC_ORDER_3: 0
Product Name: MSN4700
Manufacturer: Mellanox
Platform Name: x86_64-mlnx_msn4700-r0
ONIE Version: 2023.11-5.3.0011-9600
CHSUM_FIELD: 0XBB262C35

0 comments on commit f6496fc

Please sign in to comment.