[libvirt PATCH] Revert "tests: Use qemu:///embed to simplify fakerootdir management"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Turns out that it's not enough to pass the qemu:///embed root to
virQEMUDriverConfigNew(), you also have to make sure the same
string is copied into the virQEMUDriver structure yourself, and
not doing so in our case resulted in the cleanup never happening
and in distcheck failing because of that.

On the other hand, actually setting config->embeddedRoot would
result in different paths being generated for each test run, which
would obviously break qemuxml2argvtest, so that's not an option
either.

This reverts commit d98cc1968e7961cb02ed07406451a7b710cc2f24.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
Pushed as a CI fix yesterday, forgot to forward it to the list.

 tests/qemuhotplugtest.c  | 15 ++++++++++++++
 tests/qemumemlocktest.c  | 20 ++++++++++++++++++-
 tests/qemuxml2argvtest.c | 16 +++++++++++++++
 tests/qemuxml2xmltest.c  | 16 +++++++++++++++
 tests/testutilsqemu.c    | 43 ++++++++++++++++++++++++++--------------
 5 files changed, 94 insertions(+), 16 deletions(-)

diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index a67b6ce607..cf87de187f 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -594,6 +594,8 @@ testQemuHotplugCpuIndividual(const void *opaque)
     return ret;
 }
 
+#define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
+
 
 static int
 mymain(void)
@@ -602,8 +604,18 @@ mymain(void)
     int ret = 0;
     struct qemuHotplugTestData data = {0};
     struct testQemuHotplugCpuParams cpudata;
+    g_autofree char *fakerootdir = NULL;
     g_autoptr(virQEMUDriverConfig) cfg = NULL;
 
+    fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
+
+    if (!g_mkdtemp(fakerootdir)) {
+        fprintf(stderr, "Cannot create fakerootdir");
+        abort();
+    }
+
+    g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
+
     if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
 
@@ -879,6 +891,9 @@ mymain(void)
     DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "16-22", true, true, true);
     DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "17", true, true, true);
 
+    if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
+        virFileDeleteTree(fakerootdir);
+
     qemuTestDriverFree(&driver);
     virObjectUnref(data.vm);
     return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c
index 4813c7beb0..3f18fed1c3 100644
--- a/tests/qemumemlocktest.c
+++ b/tests/qemumemlocktest.c
@@ -51,14 +51,28 @@ testCompareMemLock(const void *data)
     return ret;
 }
 
+# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
+
 static int
 mymain(void)
 {
     int ret = 0;
+    char *fakerootdir;
     virQEMUCapsPtr qemuCaps = NULL;
 
-    if (qemuTestDriverInit(&driver) < 0)
+    fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
+
+    if (!g_mkdtemp(fakerootdir)) {
+        fprintf(stderr, "Cannot create fakerootdir");
+        abort();
+    }
+
+    g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
+
+    if (qemuTestDriverInit(&driver) < 0) {
+        VIR_FREE(fakerootdir);
         return EXIT_FAILURE;
+    }
 
     driver.privileged = true;
 
@@ -136,7 +150,11 @@ mymain(void)
  cleanup:
     virObjectUnref(qemuCaps);
 
+    if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
+        virFileDeleteTree(fakerootdir);
+
     qemuTestDriverFree(&driver);
+    VIR_FREE(fakerootdir);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 8bd6102d26..04febd1b0c 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -609,12 +609,24 @@ testInfoSetPaths(struct testQemuInfo *info,
                                     abs_srcdir, info->name, suffix ? suffix : "");
 }
 
+# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
+
 static int
 mymain(void)
 {
     int ret = 0;
+    char *fakerootdir;
     virHashTablePtr capslatest = NULL;
 
+    fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
+
+    if (!g_mkdtemp(fakerootdir)) {
+        fprintf(stderr, "Cannot create fakerootdir");
+        abort();
+    }
+
+    g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
+
     /* Set the timezone because we are mocking the time() function.
      * If we don't do that, then localtime() may return unpredictable
      * results. In order to detect things that just work by a blind
@@ -3220,8 +3232,12 @@ mymain(void)
 
     DO_TEST_CAPS_LATEST("virtio-9p-multidevs");
 
+    if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
+        virFileDeleteTree(fakerootdir);
+
     VIR_FREE(driver.config->nbdTLSx509certdir);
     qemuTestDriverFree(&driver);
+    VIR_FREE(fakerootdir);
     virHashFree(capslatest);
     virFileWrapperClearPrefixes();
 
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 6a0adab603..86f3d2c1f3 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -126,10 +126,13 @@ testInfoSetStatusPaths(struct testQemuInfo *info)
 }
 
 
+# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
+
 static int
 mymain(void)
 {
     int ret = 0;
+    char *fakerootdir;
     virQEMUDriverConfigPtr cfg = NULL;
     virHashTablePtr capslatest = NULL;
 
@@ -137,6 +140,15 @@ mymain(void)
     if (!capslatest)
         return EXIT_FAILURE;
 
+    fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
+
+    if (!g_mkdtemp(fakerootdir)) {
+        fprintf(stderr, "Cannot create fakerootdir");
+        abort();
+    }
+
+    g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
+
     /* Required for tpm-emulator tests
      */
     virFileWrapperAddPrefix(SYSCONFDIR "/qemu/firmware",
@@ -1466,8 +1478,12 @@ mymain(void)
 
     DO_TEST_CAPS_LATEST("virtio-9p-multidevs");
 
+    if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
+        virFileDeleteTree(fakerootdir);
+
     virHashFree(capslatest);
     qemuTestDriverFree(&driver);
+    VIR_FREE(fakerootdir);
     virFileWrapperClearPrefixes();
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index c7983f0014..9f9eb4033c 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -307,10 +307,11 @@ qemuTestParseCapabilitiesArch(virArch arch,
 
 void qemuTestDriverFree(virQEMUDriver *driver)
 {
-    if (g_getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
-        virFileDeleteTree(driver->embeddedRoot);
-
     virMutexDestroy(&driver->lock);
+    if (driver->config) {
+        virFileDeleteTree(driver->config->stateDir);
+        virFileDeleteTree(driver->config->configDir);
+    }
     virObjectUnref(driver->qemuCapsCache);
     virObjectUnref(driver->xmlopt);
     virObjectUnref(driver->caps);
@@ -369,21 +370,14 @@ int qemuTestCapsCacheInsert(virFileCachePtr cache,
 }
 
 
-# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
+# define STATEDIRTEMPLATE abs_builddir "/qemustatedir-XXXXXX"
+# define CONFIGDIRTEMPLATE abs_builddir "/qemuconfigdir-XXXXXX"
 
 int qemuTestDriverInit(virQEMUDriver *driver)
 {
     virSecurityManagerPtr mgr = NULL;
-    g_autofree char *fakerootdir = NULL;
-
-    fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
-
-    if (!g_mkdtemp(fakerootdir)) {
-        fprintf(stderr, "Cannot create fakerootdir");
-        abort();
-    }
-
-    g_setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, TRUE);
+    char statedir[] = STATEDIRTEMPLATE;
+    char configdir[] = CONFIGDIRTEMPLATE;
 
     memset(driver, 0, sizeof(*driver));
 
@@ -397,16 +391,35 @@ int qemuTestDriverInit(virQEMUDriver *driver)
         return -1;
 
     driver->hostarch = virArchFromHost();
-    driver->config = virQEMUDriverConfigNew(false, fakerootdir);
+    driver->config = virQEMUDriverConfigNew(false, NULL);
     if (!driver->config)
         goto error;
 
+    /* Do this early so that qemuTestDriverFree() doesn't see (unlink) the real
+     * dirs. */
+    VIR_FREE(driver->config->stateDir);
+    VIR_FREE(driver->config->configDir);
+
     /* Overwrite some default paths so it's consistent for tests. */
     VIR_FREE(driver->config->libDir);
     VIR_FREE(driver->config->channelTargetDir);
     driver->config->libDir = g_strdup("/tmp/lib");
     driver->config->channelTargetDir = g_strdup("/tmp/channel");
 
+    if (!g_mkdtemp(statedir)) {
+        fprintf(stderr, "Cannot create fake stateDir");
+        goto error;
+    }
+
+    driver->config->stateDir = g_strdup(statedir);
+
+    if (!g_mkdtemp(configdir)) {
+        fprintf(stderr, "Cannot create fake configDir");
+        goto error;
+    }
+
+    driver->config->configDir = g_strdup(configdir);
+
     driver->caps = testQemuCapsInit();
     if (!driver->caps)
         goto error;
-- 
2.25.4





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux