Option to prevent FHRP group assignment from being overwritten (#445) - #476
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 (bb-Ricardo#445)
|
Hi, and thank you very much for this PR. I'm still a bit busy but soon will have some time to look at this. Don't worry, just need some more time. |
0655b11 to
499862a
Compare
8adc4cd to
4c5fbc8
Compare
|
Hi @Noah418 or @afoster , thanks a lot for implementing this feature. I fixed it by setting single ticks as quotation marks: If I enable how may I help debugging this? Cheers |
|
I've opened #538 which builds on this PR (your commits included) and adds two fixes @ionoci reported: the py<3.12 SyntaxError that broke import, and the regression where skip_fhrp_group_ips unbound every interface IP (the FHRP check now runs before the matching loop, scoped to the same address+VRF, so it's order-independent). It also adds the first unit tests in the repo. Credited you and @afoster as co-authors. |
Fix skip_fhrp_group_ips unbinding all interface IPs and py<3.12 import (continues #476)
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 bb-Ricardo#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 bb-Ricardo#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 bb-Ricardo#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>
The VMware source could only be exercised against a live vCenter, which is why bugs like bb-Ricardo#476 were found by users rather than by a test. vcsim, the simulator from the govmomi project, replays an inventory captured with `govc object.save`, so the real pyVmomi code path can run in CI. Adds: - tests/fixtures/vcsim: the two captures contributed in bb-Ricardo#474, a 6.7.0 and an 8.0.3 vCenter. The tests are parametrized over every archive in that directory, so adding a capture needs no test changes. - tests/conftest.py: starts one vcsim per capture on a free port, gives each test a clean in-memory NetBoxInventory, and feeds the source a generated settings.ini. A second connection through pyVmomi provides an independent view of the same simulator to compare against. - tests/test_vmware_source.py: every VM and host is synced, host serial, model and manufacturer match the hardware, VM cpu and memory match the hypervisor, interface MAC addresses match, guest IPs of VMs with running tools are synced and bound to an interface, two runs produce the same inventory, and a run against objects that already exist in NetBox creates nothing new. - .github/workflows/test.yml: installs vcsim and runs pytest on pushes and pull requests. The suite needs no vCenter and no NetBox. Without vcsim installed the vcsim backed tests skip rather than fail, so `pytest` still works on a machine that only has the Python dependencies. Verified on Python 3.13 (the CI version) and 3.14: 16 passed. To check the tests actually catch regressions, four faults were injected into the source one at a time: memory reported in GB, guest IPs never collected (the shape of bb-Ricardo#476), a VM silently dropped, and the MAC address dropped from interface data. Each one turned the suite red, and it went green again after reverting.
Added a per source config option (
skip_fhrp_group_ips) to prevent FHRP group IP addresses in Netbox from being overridden by their members, as described in issue #445.