[PATCH] qemuxml2xmltest: Set dummy non-hypervisor drivers

Michal Privoznik posted 1 patch 2 weeks ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/6b542ec87d83dfb1e45f32afc6d4c3d99d2f6268.1593095879.git.mprivozn@redhat.com
tests/qemuxml2xmltest.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

[PATCH] qemuxml2xmltest: Set dummy non-hypervisor drivers

Posted by Michal Privoznik 2 weeks ago
When parsing domain XML post parse callbacks are run and one of
them might try and call API from a non-hypervisor driver (e.g.
just like qemuDomainDeviceNetDefPostParse() is doing - it calls a
network API). To avoid this in the test suite, set dummy drivers,
which renders all non-hypervisor APIs return error.

This mimics what qemuxml2argvtest does.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 tests/qemuxml2xmltest.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 5a124853b4..11ff17d83c 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -135,6 +135,7 @@ mymain(void)
     char *fakerootdir;
     virQEMUDriverConfigPtr cfg = NULL;
     virHashTablePtr capslatest = NULL;
+    g_autoptr(virConnect) conn = NULL;
 
     capslatest = testQemuGetLatestCaps();
     if (!capslatest)
@@ -164,6 +165,16 @@ mymain(void)
     cfg = virQEMUDriverGetConfig(&driver);
     driver.privileged = true;
 
+    if (!(conn = virGetConnect()))
+        goto cleanup;
+
+    virSetConnectInterface(conn);
+    virSetConnectNetwork(conn);
+    virSetConnectNWFilter(conn);
+    virSetConnectNodeDev(conn);
+    virSetConnectSecret(conn);
+    virSetConnectStorage(conn);
+
 # define DO_TEST_INTERNAL(_name, suffix, when, ...) \
     do { \
         static struct testQemuInfo info = { \
@@ -1471,6 +1482,7 @@ mymain(void)
     DO_TEST_CAPS_LATEST("virtio-9p-multidevs");
     DO_TEST("downscript", NONE);
 
+ cleanup:
     if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
         virFileDeleteTree(fakerootdir);
 
-- 
2.26.2

Re: [PATCH] qemuxml2xmltest: Set dummy non-hypervisor drivers

Posted by Daniel P. Berrangé 2 weeks ago
On Thu, Jun 25, 2020 at 04:37:59PM +0200, Michal Privoznik wrote:
> When parsing domain XML post parse callbacks are run and one of
> them might try and call API from a non-hypervisor driver (e.g.
> just like qemuDomainDeviceNetDefPostParse() is doing - it calls a
> network API). To avoid this in the test suite, set dummy drivers,
> which renders all non-hypervisor APIs return error.
> 
> This mimics what qemuxml2argvtest does.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  tests/qemuxml2xmltest.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>




Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|