From 4ea002f5a359dd9737927180d128621922782582 Mon Sep 17 00:00:00 2001 From: catborise Date: Fri, 9 Oct 2026 21:11:38 +0300 Subject: [PATCH] perf(interfaces): list only the host's network devices The interfaces page read the XML of every node device (183 on a test host) to keep the network ones; libvirt now lists only those. Same names on both test hosts, 756 -> 261 ms over TCP and 475 -> 173 ms over SSH. --- vrtManager/connection.py | 18 +++++------------- vrtManager/test_host_reads.py | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/vrtManager/connection.py b/vrtManager/connection.py index 81a35cbd..d340432d 100644 --- a/vrtManager/connection.py +++ b/vrtManager/connection.py @@ -959,19 +959,11 @@ class wvmConnect(object): return instance def get_net_devices(self): - netdevice = [] - - def get_info(doc): - dev_type = util.get_xpath(doc, "/device/capability/@type") - interface = util.get_xpath(doc, "/device/capability/interface") - return dev_type, interface - - for dev in self.wvm.listAllDevices(0): - xml = dev.XMLDesc(0) - (dev_type, interface) = util.get_xml_path(xml, func=get_info) - if dev_type == "net": - netdevice.append(interface) - return netdevice + """The host's network interface names; libvirt lists only the network devices""" + return [ + util.get_xml_path(dev.XMLDesc(0), "/device/capability/interface") + for dev in self.wvm.listAllDevices(libvirt.VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET) + ] def get_host_instances(self, raw_mem_size=False): vname = {} diff --git a/vrtManager/test_host_reads.py b/vrtManager/test_host_reads.py index 54e6ab93..70b09170 100644 --- a/vrtManager/test_host_reads.py +++ b/vrtManager/test_host_reads.py @@ -1,15 +1,18 @@ """A wvmConnect reads the host's info and capabilities once, and its domain capabilities once per emulator, arch, machine and domain type: the create page's getters parse the capabilities some 60 times, the overview reads the -info four times. An object lives for one request.""" +info four times. An object lives for one request. The interfaces page lists +only the host's network devices, not all of them.""" import unittest +from unittest.mock import MagicMock from django.conf import settings if not settings.configured: settings.configure(MAC_OUI="52:54:10") +from libvirt import VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET from vrtManager.connection import wvmConnect from vrtManager.hostdetails import wvmHostDetails @@ -97,3 +100,17 @@ class CapabilitiesOnceTestCase(unittest.TestCase): conn.wvm = FakeConn() conn.get_cap_xml() self.assertEqual(conn.wvm.reads, ["capabilities"]) + + +class NetDevicesTestCase(unittest.TestCase): + def test_only_the_network_devices_are_listed_and_read(self): + conn = connection() + devices = { + VIR_CONNECT_LIST_NODE_DEVICES_CAP_NET: [ + MagicMock(**{"XMLDesc.return_value": f"{name}" + ""}) + for name in ("eth0", "br0") + ] + } + conn.wvm.listAllDevices = lambda flags: devices.get(flags, []) + self.assertEqual(conn.get_net_devices(), ["eth0", "br0"])