[Mellanox]Check dmi file permission before access (#11309)
Signed-off-by: Sudharsan Dhamal Gopalarathnam sudharsand@nvidia.com 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.
This commit is contained in:
parent
baaf8b085f
commit
23d68883f5
@ -649,6 +649,9 @@ class Chassis(ChassisBase):
|
||||
"""
|
||||
result = {}
|
||||
try:
|
||||
if not os.access(filename, os.R_OK):
|
||||
return result
|
||||
|
||||
with open(filename, "rb") as fileobj:
|
||||
data = fileobj.read()
|
||||
|
||||
|
@ -269,3 +269,16 @@ class TestChassis:
|
||||
module_list = chassis.get_all_modules()
|
||||
assert len(module_list) == 3
|
||||
assert chassis.module_initialized_count == 3
|
||||
|
||||
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"
|
||||
new_dmi_file = sonic_platform.chassis.DMI_FILE
|
||||
os.system("touch " + new_dmi_file)
|
||||
os.system("chmod -r " + new_dmi_file)
|
||||
chassis = Chassis()
|
||||
rev = chassis.get_revision()
|
||||
sonic_platform.chassis.DMI_FILE = old_dmi_file
|
||||
os.system("rm -f " + new_dmi_file)
|
||||
assert rev == "N/A"
|
||||
|
Loading…
Reference in New Issue
Block a user