fix: scope a cluster with the site object so NetBox accepts it - #566
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found this by running development against a real NetBox 4.4.5 rather than the test inventory, and it is bad: with
cluster_site_relationset, no cluster can be created at all on NetBox 4.2 or newer.add_cluster()puts{"name": <site>}intoscope_id. Everything else in the payload gets turned into an id byget_nb_reference(), but a plain dict is passed through, so NetBox answers:The cluster is never created, and every host and VM that referenced it then fails with "updated item cluster ... could not be fully resolved". On the vc001 capture that was 43 errors and 0 clusters, while 34 VMs and 3 hosts were still written, pointing at nothing.
Two changes.
add_cluster()now puts the site object itself intoscope_id. AndNBClustergets thescope_id/scope_typehandlingNBVLANGroupalready has: the data model lists the allowed scope classes, andresolve_relations()callsresolve_scoped_relations(). Without that second part NetBox hands the scope back as an id, the id never matches the object, and every run logsscope_id changed from '2' to 'e2e-site'and patches the cluster again.Measured on NetBox 4.4.5 with the vc001 capture: before, 0 clusters and 43 errors; after, the cluster exists scoped to the site, hosts and VMs attach to it, 0 errors, and two further runs change nothing.
cluster_site_relation = .* = <NONE>is also clean, cluster unscoped, idempotent.tests/test_cluster_scope.pycovers both halves and both fail on development:scope_idends up a dict after a sync, and a scope read back as an id is not resolved. Suite 141.If it is useful I can turn the throwaway stand I used for this - NetBox in docker plus vcsim, wired to
netbox-sync.py- into something reusable. There is no end-to-end coverage against a real NetBox today and this is the kind of thing it catches.