Repository navigation
sources: assign an IP that moved to another machine in the run that sees the move - #619
Open
tyderian1978 wants to merge 1 commit into
Open
tyderian1978 wants to merge 1 commit into
tyderian1978 wants to merge 1 commit into
Conversation
…ees the move When an address moves from one running machine to another (a Windows failover cluster's or SQL listener's address, a keepalived/ucarp VIP, an address handed to a replacement VM), the next run logged Current interface 'X' for IP 'a.b.c.d' and this one 'Y' are both enabled. IP assignment skipped because it is unclear which one is the correct one! and left the address assigned to nothing, tagged orphaned, until the run after that assigned it to the new machine. The old machine no longer reports the address, so add_update_interface() queues its removal (remove_interface_association() -> unset_attribute()). That only records the removal for the NetBox update phase; the object's data still names the old interface. The matching loop for the new machine, and the reevaluation pass meant for exactly this case, therefore kept seeing the address on an enabled interface of another active machine. Treat an address whose assignment is queued for removal as free, and drop the queued removal when it is assigned again, so NetBox gets a single PATCH to the new interface. An address both machines still report stays ambiguous and is skipped as before.
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.
Disclaimer: AI generated, based off the work we're doing with Netbox.
What happens
When an address moves from one running VM to another, the next run doesn't move it. Typical cases are the cluster and listener addresses of a Windows Server failover cluster or SQL Server availability group, a keepalived/ucarp VIP, or an address re-used by a replacement VM. That run logs
takes the address off node-b's interface and tags it
NetBox-synced: Orphaned. Only the run after that assigns it to node-a. So after every failover the address is assigned to nothing and tagged orphaned for one sync interval, and the change log gets three entries for it instead of one.We have about 50 such addresses on about 25 clusters. Patching moves most of them, and moves them back a night or two later. #250 reported the same warning for HA setups in 2022; excluding the addresses through
permitted_subnetsavoids the warning, but then they aren't synced at all.Why
In the run after the move, node-b no longer reports the address, so
add_update_interface()callsremove_interface_association()on it. That only queues the change:unset_attribute()adds it tounset_items, which the NetBox update sends in its first phase. The object's data still names node-b's interface.When node-a is parsed, the matching loop finds the address on an enabled interface of another active VM and skips it. That holds whichever VM is parsed first, and in the reevaluation pass meant for this case too: by the time node-a is parsed again, the removal is still only queued.
Fix
assigned_object_idis queued for unsetting counts as unassigned: the interface it is on stopped reporting it in this run.remove_interface_association()is only called from the removal loop inadd_update_interface(), so a queued unset means exactly that.NBIPAddress.update()drops a queued unset ofassigned_object_id/assigned_object_typewhen the address is assigned again, so NetBox gets one PATCH to the new interface instead of an unassign followed by an assign.An address both machines still report stays ambiguous and is skipped, as before.
Tests
tests/test_ip_moved_between_machines.py, in the style oftest_ip_non_unique_roles.py:Three of them fail on
developmentwithout the change (the "both report it" control passes); all four pass with it. Full suite: 611 passed, 8 skipped.Also checked end to end against vcsim and NetBox 4.7.2: two running VMs from
tests/fixtures/vcsim/vc001handing an address back and forth.