Skip to content

Commit

Permalink
[Mellanox] wait until hw-management watchdog files ready (#17618)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Junchao-Mellanox authored and mssonicbld committed Jan 18, 2024
1 parent 9d91888 commit 6c7df02
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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/"):
Expand Down
2 changes: 2 additions & 0 deletions platform/mellanox/mlnx-platform-api/tests/test_watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@


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):
Expand All @@ -50,6 +51,7 @@ def test_get_watchdog_no_device(self, mock_listdir, mock_is_main):
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']))
Expand Down

0 comments on commit 6c7df02

Please sign in to comment.