File 058-uri-Mock-domcaps-returning-NO_SUPPORT.patch of Package virt-manager

Subject: uri: Mock domcaps returning NO_SUPPORT
From: Cole Robinson crobinso@redhat.com Mon Jan 22 17:07:31 2024 -0500
Date: Mon Jan 22 17:07:31 2024 -0500:
Git: 2e3db754d1d596f8fed6b327017ace922838eb49

With libvirt 9.8.0, the test driver now has a stub getDomainCapabilities
implementation. But we still have some code that needs to handle
a driver with missing domcaps.

Make our magicuri mock return NO_SUPPORT for domcaps, when the URI
doesn't have any domcaps XML passed in. This is enough for our test
purposes.

Signed-off-by: Cole Robinson <crobinso@redhat.com>

diff --git a/virtinst/uri.py b/virtinst/uri.py
index c83aaa78..c4be1960 100644
--- a/virtinst/uri.py
+++ b/virtinst/uri.py
@@ -173,23 +173,39 @@ class MagicURI(object):
             capsxml = open(self.capsfile).read()
             conn.getCapabilities = lambda: capsxml
 
+        def _raise_nosupport_error(msg):
+            import libvirt
+            err = [libvirt.VIR_ERR_NO_SUPPORT, None, msg, None, None, None]
+            exc = libvirt.libvirtError(msg)
+            exc.err = err
+            raise exc
+
         # Fake domcapabilities. This is insufficient since output should
         # vary per type/arch/emulator combo, but it can be expanded later
         # if needed
+        domcapsxml = None
         if self.domcapsfile:
             domcapsxml = open(self.domcapsfile).read()
-            def fake_domcaps(emulator, arch, machine, virttype, flags=0):
-                ignore = emulator
-                ignore = flags
-                ignore = machine
-                ignore = virttype
 
+        def fake_domcaps(emulator, arch, machine, virttype, flags=0):
+            ignore = emulator
+            ignore = flags
+            ignore = machine
+            ignore = virttype
+
+            if domcapsxml:
                 ret = domcapsxml
                 if arch:
                     ret = re.sub("arch>.+</arch", "arch>%s</arch" % arch, ret)
                 return ret
 
-            conn.getDomainCapabilities = fake_domcaps
+            # In libvirt 9.8.0 the test suite added a stub domcaps
+            # impl. Fall back to raising NO_SUPPORT for our magic URIs, so
+            # we can keep getting code coverage of the old code paths
+            _raise_nosupport_error(
+                    "virtinst test driver fake domcaps nosupport")
+
+        conn.getDomainCapabilities = fake_domcaps
 
         if self.fakeuri:
             origcreate = conn.createXML
openSUSE Build Service is sponsored by