Fix skip_fhrp_group_ips unbinding all interface IPs and py<3.12 import (continues #476) - #538
Merged
Merged
Conversation
… group ip address overriding
…assignment' into 445-sync-overwriting-FHRP-Group-assignment
…ve set valid types
…ured to prevent a duplicate ip address from being created, causing errors.
…nment Option to prevent FHRP group assignment from being overwritten (#445)
The FHRP-group check ran inside the address-matching loop, before the candidate address was compared to the IP being processed, so any FHRP group IP in the inventory raised skip_this_ip and the IP being handled was left unbound (issue #476). It also depended on inventory order and ignored the VRF. Move the check to a dedicated pass before the matching loop that scans for an FHRP-group assignment on this exact address in the same VRF, so unrelated FHRP IPs no longer suppress a regular IP and the outcome is order-independent, while the #445 behaviour (not rebinding a real FHRP-group IP) is preserved. Also fix an f-string with nested double quotes that is a SyntaxError before Python 3.12 and broke import on the supported Python 3.6+. Adds the first unit tests in the repo: an in-memory reproduction of the unbinding regression in both inventory orders, the VRF scoping, the #445 feature itself, and a control case. Verified red on the original logic and green with the fix on Python 3.11 and 3.13. Co-authored-by: Noah <noah@sol1.com.au> Co-authored-by: Andrew Foster <andy@sol1.com.au>
This was referenced Sep 9, 2026
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.
Builds on #476 by @Noah418 / @afoster (their commits are included here) and drives the v1.9.0 milestone item to a working state. Two fixes on top of their work, plus the first unit tests in the repo.
1. Import broken on Python < 3.12
The FHRP log line used an f-string with nested double quotes:
f"Ip address {grab(ip, "data.address")} ..."That syntax is only valid from Python 3.12 (PEP 701). The project supports Python 3.6+, so on 3.6–3.11 the module fails to import with
SyntaxError: f-string: unmatched '('— exactly what @ionoci reported. Reproduced on 3.11; fixed with single quotes inside; verified the module imports again on 3.11.2. skip_fhrp_group_ips unbound every interface IP
@ionoci also reported that enabling
skip_fhrp_group_ipsleft all VM interface IPs unbound. The FHRP check ran inside the address-matching loop before the candidate address was compared to the IP being processed, so any FHRP-group IP anywhere in the inventory raisedskip_this_ip, and theif skip_this_ip: continuedownstream dropped the IP being handled. The effect depended on inventory order and ignored the VRF.The fix moves the check to a dedicated pass before the matching loop that looks for an FHRP-group assignment on this exact address in the same VRF. An unrelated FHRP IP can no longer suppress a regular IP, the outcome no longer depends on inventory order, and the #445 behaviour (not rebinding a real FHRP-group IP) is preserved.
Tests
First unit tests in the repository (
tests/test_fhrp_ip_binding.py), running against the realadd_update_interfacepath via the in-memoryNetBoxInventory— no live NetBox or vCenter needed:Verified empirically: the regression and VRF tests fail on the original loop logic and all pass with the fix, on Python 3.11 and 3.13.
Closes #445.