1818# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
1919
2020import argparse
21+ import re
2122import subprocess
2223
2324from checkbox_support .snap_utils .system import on_ubuntucore
4546"""
4647
4748
49+ WATCHDOG_SERVICE_TIMEOUT_PATTERN = "watchdog-timeout"
50+
51+
4852def get_systemd_wdt_usec ():
4953 """
5054 Return value of systemd-watchdog RuntimeWatchdogUSec
@@ -64,6 +68,21 @@ def get_systemd_wdt_usec():
6468 )
6569
6670
71+ def get_watchdog_service_timeout ():
72+ watchdog_timeout = 0
73+ with open ("/etc/watchdog.conf" , "r" ) as fp :
74+ config_data = fp .read ()
75+ match = re .search (
76+ r"^{}[ ]*=[ ]*([0-9]*)" .format (WATCHDOG_SERVICE_TIMEOUT_PATTERN ),
77+ config_data ,
78+ re .MULTILINE ,
79+ )
80+ if match :
81+ watchdog_timeout = int (match .group (1 ))
82+
83+ return watchdog_timeout
84+
85+
6786def watchdog_service_check ():
6887 """
6988 Check if the watchdog service is configured correctly
@@ -111,9 +130,26 @@ def check_timeout() -> bool:
111130 "before running this test."
112131 )
113132 raise SystemExit (1 )
133+
134+ watchdog_service_sec = get_watchdog_service_timeout ()
135+ if not watchdog_service_sec :
136+ print (
137+ "watchdog service should be enabled but reset timeout "
138+ "({}) is set to: {}" .format (
139+ WATCHDOG_SERVICE_TIMEOUT_PATTERN ,
140+ watchdog_service_sec ,
141+ )
142+ )
143+ print (
144+ "In order for the watchdog.service to work, the "
145+ "{} configuration option must be set before "
146+ "running this test." .format (WATCHDOG_SERVICE_TIMEOUT_PATTERN )
147+ )
148+ raise SystemExit (1 )
149+
114150 print (
115- "systemd watchdog disabled , reset timeout: {}" .format (
116- runtime_watchdog_usec
151+ "watchdog service enabled , reset timeout: {}" .format (
152+ watchdog_service_sec
117153 )
118154 )
119155
0 commit comments