1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-08 12:06:37 +03:00
parent a1f90ec98c
commit 5f7fb4ed66
3 changed files with 32 additions and 20 deletions

View file

@ -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

View file

@ -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,

View file

@ -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: (
"<domainCapabilities><path>/usr/bin/qemu-kvm</path><domain>kvm</domain><machine>pc-q35-9.0</machine>"
"<vcpu max='4096'/><iothreads supported='yes'/><os supported='yes'><loader supported='no'/></os>"
"<devices><disk supported='no'/><video supported='no'/><hostdev supported='no'/></devices>"
"<features><gic supported='no'/><sev supported='no'/></features></domainCapabilities>")
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"):