peteeckel/netbox-plugin-dns

ValidationError for change of IP address when RFC2317 CNAME is already present

Closed this issue · 0 comments

Versions
NetBox Version: 3.7.4
NetBox DNS Version: 0.22.6
Python Version: 3.11.5

Describe the bug
When the value of an A record is changed and the PTR record is in an RFC2317 zone with managed parent zone, the CNAME record in the parent zone can't be updated if it already exists for a different record.

To Reproduce

  • Create reverse zone 0.0.10.in-addr.arpa
  • Create RFC2317 reverse zone 0-31.0.0.10.in-addr.arpa with rfc2317_parent_managed=True and rfc2317_prefix=10.0.0.0/27
  • Create forward zone, zone1.example.com
  • Create A record name1.zone1.example.com with value 10.0.0.1 and disable_ptr=False
  • Create A record name2.zone1.example.com with value 10.0.0.2 and disable_ptr=False
  • Change the value of A record name1.zone1.example.com to 10.0.0.2

Expected result

  • The value of A record name1.zone1.example.com is now 10.0.0.2
  • There is a PTR record 2.0-31.0.0.10.in-addr.arpa in the RFC2317 zone with value name1.zone1.example.com.
  • There is another PTR record 2.0-31.0.0.10.in-addr.arpa in the RFC2317 zone with value name2.zone1.example.com.
  • CNAME record 2.0.0.10.in-addr.arpa exists in zone 0.0.10.in-addr.arpa with value 2.0-31.0.0.10.in-addr.arpa

Actual result

Traceback (most recent call last):
  File "/opt/netbox/lib64/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/netbox/views/generic/object_views.py", line 175, in dispatch
    return super().dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/netbox/views/generic/base.py", line 26, in dispatch
    return super().dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/utilities/views.py", line 106, in dispatch
    return super().dispatch(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/netbox/netbox/netbox/views/generic/object_views.py", line 269, in post
    obj = form.save()
          ^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/forms/models.py", line 542, in save
    self.instance.save()
    ^^^^^^^^^^^^^^^^^^^^
  File "/vagrant/netbox-dns/netbox_dns/models/record.py", line 712, in save
    self.update_ptr_record(
    ^
  File "/vagrant/netbox-dns/netbox_dns/models/record.py", line 378, in update_ptr_record
    ptr_record.save(save_zone_serial=save_zone_serial)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/vagrant/netbox-dns/netbox_dns/models/record.py", line 702, in save
    self.update_rfc2317_cname_record(save_zone_serial=save_zone_serial)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/vagrant/netbox-dns/netbox_dns/models/record.py", line 412, in update_rfc2317_cname_record
    self.rfc2317_cname_record.save(save_zone_serial=save_zone_serial)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/vagrant/netbox-dns/netbox_dns/models/record.py", line 693, in save
    self.full_clean()
    ^^^^^^^^^^^^^^^^^
  File "/opt/netbox/lib64/python3.11/site-packages/django/db/models/base.py", line 1502, in full_clean
    raise ValidationError(errors)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Exception Type: ValidationError at /plugins/netbox-dns/records/54/edit/
Exception Value: {'value': ['There is already an active CNAME record for name 2 in zone 0.0.10.in-addr.arpa with value 2.0-31.0.0.10.in-addr.arpa..']}