Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Automatic generation of SOA Serial numbers based on the modification dates of zone and records #74

Merged
merged 5 commits into from
Dec 10, 2021
Merged

Conversation

peteeckel
Copy link
Contributor

fixes #73

This PR implements the strategy outlined in discussion #64.

Every time a zone or a record is changed in NetBox DNS, the "last_updated" field is set to the time of the change. The code submitted updates the SOA SERIAL field for a zone on every change of a record in the zone or the zone itself to an integer number representing the maximum Epoch time stamp of the zone object's and all related records' "last_updated" fields.

Special care needs to be taken in case of the deletion of records, as the operation does not change anything in the zone object, so the serial number would not change. To avoid that issue, the zone's "last_updated" field is set to the current time
every time a record belonging to the zone is deleted.

Changes to SOA records are exempt from calculating the zone's serial number to avoid the risk of endless loops (which is rather low, but still present and since the SOA record will only change when the SOA related fields in the zone change the SOA record is not interesting for the serial calculation.

There is a new setting in the PLUGINS_CONFIG field for netbox_dns: zone_soa_serial_auto can be set to a boolean value determining whether new records should have automatic SOA generation enabled or not. The default for new zones is "True".

On migration, all existing zones will have the "zone_soa_auto" flag set to "False" to provide backward compatibility and avoid data loss.

@peteeckel peteeckel marked this pull request as draft November 29, 2021 23:06
@peteeckel peteeckel marked this pull request as ready for review November 29, 2021 23:22
@peteeckel peteeckel marked this pull request as draft December 1, 2021 18:16
@peteeckel peteeckel marked this pull request as ready for review December 1, 2021 18:23
The problem with testing this feature is that the serial numbers it creates are
time-based, and so it would be very time-consuming to create meaningful tests, as
lots of delays would have to be implemented to make time advance in the test
environment.

One way to fix this would be to run tests asynchronsously and keep the delays
short, say in between 0 and 20 seconds. Asynchronous execution with e.g. pytest-async
would have the advantage of only having to wait for the duration of the slowest test.

Another way could be to change the "last_updated" field for certain objects in the
database. I'm not really sure if that would be such a great idea, though.

All in all, a tricky one.
@peteeckel
Copy link
Contributor Author

Rebased to today's main branch and ready for merging.

@hatsat32
Copy link
Collaborator

hatsat32 commented Dec 9, 2021

Hi, peter. Thanks for this great PR. May I ask you a question, please?

In the zone_edit.html file I see you changed the form field order, leave a lot of comments, and removed the tags field. I think we should keep tags field :)

If you only want to change field order we can use fieldsets in Meta class with object_edit.html template:

class XForm:
    ...
    class Meta:
    ...
        fieldsets = (
            ('Zone', ('name', 'status', 'nameservers', 'default_ttl', 'tags')),
            ('SOA', ('soa_ttl', 'soa_mname', 'soa_serial_auto', .....)),
        )

The above example is a little bit dirty but it should give you an idea.

If I am missing something just let me know.

@peteeckel
Copy link
Contributor Author

Hi Süleyman! Thanks, you're absolutely right - the tags field got lost on the way, that certainly wasn't intended (in fact I have a PR in preparation that adds tags to one of the search fields where it was missing, so I certainly don't want to lose the tags feature anywhere).

You'll have noticed that the zone_edit.html template has been completely re-written, because the standard template didn't provide any way of optically structuring the input fields, and to provide an option of dynamically hiding and showing fields depending on, e.g. the "Generate SOA Serial" checkbox - unfortunately that's not ready yet, and currently I'm trying to get the current state usable for the first pre-production application and don't have too much time. So it's not just about ordering the fields.

And yes, the comments were left in by accident - they contain my first non-successful attempt at hiding fields dynamically. Gone now (for the time being).

I've added the missing "tags" field now.

@hatsat32 hatsat32 merged commit d60e1f8 into auroraresearchlab:main Dec 10, 2021
@peteeckel peteeckel deleted the feature/auto-soa-serial branch December 10, 2021 16:59
@hatsat32 hatsat32 mentioned this pull request Dec 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatic creation of the SOA Serial number
2 participants