(refactor) Use operator-facing config errors
Replace remaining model-name based configuration errors with labels that match the Django-first operating model. Add coverage for missing global config and host configuration errors so operator-facing messages stay readable.
This commit is contained in:
@@ -85,7 +85,7 @@ def global_config_data(name: str = "default") -> dict[str, Any]:
|
|||||||
try:
|
try:
|
||||||
global_config = GlobalConfig.objects.get(name=name)
|
global_config = GlobalConfig.objects.get(name=name)
|
||||||
except ObjectDoesNotExist as exc:
|
except ObjectDoesNotExist as exc:
|
||||||
raise ConfigRepositoryError(f"Missing GlobalConfig {name!r}") from exc
|
raise ConfigRepositoryError(f"Missing global config {name!r}") from exc
|
||||||
return _global_runtime_data(global_config)
|
return _global_runtime_data(global_config)
|
||||||
|
|
||||||
|
|
||||||
@@ -93,5 +93,5 @@ def host_config_data(host: str) -> dict[str, Any]:
|
|||||||
try:
|
try:
|
||||||
host_config = HostConfig.objects.get(host=host, enabled=True)
|
host_config = HostConfig.objects.get(host=host, enabled=True)
|
||||||
except ObjectDoesNotExist as exc:
|
except ObjectDoesNotExist as exc:
|
||||||
raise ConfigRepositoryError(f"Missing enabled HostConfig {host!r}") from exc
|
raise ConfigRepositoryError(f"Missing enabled host {host!r}") from exc
|
||||||
return _host_runtime_data(host_config)
|
return _host_runtime_data(host_config)
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ def _enabled_host_config(host: str) -> HostConfig:
|
|||||||
try:
|
try:
|
||||||
return HostConfig.objects.get(host=host, enabled=True)
|
return HostConfig.objects.get(host=host, enabled=True)
|
||||||
except HostConfig.DoesNotExist as exc:
|
except HostConfig.DoesNotExist as exc:
|
||||||
raise ConfigError(f"Missing enabled HostConfig {host!r}") from exc
|
raise ConfigError(f"Missing enabled host {host!r}") from exc
|
||||||
|
|
||||||
|
|
||||||
def _retention_for_host(host_config: HostConfig) -> dict[str, int]:
|
def _retention_for_host(host_config: HostConfig) -> dict[str, int]:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from pobsync_backend.config_repository import global_config_data, host_config_data
|
from pobsync_backend.config_repository import ConfigRepositoryError, global_config_data, host_config_data
|
||||||
from pobsync_backend.models import GlobalConfig, HostConfig
|
from pobsync_backend.models import GlobalConfig, HostConfig
|
||||||
|
|
||||||
|
|
||||||
@@ -52,3 +52,12 @@ class ConfigRepositoryTests(TestCase):
|
|||||||
self.assertEqual(host_cfg["excludes_add"], ["/tmp/***"])
|
self.assertEqual(host_cfg["excludes_add"], ["/tmp/***"])
|
||||||
self.assertNotIn("unknown", global_cfg)
|
self.assertNotIn("unknown", global_cfg)
|
||||||
self.assertNotIn("unknown", host_cfg)
|
self.assertNotIn("unknown", host_cfg)
|
||||||
|
|
||||||
|
def test_missing_config_errors_use_operator_labels(self) -> None:
|
||||||
|
with self.assertRaisesMessage(ConfigRepositoryError, "Missing global config 'default'"):
|
||||||
|
global_config_data()
|
||||||
|
|
||||||
|
GlobalConfig.objects.create(name="default", backup_root="/backups")
|
||||||
|
|
||||||
|
with self.assertRaisesMessage(ConfigRepositoryError, "Missing enabled host 'web-01'"):
|
||||||
|
host_config_data("web-01")
|
||||||
|
|||||||
Reference in New Issue
Block a user