diff --git a/CHANGELOG.md b/CHANGELOG.md index 63ff980..0fd0382 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/napalm_proxmox/sdn_mixin.py b/napalm_proxmox/sdn_mixin.py index 80bd327..7568528 100644 --- a/napalm_proxmox/sdn_mixin.py +++ b/napalm_proxmox/sdn_mixin.py @@ -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] diff --git a/tests/test_switch_uplink.py b/tests/test_switch_uplink.py new file mode 100644 index 0000000..d33a68d --- /dev/null +++ b/tests/test_switch_uplink.py @@ -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"}})