diagnostics: Safely access results when showing notification

It is best to have obtained the results lock when counting the severe failures
in diagnostic results.

Tests:

- When some packages are outdated, notification is shown with warning severity.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Sunil Mohan Adapa 2024-01-18 22:04:42 -08:00
parent 5f08752058
commit ba145b3194
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

@ -271,19 +271,18 @@ def _run_diagnostics():
kvstore.set('diagnostics_results', kvstore.set('diagnostics_results',
json.dumps(results, cls=CheckJSONEncoder)) json.dumps(results, cls=CheckJSONEncoder))
issue_count = 0 issue_count = 0
severity = 'warning' severity = 'warning'
for _app_id, app_data in results.items(): for _app_id, app_data in results.items():
if app_data['exception']: if app_data['exception']:
issue_count += 1 issue_count += 1
severity = 'error' severity = 'error'
else: else:
for check in app_data['diagnosis']: for check in app_data['diagnosis']:
if check.result != Result.PASSED: if check.result != Result.PASSED:
if check.result != Result.WARNING: issue_count += 1
severity = 'error' if check.result != Result.WARNING:
severity = 'error'
issue_count += 1
if not issue_count: if not issue_count:
# Remove any previous notifications if there are no issues. # Remove any previous notifications if there are no issues.