fix: put access point IPs into the VRF of the matching tenant prefix instead of always global
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
1352514577
commit
f134db0c16
3 files changed
+52
-5
No files matched your search
@@ -31,6 +31,10 @@ def _matches(record, key, value):
|
||||
vrf = getattr(record, "vrf", None)
|
||||
vrf_id = vrf if isinstance(vrf, int) else getattr(vrf, "id", None)
|
||||
return (vrf_id is None) if value == "null" else vrf_id == value
|
||||
if key == "contains":
|
||||
import ipaddress
|
||||
prefix = getattr(record, "prefix", None)
|
||||
return prefix is not None and ipaddress.ip_address(value) in ipaddress.ip_network(str(prefix), strict=False)
|
||||
if key == "address":
|
||||
return str(getattr(record, "address", "")).split("/")[0] == str(value).split("/")[0]
|
||||
if key.endswith("_id") and not hasattr(record, key):
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import ipaddress
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
@@ -128,3 +129,24 @@ def test_without_tenant_the_whole_netbox_is_searched_and_tenant_comes_from_the_c
|
||||
assert [ap["device"].id if ap["device"] else None for ap in aps] == [102, 101, None]
|
||||
report = engine.sync(aps, {ap_key(aps[2]): {"site": 21, "tenant": 7}}, role_id=30, dry_run=False)
|
||||
assert report["errors"] == [] and nb.dcim.devices.created[-1]["tenant"] == 7
|
||||
|
||||
|
||||
def test_ip_goes_into_the_vrf_of_the_tenant_prefix():
|
||||
nb = _netbox()
|
||||
vrf = nb.ipam.vrfs.create({"name": "Kunde", "tenant": 7})
|
||||
nb.ipam.vrfs.create({"name": "Fremd", "tenant": 999})
|
||||
nb.ipam.prefixes.create({"prefix": "10.0.0.0/8", "vrf": None})
|
||||
nb.ipam.prefixes.create({"prefix": "0.0.0.0/0", "vrf": None})
|
||||
for ap in parse_csv(CSV):
|
||||
if ap["ip"]:
|
||||
network = ipaddress.ip_network(f"{ap['ip']}/24", strict=False)
|
||||
if not nb.ipam.prefixes.filter(prefix=str(network)):
|
||||
nb.ipam.prefixes.create({"prefix": str(network), "vrf": SimpleNamespace(id=vrf.id, name="Kunde")})
|
||||
engine = APSyncEngine(nb)
|
||||
engine.load_context(7)
|
||||
aps = parse_csv(CSV)
|
||||
engine.match(aps)
|
||||
report = engine.sync(aps, {ap_key(aps[2]): {"site": 21}}, role_id=30, dry_run=False)
|
||||
assert report["errors"] == []
|
||||
created = nb.ipam.ip_addresses.created
|
||||
assert created and all(payload["vrf"] == vrf.id and payload["address"].endswith("/24") for payload in created)
|
||||
Reference in new issue
Block a user