Skip to content

Commit 32ffd04

Browse files
committed
[fix] Fixed backward compatibility issue with custom health status labels
When using customized OPENWISP_MONITORING_HEALTH_STATUS_LABELS, forgetting to add the new deactivated status label after upgrading would cause a crash of the application during startup. This fix provides a set of valid defaults which is always present and gets overridden with the custom labels.
1 parent cbcbae5 commit 32ffd04

File tree

2 files changed

+11
-28
lines changed

2 files changed

+11
-28
lines changed

openwisp_monitoring/device/settings.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,19 @@ def get_critical_device_metrics():
2020

2121

2222
def get_health_status_labels():
23-
labels = get_settings_value(
23+
default_labels = {
24+
'unknown': 'unknown',
25+
'ok': 'ok',
26+
'problem': 'problem',
27+
'critical': 'critical',
28+
'deactivated': 'deactivated',
29+
}
30+
labels = default_labels.copy()
31+
configured_labels = get_settings_value(
2432
'HEALTH_STATUS_LABELS',
25-
{
26-
'unknown': 'unknown',
27-
'ok': 'ok',
28-
'problem': 'problem',
29-
'critical': 'critical',
30-
'deactivated': 'deactivated',
31-
},
33+
default_labels,
3234
)
33-
try:
34-
assert 'unknown' in labels
35-
assert 'ok' in labels
36-
assert 'problem' in labels
37-
assert 'critical' in labels
38-
assert 'deactivated' in labels
39-
except AssertionError as e: # pragma: no cover
40-
raise ImproperlyConfigured(
41-
'OPENWISP_MONITORING_HEALTH_STATUS_LABELS must contain the following '
42-
'keys: unknown, ok, problem, critical'
43-
) from e
35+
labels.update(configured_labels)
4436
return labels
4537

4638

openwisp_monitoring/device/tests/test_settings.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,3 @@ def test_invalid_critical_device_metrics_setting(self):
1818
from ..settings import get_critical_device_metrics
1919

2020
get_critical_device_metrics()
21-
22-
@patch(
23-
'django.conf.settings.OPENWISP_MONITORING_HEALTH_STATUS_LABELS', {}, create=True
24-
)
25-
def test_invalid_health_status_setting(self):
26-
with self.assertRaises(ImproperlyConfigured):
27-
from ..settings import get_health_status_labels
28-
29-
get_health_status_labels()

0 commit comments

Comments
 (0)