mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
qemuTestDriverInit: Don't access live data
Some of our tests (e.g. qemuhotplugtest) call virDomainSaveConfig(). Now the problem is, qemuTestDriverInit() creates a fake qemu driver and fills it with some fake configuration. At least so we hoped. The truth is, it calls regular virQEMUDriverConfigNew() and then fix couple of paths. Literally. Therefore our tests see regular stateDir and configDir for the user that is running the tests. Directories, where live domain XMLs are stored. Let's just hope our test suite hasn't mangled any of them. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
b3388de7f2
commit
16efa11aa6
@ -513,6 +513,10 @@ qemuTestParseCapabilities(virCapsPtr caps,
|
||||
void qemuTestDriverFree(virQEMUDriver *driver)
|
||||
{
|
||||
virMutexDestroy(&driver->lock);
|
||||
if (driver->config) {
|
||||
virFileDeleteTree(driver->config->stateDir);
|
||||
virFileDeleteTree(driver->config->configDir);
|
||||
}
|
||||
virQEMUCapsCacheFree(driver->qemuCapsCache);
|
||||
virObjectUnref(driver->xmlopt);
|
||||
virObjectUnref(driver->caps);
|
||||
@ -548,9 +552,14 @@ int qemuTestCapsCacheInsert(virQEMUCapsCachePtr cache, const char *binary,
|
||||
return ret;
|
||||
}
|
||||
|
||||
# define STATEDIRTEMPLATE abs_builddir "/qemustatedir-XXXXXX"
|
||||
# define CONFIGDIRTEMPLATE abs_builddir "/qemuconfigdir-XXXXXX"
|
||||
|
||||
int qemuTestDriverInit(virQEMUDriver *driver)
|
||||
{
|
||||
virSecurityManagerPtr mgr = NULL;
|
||||
char statedir[] = STATEDIRTEMPLATE;
|
||||
char configdir[] = CONFIGDIRTEMPLATE;
|
||||
|
||||
memset(driver, 0, sizeof(*driver));
|
||||
|
||||
@ -561,6 +570,11 @@ int qemuTestDriverInit(virQEMUDriver *driver)
|
||||
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);
|
||||
@ -568,6 +582,26 @@ int qemuTestDriverInit(virQEMUDriver *driver)
|
||||
VIR_STRDUP(driver->config->channelTargetDir, "/tmp/channel") < 0)
|
||||
goto error;
|
||||
|
||||
if (!mkdtemp(statedir)) {
|
||||
virFilePrintf(stderr, "Cannot create fake stateDir");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (VIR_STRDUP(driver->config->stateDir, statedir) < 0) {
|
||||
rmdir(statedir);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!mkdtemp(configdir)) {
|
||||
virFilePrintf(stderr, "Cannot create fake configDir");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (VIR_STRDUP(driver->config->configDir, configdir) < 0) {
|
||||
rmdir(configdir);
|
||||
goto error;
|
||||
}
|
||||
|
||||
driver->caps = testQemuCapsInit();
|
||||
if (!driver->caps)
|
||||
goto error;
|
||||
|
Loading…
Reference in New Issue
Block a user