Skip to content

Commit b5dc935

Browse files
Junchao-Mellanoxsaravanansv
authored andcommitted
[Mellanox] Fixed issue: failed to recover mock file (sonic-net#3407)
* Remove check for /var/run/hw-management/config/suspend since it is not used in SONiC Fixed issue: failed to recover mock file. If a file is mocked, no need to check the file type again. - How did you do it? If a file is mocked, skip checking the file type and directly write value to it. - How did you verify/test it? Run test case manually - Any platform specific information? Mellanox
1 parent f65a9cd commit b5dc935

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

tests/platform_tests/mellanox/mellanox_thermal_control_test_helper.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,14 @@ def mock_value(self, file_path, value):
193193
:param value: Value to write to sys fs file.
194194
:return:
195195
"""
196-
out = self.dut.stat(path=file_path)
197-
if not out['stat']['exists']:
198-
raise SysfsNotExistError('{} not exist'.format(file_path))
199-
if out['stat']['islnk']:
200-
self._unlink(file_path)
201-
else:
202-
self._cache_file_value(file_path)
196+
if file_path not in self.regular_file_list and file_path not in self.unlink_file_list:
197+
out = self.dut.stat(path=file_path)
198+
if not out['stat']['exists']:
199+
raise SysfsNotExistError('{} not exist'.format(file_path))
200+
if out['stat']['islnk']:
201+
self._unlink(file_path)
202+
else:
203+
self._cache_file_value(file_path)
203204
self.dut.shell('echo \'{}\' > {}'.format(value, file_path))
204205

205206
def read_thermal_value(self, file_path):
@@ -242,26 +243,24 @@ def _cache_file_value(self, file_path):
242243
:param file_path: Regular file path.
243244
:return:
244245
"""
245-
if file_path not in self.regular_file_list:
246-
try:
247-
output = self.dut.command("cat %s" % file_path)
248-
value = output["stdout"]
249-
self.regular_file_list[file_path] = value.strip()
250-
except Exception as e:
251-
assert 0, "Get content from %s failed, exception: %s" % (file_path, repr(e))
246+
try:
247+
output = self.dut.command("cat %s" % file_path)
248+
value = output["stdout"]
249+
self.regular_file_list[file_path] = value.strip()
250+
except Exception as e:
251+
assert 0, "Get content from %s failed, exception: %s" % (file_path, repr(e))
252252

253253
def _unlink(self, file_path):
254254
"""
255255
Unlink given sys fs file, record its soft link target.
256256
:param file_path: Sys fs file path.
257257
:return:
258258
"""
259-
if file_path not in self.unlink_file_list:
260-
readlink_output = self.dut.command('readlink {}'.format(file_path))
261-
self.unlink_file_list[file_path] = readlink_output["stdout"]
262-
self.dut.command('unlink {}'.format(file_path))
263-
self.dut.command('touch {}'.format(file_path))
264-
self.dut.command('chown admin {}'.format(file_path))
259+
readlink_output = self.dut.command('readlink {}'.format(file_path))
260+
self.unlink_file_list[file_path] = readlink_output["stdout"]
261+
self.dut.command('unlink {}'.format(file_path))
262+
self.dut.command('touch {}'.format(file_path))
263+
self.dut.command('chown admin {}'.format(file_path))
265264

266265
def deinit(self):
267266
"""

0 commit comments

Comments
 (0)