[Mellanox] wait until hw-management watchdog files ready (#17618)

- Why I did it
watchdog-control service always disarm watchdog during system startup stage. It could be the case that watchdog is not fully initialized while the watchdog-control service is accessing it. This PR adds a wait to make sure watchdog has been fully initialized.

- How I did it
adds a wait to make sure watchdog has been fully initialized.

- How to verify it
Manual test
sonic regression
This commit is contained in:
Junchao-Mellanox 2023-12-27 00:27:18 +08:00 committed by mssonicbld
parent 9d918889e4
commit 0fbdc2b8ed
2 changed files with 4 additions and 1 deletions

View File

@ -283,7 +283,8 @@ def get_watchdog():
"""
Return WatchdogType1 or WatchdogType2 based on system
"""
utils.wait_until(lambda: os.path.exists('/run/hw-management/watchdog/main/state'), timeout=10, interval=1)
watchdog_main_device_name = None
for device in os.listdir("/dev/"):

View File

@ -36,6 +36,7 @@ from sonic_platform.watchdog import get_watchdog, \
class TestWatchdog:
@mock.patch('sonic_platform.utils.wait_until', mock.MagicMock())
@mock.patch('sonic_platform.watchdog.is_mlnx_wd_main')
@mock.patch('sonic_platform.watchdog.os.listdir')
def test_get_watchdog_no_device(self, mock_listdir, mock_is_main):
@ -50,6 +51,7 @@ class TestWatchdog:
mock_is_main.return_value = False
assert get_watchdog() is None
@mock.patch('sonic_platform.utils.wait_until', mock.MagicMock())
@mock.patch('sonic_platform.watchdog.is_mlnx_wd_main')
@mock.patch('sonic_platform.watchdog.is_wd_type2')
@mock.patch('sonic_platform.watchdog.os.listdir', mock.MagicMock(return_value=['watchdog1', 'watchdog2']))