Skip to content

Commit 23d6888

Browse files
authored
[Mellanox]Check dmi file permission before access (#11309)
Signed-off-by: Sudharsan Dhamal Gopalarathnam [email protected] Why I did it During the system boot up when 'show platform status' or 'show version' command is executed before STATE_DB CHASSIS_INFO table is populated, the show will try to fallback to use the platform API. The DMI file in mellanox platforms require root permission for access. So if the show commands are executed as admin or any other user, the following error log will appear in the syslog Jun 28 17:21:25.612123 sonic ERR show: Fail to decode DMI /sys/firmware/dmi/entries/2-0/raw due to PermissionError(13, 'Permission denied') How I did it Check the file permission before accessing it. How to verify it Added UT to verify. Manually verified if the error log is not thrown.
1 parent baaf8b0 commit 23d6888

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,9 @@ def _parse_dmi(self, filename):
649649
"""
650650
result = {}
651651
try:
652+
if not os.access(filename, os.R_OK):
653+
return result
654+
652655
with open(filename, "rb") as fileobj:
653656
data = fileobj.read()
654657

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

+13
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,16 @@ def test_module(self):
269269
module_list = chassis.get_all_modules()
270270
assert len(module_list) == 3
271271
assert chassis.module_initialized_count == 3
272+
273+
def test_revision_permission(self):
274+
old_dmi_file = sonic_platform.chassis.DMI_FILE
275+
#Override the dmi file
276+
sonic_platform.chassis.DMI_FILE = "/tmp/dmi_file"
277+
new_dmi_file = sonic_platform.chassis.DMI_FILE
278+
os.system("touch " + new_dmi_file)
279+
os.system("chmod -r " + new_dmi_file)
280+
chassis = Chassis()
281+
rev = chassis.get_revision()
282+
sonic_platform.chassis.DMI_FILE = old_dmi_file
283+
os.system("rm -f " + new_dmi_file)
284+
assert rev == "N/A"

0 commit comments

Comments
 (0)