Skip to content

Commit 0700363

Browse files
fix(drivers): prefer the logical network name when reporting a port's source
A type='network' interface backed by a libvirt network with <forward mode='bridge'/> (e.g. a boot network riding the same bridge as the main network) gets rewritten by libvirt to type='bridge' in the live domain XML, but its <source> element keeps both the original 'network' attribute and the underlying 'bridge' one. Reading by iface type alone picked up the bridge name, permanently diverging from the target state's logical network name and leaving update_on_dp() stuck logging "Unknown update action" every iteration since no tracked field actually looked different to it.
1 parent 53370ae commit 0700363

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

exordos_core/compute/pool/drivers/libvirt.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@
4141
CONSOLE_LOG_DIR = "/var/log/libvirt/qemu"
4242

4343

44+
def _interface_source(
45+
iface: ET.Element, source_el: tp.Optional[ET.Element]
46+
) -> tp.Optional[str]:
47+
"""Return the logical network/bridge name this interface connects to.
48+
49+
A domain interface created as type='network' backed by a libvirt
50+
network with <forward mode='bridge'/> gets rewritten by libvirt in
51+
the live/persistent XML to type='bridge', but its <source> element
52+
keeps both the original 'network' attribute (the logical name the
53+
orchestrator/target state actually tracks) and the 'bridge' one
54+
(the real underlying device). Prefer 'network' when present so a
55+
boot port riding such a network still reports its logical name
56+
instead of the bridge it happens to be implemented with.
57+
"""
58+
if source_el is None:
59+
return None
60+
return source_el.get("network") or source_el.get(iface.get("type"))
61+
62+
4463
class StoragePoolType(enum.Enum):
4564
DIR = "dir"
4665
ZFS = "zfs"
@@ -611,11 +630,7 @@ def _domain2machine(
611630
mac_el = iface.find("mac")
612631
source_el = iface.find("source")
613632
mac = mac_el.get("address")
614-
# The boot-network port is always type='network' regardless of
615-
# the hypervisor's own network_type (see create_machine) - read
616-
# the source attribute this specific interface actually has
617-
# ('network' or 'bridge'), not the hypervisor's configured type.
618-
source = source_el.get(iface.get("type"))
633+
source = _interface_source(iface, source_el)
619634

620635
if not mac or not source:
621636
raise ValueError(f"Interface {iface} has no mac or source")
@@ -694,9 +709,7 @@ def _list_interfaces(self, machine: models.Machine) -> tp.List[models.Port]:
694709
mac_el = iface.find("mac")
695710
source_el = iface.find("source")
696711
mac = mac_el.get("address")
697-
# See _domain2machine: read the source attribute this specific
698-
# interface actually has, not the hypervisor's network_type.
699-
source = source_el.get(iface.get("type"))
712+
source = _interface_source(iface, source_el)
700713

701714
if not mac or not source:
702715
raise ValueError(f"Interface {iface} has no mac or source")

0 commit comments

Comments
 (0)