From 5f7fb4ed66d0e1d4e10d684ce2bcde9b99d1d71d Mon Sep 17 00:00:00 2001 From: catborise Date: Sun, 8 Nov 2026 12:06:37 +0300 Subject: [PATCH] perf(vrtManager): the domain capabilities and each pool's XML are parsed once get_dom_capabilities() parsed the same domain capabilities XML for each of its 14 reads, and the pool list parsed each pool's XML for its type, its path and its source name. Each is now parsed once and read with get_xpath(). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea --- vrtManager/connection.py | 32 ++++++++++++++--------------- vrtManager/storage.py | 7 ++++--- vrtManager/tests/test_host_reads.py | 13 ++++++++++++ 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/vrtManager/connection.py b/vrtManager/connection.py index 39f4201e..2490bf1d 100644 --- a/vrtManager/connection.py +++ b/vrtManager/connection.py @@ -540,15 +540,15 @@ class wvmConnect(object): """Return domain capabilities""" result = dict() - xml = self.get_dom_cap_xml(arch, machine) - result["path"] = util.get_xml_path(xml, "/domainCapabilities/path") - result["domain"] = util.get_xml_path(xml, "/domainCapabilities/domain") - result["machine"] = util.get_xml_path(xml, "/domainCapabilities/machine") - result["vcpu_max"] = util.get_xml_path(xml, "/domainCapabilities/vcpu/@max") - result["iothreads_support"] = util.get_xml_path(xml, "/domainCapabilities/iothreads/@supported") - result["os_support"] = util.get_xml_path(xml, "/domainCapabilities/os/@supported") + doc = etree.fromstring(self.get_dom_cap_xml(arch, machine)) + result["path"] = util.get_xpath(doc, "/domainCapabilities/path") + result["domain"] = util.get_xpath(doc, "/domainCapabilities/domain") + result["machine"] = util.get_xpath(doc, "/domainCapabilities/machine") + result["vcpu_max"] = util.get_xpath(doc, "/domainCapabilities/vcpu/@max") + result["iothreads_support"] = util.get_xpath(doc, "/domainCapabilities/iothreads/@supported") + result["os_support"] = util.get_xpath(doc, "/domainCapabilities/os/@supported") - result["loader_support"] = util.get_xml_path(xml, "/domainCapabilities/os/loader/@supported") + result["loader_support"] = util.get_xpath(doc, "/domainCapabilities/os/loader/@supported") if result["loader_support"] == "yes": result["loaders"] = self.get_os_loaders(arch, machine) result["loader_enums"] = self.get_os_loader_enums(arch, machine) @@ -558,27 +558,25 @@ class wvmConnect(object): # supported and unknown cpu models result["cpu_custom_models"] = self.get_cpu_custom_types(arch, machine) - result["disk_support"] = util.get_xml_path(xml, "/domainCapabilities/devices/disk/@supported") + result["disk_support"] = util.get_xpath(doc, "/domainCapabilities/devices/disk/@supported") if result["disk_support"] == "yes": result["disk_devices"] = self.get_disk_device_types(arch, machine) result["disk_bus"] = self.get_disk_bus_types(arch, machine) - result["video_support"] = util.get_xml_path(xml, "/domainCapabilities/devices/video/@supported") + result["video_support"] = util.get_xpath(doc, "/domainCapabilities/devices/video/@supported") if result["video_support"] == "yes": result["video_types"] = self.get_video_models(arch, machine) - result["hostdev_support"] = util.get_xml_path(xml, "/domainCapabilities/devices/hostdev/@supported") + result["hostdev_support"] = util.get_xpath(doc, "/domainCapabilities/devices/hostdev/@supported") if result["hostdev_support"] == "yes": result["hostdev_types"] = self.get_hostdev_modes(arch, machine) result["hostdev_startup_policies"] = self.get_hostdev_startup_policies(arch, machine) result["hostdev_subsys_types"] = self.get_hostdev_subsys_types(arch, machine) - result["features_gic_support"] = util.get_xml_path(xml, "/domainCapabilities/features/gic/@supported") - result["features_genid_support"] = util.get_xml_path(xml, "/domainCapabilities/features/genid/@supported") - result["features_vmcoreinfo_support"] = util.get_xml_path( - xml, "/domainCapabilities/features/vmcoreinfo/@supported" - ) - result["features_sev_support"] = util.get_xml_path(xml, "/domainCapabilities/features/sev/@supported") + result["features_gic_support"] = util.get_xpath(doc, "/domainCapabilities/features/gic/@supported") + result["features_genid_support"] = util.get_xpath(doc, "/domainCapabilities/features/genid/@supported") + result["features_vmcoreinfo_support"] = util.get_xpath(doc, "/domainCapabilities/features/vmcoreinfo/@supported") + result["features_sev_support"] = util.get_xpath(doc, "/domainCapabilities/features/sev/@supported") return result diff --git a/vrtManager/storage.py b/vrtManager/storage.py index d63738dc..1713c827 100644 --- a/vrtManager/storage.py +++ b/vrtManager/storage.py @@ -2,6 +2,7 @@ from django.utils.translation import gettext_noop import contextlib import libvirt +from lxml import etree from vrtManager import util from vrtManager.connection import wvmConnect @@ -35,7 +36,7 @@ class wvmStorages(wvmConnect): if stg_status: with contextlib.suppress(libvirt.libvirtError): # refused while a volume is cloned in it stg.refresh(0) - xml = stg.XMLDesc(0) + doc = etree.fromstring(stg.XMLDesc(0)) stg_vol = len(stg.listVolumes()) if stg_status else None _state, stg_size, _allocation, stg_free = stg.info() storages.append( @@ -43,8 +44,8 @@ class wvmStorages(wvmConnect): "name": pool, "status": stg_status, "autostart": stg.autostart(), - "type": util.get_xml_path(xml, "/pool/@type"), - "path": util.get_xml_path(xml, "/pool/target/path") or util.get_xml_path(xml, "/pool/source/name"), + "type": doc.get("type"), + "path": util.get_xpath(doc, "/pool/target/path") or util.get_xpath(doc, "/pool/source/name"), "volumes": stg_vol, "size": stg_size, "free": stg_free, diff --git a/vrtManager/tests/test_host_reads.py b/vrtManager/tests/test_host_reads.py index adcec488..5da67f07 100644 --- a/vrtManager/tests/test_host_reads.py +++ b/vrtManager/tests/test_host_reads.py @@ -91,6 +91,19 @@ class CapabilitiesOnceTestCase(unittest.TestCase): ["capabilities", ("/usr/bin/qemu-kvm", "x86_64", "q35", "kvm"), ("/usr/bin/qemu-kvm", "x86_64", "pc", "kvm")], ) + def test_the_domain_capabilities_are_read_from_their_xml(self): + conn = connection() + conn.wvm.getDomainCapabilities = lambda *key: ( + "/usr/bin/qemu-kvmkvmpc-q35-9.0" + "" + "" + "") + caps = conn.get_dom_capabilities("x86_64", "q35") + self.assertEqual((caps["path"], caps["domain"], caps["machine"], caps["vcpu_max"]), + ("/usr/bin/qemu-kvm", "kvm", "pc-q35-9.0", "4096")) + self.assertEqual((caps["iothreads_support"], caps["loader_support"], caps["features_genid_support"]), + ("yes", "no", None)) + def test_an_architecture_the_host_does_not_run_is_refused_with_its_name(self): # the create page and the API take it from the URL: it was a KeyError, a 500 with self.assertRaisesRegex(util.OperationError, "This host has no architecture noarch"):