Replace global IntegerKeyValueSetting with per-view CatalogZone model
Track the catalog zone SOA serial per view instead of a single global value. The new CatalogZone model has a 1:1 FK to netbox_dns.models.View and its own soa_serial field; each view's catalog zone now increments independently. The existing global serial is preserved during migration by copying it into every view's new CatalogZone row. Change CatalogZoneMemberIdentifier.name from globally unique to unique per catalog zone (UniqueConstraint(name, catalog_zone)) and add a catalog_zone FK to enforce it. Remove the dns-settings management command, which was a generic interface over the now-removed IntegerKeyValueSetting model. Increment both catalog zone serials when a zone moves between views: the old view's catalog zone loses a member and the new view's gains one, so both must be bumped. Also refresh the member identifier's catalog_zone FK on a view move so it does not go stale. The pre_save handler now captures _old_view_id and the post_save handler detects view changes, increments the old view's serial inside on_commit (before the new view's), and re-creates the identifier. AI generated, code manually verified.
This commit is contained in:
1 parent
4ad110ca53
commit
9f5e40ae48
17 files changed
+429
-240
No files matched your search
@@ -203,12 +203,12 @@ class TestScheduleNsNotify:
|
||||
class TestSendClientDNSNotifyRun:
|
||||
def test_sends_notify_to_seen_clients(self, make_zone, make_view, monkeypatch):
|
||||
import netbox_dns_bridge.signals.notify_handler as nh
|
||||
from netbox_dns_bridge.models import SeenTransferClients, IntegerKeyValueSetting
|
||||
from netbox_dns_bridge.models import SeenTransferClients, CatalogZone
|
||||
from django.utils import timezone
|
||||
|
||||
view = make_view(name="notify-run-view")
|
||||
IntegerKeyValueSetting.objects.update_or_create(
|
||||
key="catalog-zone-soa-serial", defaults={"value": 42}
|
||||
CatalogZone.objects.update_or_create(
|
||||
view=view, defaults={"soa_serial": 42}
|
||||
)
|
||||
SeenTransferClients.objects.create(
|
||||
source_ip="192.0.2.99", view=view, last_seen=timezone.now()
|
||||
@@ -236,7 +236,7 @@ class TestSendClientDNSNotifyRun:
|
||||
assert mock_udp.call_count >= 3 # zone + catz + view.catz
|
||||
|
||||
def test_handles_missing_serial_setting(self, monkeypatch, make_view):
|
||||
# When the IntegerKeyValueSetting for catz serial doesn't exist,
|
||||
# When the CatalogZone for the view doesn't exist,
|
||||
# the job should log an error and not send any notifies
|
||||
view = make_view(name="missing-serial-view")
|
||||
|
||||
|
||||
Reference in new issue
Block a user