Skip to content

Commit 6d4a915

Browse files
authored
[Mellanox] Changed platform summary to reflect HW revision from vpd_data (sonic-net#19098)
- Why I did it The command 'show platform summary' reflected the wrong HW revision. In order to have the correct HW revision, we need to read it from vpd_data file that HW management provide. - How I did it Changed the source from which the HW revision is taken.
1 parent c2d06ee commit 6d4a915

File tree

4 files changed

+66
-49
lines changed

4 files changed

+66
-49
lines changed

platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py

+12-33
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,8 @@
4141

4242
RJ45_TYPE = "RJ45"
4343

44-
DMI_FILE = '/sys/firmware/dmi/entries/2-0/raw'
45-
DMI_HEADER_LEN = 15
46-
DMI_PRODUCT_NAME = "Product Name"
47-
DMI_MANUFACTURER = "Manufacturer"
48-
DMI_VERSION = "Version"
49-
DMI_SERIAL = "Serial Number"
50-
DMI_ASSET_TAG = "Asset Tag"
51-
DMI_LOC = "Location In Chassis"
52-
DMI_TABLE_MAP = {
53-
DMI_PRODUCT_NAME: 0,
54-
DMI_MANUFACTURER: 1,
55-
DMI_VERSION: 2,
56-
DMI_SERIAL: 3,
57-
DMI_ASSET_TAG: 4,
58-
DMI_LOC: 5
59-
}
44+
VPD_DATA_FILE = "/var/run/hw-management/eeprom/vpd_data"
45+
REVISION = "REV"
6046

6147
HWMGMT_SYSTEM_ROOT = '/var/run/hw-management/system/'
6248

@@ -87,8 +73,8 @@ class Chassis(ChassisBase):
8773
def __init__(self):
8874
super(Chassis, self).__init__()
8975

90-
# Initialize DMI data
91-
self.dmi_data = None
76+
# Initialize vpd data
77+
self.vpd_data = None
9278

9379
# move the initialization of each components to their dedicated initializer
9480
# which will be called from platform
@@ -933,14 +919,14 @@ def get_revision(self):
933919
Returns:
934920
string: Revision value of device
935921
"""
936-
if self.dmi_data is None:
937-
self.dmi_data = self._parse_dmi(DMI_FILE)
922+
if not self.vpd_data:
923+
self.vpd_data = self._parse_vpd_data(VPD_DATA_FILE)
938924

939-
return self.dmi_data.get(DMI_VERSION, "N/A")
925+
return self.vpd_data.get(REVISION, "N/A")
940926

941-
def _parse_dmi(self, filename):
927+
def _parse_vpd_data(self, filename):
942928
"""
943-
Read DMI data chassis data and returns a dictionary of values
929+
Read vpd_data and returns a dictionary of values
944930
945931
Returns:
946932
A dictionary containing the dmi table of the switch chassis info
@@ -950,17 +936,10 @@ def _parse_dmi(self, filename):
950936
if not os.access(filename, os.R_OK):
951937
return result
952938

953-
with open(filename, "rb") as fileobj:
954-
data = fileobj.read()
955-
956-
body = data[DMI_HEADER_LEN:]
957-
records = body.split(b'\x00')
958-
959-
for k, v in DMI_TABLE_MAP.items():
960-
result[k] = records[v].decode("utf-8")
961-
939+
result = utils.read_key_value_file(filename, delimeter=": ")
940+
962941
except Exception as e:
963-
logger.log_error("Fail to decode DMI {} due to {}".format(filename, repr(e)))
942+
logger.log_error("Fail to decode vpd_data {} due to {}".format(filename, repr(e)))
964943

965944
return result
966945

-96 Bytes
Binary file not shown.

platform/mellanox/mlnx-platform-api/tests/test_chassis.py

+3-16
Original file line numberDiff line numberDiff line change
@@ -324,19 +324,6 @@ def test_module(self):
324324
assert len(module_list) == 3
325325
assert chassis.module_initialized_count == 3
326326

327-
def test_revision_permission(self):
328-
old_dmi_file = sonic_platform.chassis.DMI_FILE
329-
#Override the dmi file
330-
sonic_platform.chassis.DMI_FILE = "/tmp/dmi_file"
331-
new_dmi_file = sonic_platform.chassis.DMI_FILE
332-
subprocess.call(["touch", new_dmi_file])
333-
subprocess.call(["chmod", "-r", new_dmi_file])
334-
chassis = Chassis()
335-
rev = chassis.get_revision()
336-
sonic_platform.chassis.DMI_FILE = old_dmi_file
337-
subprocess.call(["rm", "-f", new_dmi_file])
338-
assert rev == "N/A"
339-
340327
def test_get_port_or_cage_type(self):
341328
chassis = Chassis()
342329
chassis._RJ45_port_inited = True
@@ -351,7 +338,7 @@ def test_get_port_or_cage_type(self):
351338

352339
assert exceptionRaised
353340

354-
def test_parse_dmi(self):
341+
def test_parse_vpd(self):
355342
chassis = Chassis()
356-
content = chassis._parse_dmi(os.path.join(test_path, 'dmi_file'))
357-
assert content.get('Version') == 'A4'
343+
content = chassis._parse_vpd_data(os.path.join(test_path, 'vpd_data_file'))
344+
assert content.get('REV') == 'A7'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Part Number: MSN4700-WS2FO
2+
Serial Number: MT2022X08597
3+
Base MAC Address: 1c34da1d4200
4+
Manufacture Date: 07/02/2020 02:38:26
5+
MAC Addresses: 254
6+
SN: MT2022X08597
7+
PN: MSN4700-WS2FO
8+
REV: A7
9+
MFG_DATE: 8561348
10+
PROD_NAME: Leopard Eth 400
11+
HW_MGT_ID: 122
12+
HW_MGT_REV: 0
13+
SW_MGT_ID: 4700
14+
SYS_DISPLAY: MSN4700
15+
MAX_POWER: 0
16+
CRIT_AMB_TEMP: 0
17+
CRIT_IC_TEMP: 0
18+
ALERT_AMB_TEMP: 0
19+
ALERT_IC_TEMP: 0
20+
FAN_DIR: 0
21+
LENGTH: 0
22+
WIDTH: 0
23+
LED: 0
24+
GUID_TYPE: 0xd
25+
BASE_MAC_1: 1C:34:DA:1D:42:00
26+
MAC_RANGE_1: 0xfe00
27+
BASE_GUID_1: 1C:34:DA:03:00:1D:42:00
28+
FEATURE_EN_0: 0
29+
FEATURE_EN_1: 70
30+
FEATURE_EN_2: 0
31+
FEATURE_EN_3: 0
32+
FEATURE_EN_4: 8
33+
FEATURE_EN_5: 0
34+
FEATURE_EN_6: 7
35+
FEATURE_EN_7: 7
36+
FEATURE_EN_8: 7
37+
FEATURE_EN_9: 7
38+
FEATURE_EN_10: 0
39+
FEATURE_EN_11: 0
40+
NUM_SCHEME: 0
41+
EN_PORTS_NUM: 32
42+
PORTS_INC_SCHEME: 0
43+
PORTS_INC_ORDER_0: 0
44+
PORTS_INC_ORDER_1: 0
45+
PORTS_INC_ORDER_2: 0
46+
PORTS_INC_ORDER_3: 0
47+
Product Name: MSN4700
48+
Manufacturer: Mellanox
49+
Platform Name: x86_64-mlnx_msn4700-r0
50+
ONIE Version: 2023.11-5.3.0011-9600
51+
CHSUM_FIELD: 0XBB262C35

0 commit comments

Comments
 (0)