issue-7-config-cleanup-legacy-removal #18

Merged
parkel merged 7 commits from issue-7-config-cleanup-legacy-removal into master 2026-05-21 02:57:39 +02:00
3 changed files with 13 additions and 4 deletions
Showing only changes of commit a73d34ac9f - Show all commits

View File

@@ -85,7 +85,7 @@ def global_config_data(name: str = "default") -> dict[str, Any]:
try:
global_config = GlobalConfig.objects.get(name=name)
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)
@@ -93,5 +93,5 @@ def host_config_data(host: str) -> dict[str, Any]:
try:
host_config = HostConfig.objects.get(host=host, enabled=True)
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)

View File

@@ -135,7 +135,7 @@ def _enabled_host_config(host: str) -> HostConfig:
try:
return HostConfig.objects.get(host=host, enabled=True)
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]:

View File

@@ -2,7 +2,7 @@ from __future__ import annotations
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
@@ -52,3 +52,12 @@ class ConfigRepositoryTests(TestCase):
self.assertEqual(host_cfg["excludes_add"], ["/tmp/***"])
self.assertNotIn("unknown", global_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")