fix(sdn): restore the virtual interface prefixes for set_vlan

b1ba991 removed _VIRTUAL_IFACE_PREFIXES while _is_physical_uplink still
read it. The AttributeError was swallowed by _find_switch_uplink, so
set_vlan never found an uplink on any node. Restore the constant and
cover both helpers with tests.

Closes #37
This commit is contained in:
Christian Manivong committed 2026-11-01 21:43:09 +01:00
1 parent cb29a42c31
commit d142db73e5
3 files changed
+71

No files matched your search

+2
View File
@@ -40,6 +40,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `get_ipv6_neighbors_table()` reports an unknown age as `-1.0`, as `get_arp_table()`
already did (napalm-device-types' `ARP_AGE_UNKNOWN`), instead of `0.0`, which
means "confirmed just now" (NetOrk/netork#1327).
- `set_vlan()` finds the node's switch uplink again. Since 0.8.0 every call failed
with "no LLDP-detected switch uplink found", whatever LLDP reported (#37).
## [0.8.0] - 2026-10-23
+11
View File
@@ -33,6 +33,17 @@ _JsonDict = dict[str, Any]
class ProxmoxSDNMixin:
"""Mixin providing SDN, VLAN and network-instance NAPALM methods."""
#: Name prefixes of Proxmox-internal and runtime virtual interfaces, never a switch uplink.
_VIRTUAL_IFACE_PREFIXES: tuple[str, ...] = (
"fwpr", # Proxmox firewall proxy veth
"fwln", # Proxmox firewall link veth
"tap", # VM tap devices
"veth", # generic veth pairs (containers)
"virbr", # libvirt bridges
"docker", # Docker virtual interfaces
"lxcbr", # LXC bridges
)
def _get_sdn_zones(self) -> list[_JsonDict]:
try:
return self._api.cluster.sdn.zones.get() or [] # type: ignore[union-attr]
+58
View File
@@ -0,0 +1,58 @@
"""The physical port set_vlan configures: _find_switch_uplink / _is_physical_uplink."""
from __future__ import annotations
from unittest.mock import MagicMock
from napalm_proxmox.sdn_mixin import ProxmoxSDNMixin
NETWORK = [
{"iface": "eno1", "type": "eth"},
{"iface": "vmbr0", "type": "bridge", "bridge_ports": "eno1"},
]
def _mixin(detail: dict, basic: dict) -> ProxmoxSDNMixin:
m = ProxmoxSDNMixin()
m._get_node_network = MagicMock(return_value=NETWORK)
m.get_lldp_neighbors_detail = MagicMock(return_value=detail)
m.get_lldp_neighbors = MagicMock(return_value=basic)
return m
class TestFindSwitchUplink:
def test_physical_port_with_a_bridge_neighbour_is_the_uplink(self):
m = _mixin(
detail={
"tap100i0": [{"remote_system_capab": ["bridge"]}],
"eno1": [{"remote_system_capab": ["bridge", "router"]}],
},
basic={},
)
assert m._find_switch_uplink() == "eno1"
def test_basic_lldp_fallback_skips_a_virtual_port(self):
m = _mixin(
detail={},
basic={"fwpr100p0": [{"hostname": "sw"}], "eno1": [{"hostname": "sw"}]},
)
assert m._find_switch_uplink() == "eno1"
def test_no_physical_neighbour_is_none(self):
m = _mixin(detail={"tap100i0": [{"remote_system_capab": ["bridge"]}]}, basic={})
assert m._find_switch_uplink() is None
class TestIsPhysicalUplink:
def test_eth_in_the_network_config_is_physical(self):
assert ProxmoxSDNMixin()._is_physical_uplink("eno1", {"eno1": {"type": "eth"}})
def test_virtual_prefix_is_never_physical(self):
network = {"tap100i0": {"type": ""}}
assert not ProxmoxSDNMixin()._is_physical_uplink("tap100i0", network)
def test_port_missing_from_the_network_config_is_not_physical(self):
assert not ProxmoxSDNMixin()._is_physical_uplink("eno9", {})
def test_bridge_is_not_physical(self):
assert not ProxmoxSDNMixin()._is_physical_uplink("vmbr0", {"vmbr0": {"type": "bridge"}})