File 045-virtinst-delay-lookup_capsinfo-until-we-really-need-it.patch of Package virt-manager

Subject: virtinst: delay "lookup_capsinfo" until we really need it
From: Laszlo Ersek lersek@redhat.com Sat Aug 26 13:00:16 2023 +0200
Date: Tue Aug 29 13:24:52 2023 +0200:
Git: 4ead4acb440e132c84f2e73365a1e419279d9fb9

When I try to open the details window for a domain that does not use the
system default emulator, I get the following exception:

> Traceback (most recent call last):
>   File "virtManager/vmwindow.py", line 40, in get_instance
>     cls._instances[key] = vmmVMWindow(vm)
>   File "virtManager/vmwindow.py", line 83, in __init__
>     self._details = vmmDetails(self.vm, self.builder, self.topwin,
>   File "virtManager/details/details.py", line 389, in __init__
>     self._init_details()
>   File "virtManager/details/details.py", line 807, in _init_details
>     vmmAddHardware.build_video_combo(self.vm, video_dev)
>   File "virtManager/addhardware.py", line 816, in build_video_combo
>     default = DeviceVideo.default_model(vm.xmlobj)
>   File "virtinst/devices/video.py", line 47, in default_model
>     if (guest.lookup_domcaps().supports_video_virtio() and
>   File "virtinst/guest.py", line 656, in lookup_domcaps
>     if not self._domcaps or not _compare(self._domcaps):
>   File "virtinst/guest.py", line 646, in _compare
>     if self.os.machine and not _compare_machine(domcaps):
>   File "virtinst/guest.py", line 633, in _compare_machine
>     capsinfo = self.lookup_capsinfo()
>   File "virtinst/guest.py", line 674, in lookup_capsinfo
>     self._capsinfo = self.conn.caps.guest_lookup(
>   File "virtinst/capabilities.py", line 319, in guest_lookup
>     raise ValueError(msg)
> ValueError: Host does not support domain type kvm with machine
> 'pc-q35-8.1' for virtualization type 'hvm' with architecture 'x86_64'

This is a regression; according to git-bisect, it was introduced in commit
05fcc7410eee ("virtinst: fix caching of domain capabilities", 2022-07-27).

"lookup_capsinfo" (and "guest_lookup" called by it) are unsuitable for
machine type alias checking (or for anything else) if the domain uses an
emulator that differs from the system default emulator. The information
returned by virConnectGetCapabilities() pertains to the system default
emulator. Thus, when using a non-default emulator, we should either not
call "lookup_capsinfo" for machine type alias checking, *or* we should
suppress the exception, and pretend that the alias check was a mismatch.

It turns out that we can avoid the "lookup_capsinfo" call (and thereby the
exception) in practice if we just delay the call until after the direct
(non-alias) comparison.

Fixes: #539
Fixes: 05fcc7410eee ("virtinst: fix caching of domain capabilities", 2022-07-27)
Signed-off-by: Laszlo Ersek <lersek@redhat.com>

diff --git a/virtinst/guest.py b/virtinst/guest.py
index 123abfb2..9232405b 100644
--- a/virtinst/guest.py
+++ b/virtinst/guest.py
@@ -630,9 +630,9 @@ class Guest(XMLBuilder):
 
     def lookup_domcaps(self):
         def _compare_machine(domcaps):
-            capsinfo = self.lookup_capsinfo()
             if self.os.machine == domcaps.machine:
                 return True
+            capsinfo = self.lookup_capsinfo()
             if capsinfo.is_machine_alias(self.os.machine, domcaps.machine):
                 return True
             return False
openSUSE Build Service is sponsored by