mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
tests: Use qemu:///embed to simplify fakerootdir management
Now that the QEMU driver natively supports storing all its runtime data inside an arbitrary directory, we can avoid having multiple copies of the same logic in the test suite. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
f28fbb05d3
commit
d98cc1968e
@ -594,8 +594,6 @@ testQemuHotplugCpuIndividual(const void *opaque)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
|
||||
|
||||
|
||||
static int
|
||||
mymain(void)
|
||||
@ -604,18 +602,8 @@ 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;
|
||||
|
||||
@ -891,9 +879,6 @@ 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;
|
||||
|
@ -51,28 +51,14 @@ testCompareMemLock(const void *data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
|
||||
|
||||
static int
|
||||
mymain(void)
|
||||
{
|
||||
int ret = 0;
|
||||
char *fakerootdir;
|
||||
virQEMUCapsPtr qemuCaps = 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) {
|
||||
VIR_FREE(fakerootdir);
|
||||
if (qemuTestDriverInit(&driver) < 0)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
driver.privileged = true;
|
||||
|
||||
@ -150,11 +136,7 @@ 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;
|
||||
}
|
||||
|
@ -609,24 +609,12 @@ 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
|
||||
@ -3232,12 +3220,8 @@ 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();
|
||||
|
||||
|
@ -126,13 +126,10 @@ 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;
|
||||
|
||||
@ -140,15 +137,6 @@ 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",
|
||||
@ -1478,12 +1466,8 @@ 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;
|
||||
|
@ -307,11 +307,10 @@ 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);
|
||||
@ -370,14 +369,21 @@ int qemuTestCapsCacheInsert(virFileCachePtr cache,
|
||||
}
|
||||
|
||||
|
||||
# define STATEDIRTEMPLATE abs_builddir "/qemustatedir-XXXXXX"
|
||||
# define CONFIGDIRTEMPLATE abs_builddir "/qemuconfigdir-XXXXXX"
|
||||
# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
|
||||
|
||||
int qemuTestDriverInit(virQEMUDriver *driver)
|
||||
{
|
||||
virSecurityManagerPtr mgr = NULL;
|
||||
char statedir[] = STATEDIRTEMPLATE;
|
||||
char configdir[] = CONFIGDIRTEMPLATE;
|
||||
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);
|
||||
|
||||
memset(driver, 0, sizeof(*driver));
|
||||
|
||||
@ -391,35 +397,16 @@ int qemuTestDriverInit(virQEMUDriver *driver)
|
||||
return -1;
|
||||
|
||||
driver->hostarch = virArchFromHost();
|
||||
driver->config = virQEMUDriverConfigNew(false, NULL);
|
||||
driver->config = virQEMUDriverConfigNew(false, fakerootdir);
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user