datetime: Fix diagnostic test for checking NTP server sync

Fixes: #2384

- This was missed during the original transition to DiagnosticCheck class for
returning diagnostic results.

Tests:

- In vagrant container, test that the diagnostic test result shows up in
datetime app and it passes.

- Running full diagnostics on the system works.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2023-10-30 15:40:30 -07:00 committed by James Valleroy
parent 1f90047621
commit e3c2546b79
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -11,6 +11,7 @@ from plinth import app as app_module
from plinth import menu
from plinth.daemon import Daemon, RelatedDaemon
from plinth.modules.backups.components import BackupRestore
from plinth.modules.diagnostics.check import DiagnosticCheck, Result
from plinth.package import Packages
from . import manifest
@ -107,13 +108,14 @@ class DateTimeApp(app_module.App):
def _diagnose_time_synchronized():
"""Check whether time is synchronized to NTP server."""
result = 'failed'
result = Result.FAILED
try:
output = subprocess.check_output(
['timedatectl', 'show', '--property=NTPSynchronized', '--value'])
if 'yes' in output.decode():
result = 'passed'
result = Result.PASSED
except subprocess.CalledProcessError:
pass
return [_('Time synchronized to NTP server'), result]
return DiagnosticCheck('datetime-ntp-sync',
_('Time synchronized to NTP server'), result)