fix: ignore wireless interfaces when looking for the far end of a cable
NetBox does not allow cables on wireless interfaces; wlan1 made "LAN1" on a LANCOM LW-600 (eth1, wlan0, wlan1) ambiguous and prevented the single-port rule. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
823d968b33
commit
144e5f9eb8
2 files changed
+28
-2
No files matched your search
@@ -1095,6 +1095,14 @@ def _physical_record(record):
|
|||||||
and not re.match(r"^(?:vlan|lo|mgmt|oobm)", interface_key(record.name)))
|
and not re.match(r"^(?:vlan|lo|mgmt|oobm)", interface_key(record.name)))
|
||||||
|
|
||||||
|
|
||||||
|
# NetBox does not allow cables on wireless interfaces (Wi-Fi, LTE/5G, Bluetooth …).
|
||||||
|
_WIRELESS_TYPE = re.compile(r"^(?:ieee802\.1[15]|other-wireless|gsm|cdma|lte|4g|5g)")
|
||||||
|
|
||||||
|
|
||||||
|
def _cableable_record(record):
|
||||||
|
return _physical_record(record) and not _WIRELESS_TYPE.match(_record_type(record))
|
||||||
|
|
||||||
|
|
||||||
def _physical_interface(interface):
|
def _physical_interface(interface):
|
||||||
return netbox_interface_type(interface) not in ("virtual", "lag")
|
return netbox_interface_type(interface) not in ("virtual", "lag")
|
||||||
|
|
||||||
@@ -1538,7 +1546,7 @@ class _RemoteLookup:
|
|||||||
number = _port_number(neighbor.get("remote_port"))
|
number = _port_number(neighbor.get("remote_port"))
|
||||||
if number is not None:
|
if number is not None:
|
||||||
found = [record for record in records.values()
|
found = [record for record in records.values()
|
||||||
if _physical_record(record) and _port_number(record.name) == number]
|
if _cableable_record(record) and _port_number(record.name) == number]
|
||||||
if len(found) == 1:
|
if len(found) == 1:
|
||||||
return found[0]
|
return found[0]
|
||||||
# Access points and phones often report their MAC address as port ID.
|
# Access points and phones often report their MAC address as port ID.
|
||||||
@@ -1550,7 +1558,7 @@ class _RemoteLookup:
|
|||||||
return found[0]
|
return found[0]
|
||||||
# An end device with a single port (e.g. an AP from the Sophos import) can only be cabled there.
|
# An end device with a single port (e.g. an AP from the Sophos import) can only be cabled there.
|
||||||
physical = [record for record in records.values()
|
physical = [record for record in records.values()
|
||||||
if _physical_record(record) and not getattr(record, "mgmt_only", False)]
|
if _cableable_record(record) and not getattr(record, "mgmt_only", False)]
|
||||||
return physical[0] if len(physical) == 1 else None
|
return physical[0] if len(physical) == 1 else None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -622,3 +622,21 @@ def test_skipped_cables_are_explained():
|
|||||||
switch["neighbor_devices"] = {"1/1/2": 0} # "no cable" is chosen deliberately: no note
|
switch["neighbor_devices"] = {"1/1/2": 0} # "no cable" is chosen deliberately: no note
|
||||||
report = sync_snapshot_to_netbox(nb, switch, snapshot, dry_run=True)
|
report = sync_snapshot_to_netbox(nb, switch, snapshot, dry_run=True)
|
||||||
assert not any("übersprungen" in note for note in report["notes"])
|
assert not any("übersprungen" in note for note in report["notes"])
|
||||||
|
|
||||||
|
|
||||||
|
def test_wireless_interfaces_are_no_cable_targets():
|
||||||
|
"""LANCOM LW-600: eth1 plus wlan0/wlan1; LLDP reports "LAN1" – wlan1 must not make it ambiguous."""
|
||||||
|
nb, switch, snapshot = _numbered_setup()
|
||||||
|
nb.dcim.devices.records.append(Record(nb.dcim.devices, id=5, name="AP-005", tenant=SimpleNamespace(id=7)))
|
||||||
|
nb.dcim.interfaces.records += [
|
||||||
|
Record(nb.dcim.interfaces, id=50, name="eth1", device=SimpleNamespace(id=5), mac_address=None,
|
||||||
|
type=SimpleNamespace(value="1000base-t"), enabled=True, cable=None),
|
||||||
|
Record(nb.dcim.interfaces, id=51, name="wlan0", device=SimpleNamespace(id=5), mac_address=None,
|
||||||
|
type=SimpleNamespace(value="ieee802.11ax"), enabled=True, cable=None),
|
||||||
|
Record(nb.dcim.interfaces, id=52, name="wlan1", device=SimpleNamespace(id=5), mac_address=None,
|
||||||
|
type=SimpleNamespace(value="ieee802.11ax"), enabled=True, cable=None),
|
||||||
|
]
|
||||||
|
snapshot["neighbors"][0].update(system_name="AP-005", remote_port="LAN1", port_description="LAN1")
|
||||||
|
report = sync_snapshot_to_netbox(nb, switch, snapshot)
|
||||||
|
assert report["errors"] == []
|
||||||
|
assert nb.dcim.cables.created[0]["b_terminations"] == [{"object_type": "dcim.interface", "object_id": 50}]
|
||||||
Reference in new issue
Block a user