From 6c7df02d5bb1be1d689da2fb911ffe153919a736 Mon Sep 17 00:00:00 2001 From: Junchao-Mellanox <57339448+Junchao-Mellanox@users.noreply.github.com> Date: Wed, 27 Dec 2023 00:27:18 +0800 Subject: [PATCH] [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 --- platform/mellanox/mlnx-platform-api/sonic_platform/watchdog.py | 3 ++- platform/mellanox/mlnx-platform-api/tests/test_watchdog.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/platform/mellanox/mlnx-platform-api/sonic_platform/watchdog.py b/platform/mellanox/mlnx-platform-api/sonic_platform/watchdog.py index 630163c12e18..9e16b6d69cf8 100644 --- a/platform/mellanox/mlnx-platform-api/sonic_platform/watchdog.py +++ b/platform/mellanox/mlnx-platform-api/sonic_platform/watchdog.py @@ -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/"): diff --git a/platform/mellanox/mlnx-platform-api/tests/test_watchdog.py b/platform/mellanox/mlnx-platform-api/tests/test_watchdog.py index 68d29d38a654..6e925d594708 100644 --- a/platform/mellanox/mlnx-platform-api/tests/test_watchdog.py +++ b/platform/mellanox/mlnx-platform-api/tests/test_watchdog.py @@ -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): @@ -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']))