mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Rename virDomainGetRootFilesystem to virDomainGetFilesystemForTarget
The virDomainGetRootFilesystem method can be generalized to allow any filesystem path to be obtained. While doing this, start a new test case for purpose of testing various helper methods in the domain_conf.{c,h} files, such as this one. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
590029f672
commit
432a3fee3b
1
.gitignore
vendored
1
.gitignore
vendored
@ -149,6 +149,7 @@
|
|||||||
/tests/commandtest
|
/tests/commandtest
|
||||||
/tests/conftest
|
/tests/conftest
|
||||||
/tests/cputest
|
/tests/cputest
|
||||||
|
/tests/domainconftest
|
||||||
/tests/domainsnapshotxml2xmltest
|
/tests/domainsnapshotxml2xmltest
|
||||||
/tests/esxutilstest
|
/tests/esxutilstest
|
||||||
/tests/eventtest
|
/tests/eventtest
|
||||||
|
@ -18083,12 +18083,13 @@ virDomainFSRemove(virDomainDefPtr def, size_t i)
|
|||||||
}
|
}
|
||||||
|
|
||||||
virDomainFSDefPtr
|
virDomainFSDefPtr
|
||||||
virDomainGetRootFilesystem(virDomainDefPtr def)
|
virDomainGetFilesystemForTarget(virDomainDefPtr def,
|
||||||
|
const char *path)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < def->nfss; i++) {
|
for (i = 0; i < def->nfss; i++) {
|
||||||
if (STREQ(def->fss[i]->dst, "/"))
|
if (STREQ(def->fss[i]->dst, path))
|
||||||
return def->fss[i];
|
return def->fss[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2563,7 +2563,8 @@ int virDiskNameToBusDeviceIndex(virDomainDiskDefPtr disk,
|
|||||||
int *busIdx,
|
int *busIdx,
|
||||||
int *devIdx);
|
int *devIdx);
|
||||||
|
|
||||||
virDomainFSDefPtr virDomainGetRootFilesystem(virDomainDefPtr def);
|
virDomainFSDefPtr virDomainGetFilesystemForTarget(virDomainDefPtr def,
|
||||||
|
const char *path);
|
||||||
int virDomainFSInsert(virDomainDefPtr def, virDomainFSDefPtr fs);
|
int virDomainFSInsert(virDomainDefPtr def, virDomainFSDefPtr fs);
|
||||||
int virDomainFSIndexByName(virDomainDefPtr def, const char *name);
|
int virDomainFSIndexByName(virDomainDefPtr def, const char *name);
|
||||||
virDomainFSDefPtr virDomainFSRemove(virDomainDefPtr def, size_t i);
|
virDomainFSDefPtr virDomainFSRemove(virDomainDefPtr def, size_t i);
|
||||||
|
@ -229,7 +229,7 @@ virDomainFSTypeFromString;
|
|||||||
virDomainFSTypeToString;
|
virDomainFSTypeToString;
|
||||||
virDomainFSWrpolicyTypeFromString;
|
virDomainFSWrpolicyTypeFromString;
|
||||||
virDomainFSWrpolicyTypeToString;
|
virDomainFSWrpolicyTypeToString;
|
||||||
virDomainGetRootFilesystem;
|
virDomainGetFilesystemForTarget;
|
||||||
virDomainGraphicsAuthConnectedTypeFromString;
|
virDomainGraphicsAuthConnectedTypeFromString;
|
||||||
virDomainGraphicsAuthConnectedTypeToString;
|
virDomainGraphicsAuthConnectedTypeToString;
|
||||||
virDomainGraphicsDefFree;
|
virDomainGraphicsDefFree;
|
||||||
|
@ -1823,7 +1823,7 @@ static int lxcContainerChild(void *data)
|
|||||||
if (lxcContainerSetID(vmDef) < 0)
|
if (lxcContainerSetID(vmDef) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
root = virDomainGetRootFilesystem(vmDef);
|
root = virDomainGetFilesystemForTarget(vmDef, "/");
|
||||||
|
|
||||||
if (argv->nttyPaths) {
|
if (argv->nttyPaths) {
|
||||||
const char *tty = argv->ttyPaths[0];
|
const char *tty = argv->ttyPaths[0];
|
||||||
|
@ -957,7 +957,7 @@ virLXCProcessReadLogOutput(virDomainObjPtr vm,
|
|||||||
static int
|
static int
|
||||||
virLXCProcessEnsureRootFS(virDomainObjPtr vm)
|
virLXCProcessEnsureRootFS(virDomainObjPtr vm)
|
||||||
{
|
{
|
||||||
virDomainFSDefPtr root = virDomainGetRootFilesystem(vm->def);
|
virDomainFSDefPtr root = virDomainGetFilesystemForTarget(vm->def, "/");
|
||||||
|
|
||||||
if (root)
|
if (root)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -65,6 +65,7 @@ EXTRA_DIST = \
|
|||||||
commanddata \
|
commanddata \
|
||||||
confdata \
|
confdata \
|
||||||
cputestdata \
|
cputestdata \
|
||||||
|
domainconfdata \
|
||||||
domainschemadata \
|
domainschemadata \
|
||||||
domainschematest \
|
domainschematest \
|
||||||
domainsnapshotschematest \
|
domainsnapshotschematest \
|
||||||
@ -147,6 +148,7 @@ test_programs = virshtest sockettest \
|
|||||||
virnetdevbandwidthtest \
|
virnetdevbandwidthtest \
|
||||||
virkmodtest \
|
virkmodtest \
|
||||||
vircapstest \
|
vircapstest \
|
||||||
|
domainconftest \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
if WITH_REMOTE
|
if WITH_REMOTE
|
||||||
@ -939,6 +941,10 @@ sysinfotest_SOURCES = \
|
|||||||
sysinfotest.c testutils.h testutils.c
|
sysinfotest.c testutils.h testutils.c
|
||||||
sysinfotest_LDADD = $(LDADDS)
|
sysinfotest_LDADD = $(LDADDS)
|
||||||
|
|
||||||
|
domainconftest_SOURCES = \
|
||||||
|
domainconftest.c testutils.h testutils.c
|
||||||
|
domainconftest_LDADD = $(LDADDS)
|
||||||
|
|
||||||
fdstreamtest_SOURCES = \
|
fdstreamtest_SOURCES = \
|
||||||
fdstreamtest.c testutils.h testutils.c
|
fdstreamtest.c testutils.h testutils.c
|
||||||
fdstreamtest_LDADD = $(LDADDS)
|
fdstreamtest_LDADD = $(LDADDS)
|
||||||
|
28
tests/domainconfdata/getfilesystem.xml
Normal file
28
tests/domainconfdata/getfilesystem.xml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<domain type='test'>
|
||||||
|
<name>demo</name>
|
||||||
|
<uuid>8369f1ac-7e46-e869-4ca5-759d51478066</uuid>
|
||||||
|
<memory unit='KiB'>500000</memory>
|
||||||
|
<currentMemory unit='KiB'>500000</currentMemory>
|
||||||
|
<vcpu placement='static'>1</vcpu>
|
||||||
|
<os>
|
||||||
|
<type arch='x86_64'>hvm</type>
|
||||||
|
<init>/bin/sh</init>
|
||||||
|
</os>
|
||||||
|
<clock offset='utc'/>
|
||||||
|
<on_poweroff>destroy</on_poweroff>
|
||||||
|
<on_reboot>restart</on_reboot>
|
||||||
|
<on_crash>destroy</on_crash>
|
||||||
|
<devices>
|
||||||
|
<filesystem type='mount' accessmode='passthrough'>
|
||||||
|
<source dir='/'/>
|
||||||
|
<target dir='/'/>
|
||||||
|
</filesystem>
|
||||||
|
<filesystem type='mount' accessmode='passthrough'>
|
||||||
|
<source dir='/'/>
|
||||||
|
<target dir='/dev'/>
|
||||||
|
</filesystem>
|
||||||
|
<console type='pty'>
|
||||||
|
<target type='lxc' port='0'/>
|
||||||
|
</console>
|
||||||
|
</devices>
|
||||||
|
</domain>
|
120
tests/domainconftest.c
Normal file
120
tests/domainconftest.c
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013 Red Hat, Inc.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include "testutils.h"
|
||||||
|
#include "virerror.h"
|
||||||
|
#include "viralloc.h"
|
||||||
|
#include "virlog.h"
|
||||||
|
|
||||||
|
#include "domain_conf.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
|
||||||
|
static virCapsPtr caps;
|
||||||
|
static virDomainXMLOptionPtr xmlopt;
|
||||||
|
|
||||||
|
struct testGetFilesystemData {
|
||||||
|
const char *filename;
|
||||||
|
const char *path;
|
||||||
|
bool expectEntry;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int testGetFilesystem(const void *opaque)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
char *xmlData = NULL;
|
||||||
|
virDomainDefPtr def = NULL;
|
||||||
|
char *filename = NULL;
|
||||||
|
const struct testGetFilesystemData *data = opaque;
|
||||||
|
virDomainFSDefPtr fsdef;
|
||||||
|
|
||||||
|
if (virAsprintf(&filename, "%s/domainconfdata/%s.xml",
|
||||||
|
abs_srcdir, data->filename) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virtTestLoadFile(filename, &xmlData) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!(def = virDomainDefParseString(xmlData, caps, xmlopt,
|
||||||
|
1 << VIR_DOMAIN_VIRT_TEST, 0)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
fsdef = virDomainGetFilesystemForTarget(def,
|
||||||
|
data->path);
|
||||||
|
if (!fsdef) {
|
||||||
|
if (data->expectEntry) {
|
||||||
|
fprintf(stderr, "Expected FS for path '%s' in '%s'\n",
|
||||||
|
data->path, filename);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!data->expectEntry) {
|
||||||
|
fprintf(stderr, "Unexpected FS for path '%s' in '%s'\n",
|
||||||
|
data->path, filename);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
virDomainDefFree(def);
|
||||||
|
VIR_FREE(xmlData);
|
||||||
|
VIR_FREE(filename);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
mymain(void)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
if ((caps = virTestGenericCapsInit()) == NULL)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!(xmlopt = virTestGenericDomainXMLConfInit()))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
#define DO_TEST_GET_FS(fspath, expect) \
|
||||||
|
do { \
|
||||||
|
struct testGetFilesystemData data = { \
|
||||||
|
.filename = "getfilesystem", \
|
||||||
|
.path = fspath, \
|
||||||
|
.expectEntry = expect, \
|
||||||
|
}; \
|
||||||
|
if (virtTestRun("Get FS " fspath, testGetFilesystem, &data) < 0) \
|
||||||
|
ret = -1; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
DO_TEST_GET_FS("/", true);
|
||||||
|
DO_TEST_GET_FS("/dev", true);
|
||||||
|
DO_TEST_GET_FS("/dev/pts", false);
|
||||||
|
DO_TEST_GET_FS("/doesnotexist", false);
|
||||||
|
|
||||||
|
virObjectUnref(caps);
|
||||||
|
virObjectUnref(xmlopt);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
VIRT_TEST_MAIN(mymain)
|
@ -834,3 +834,60 @@ int virtTestClearLineRegex(const char *pattern,
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
virCapsPtr virTestGenericCapsInit(void)
|
||||||
|
{
|
||||||
|
virCapsPtr caps;
|
||||||
|
virCapsGuestPtr guest;
|
||||||
|
|
||||||
|
if ((caps = virCapabilitiesNew(VIR_ARCH_X86_64,
|
||||||
|
0, 0)) == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if ((guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_I686,
|
||||||
|
"/usr/bin/acme-virt", NULL,
|
||||||
|
0, NULL)) == NULL)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (!virCapabilitiesAddGuestDomain(guest, "test", NULL, NULL, 0, NULL))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
|
||||||
|
if ((guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_X86_64,
|
||||||
|
"/usr/bin/acme-virt", NULL,
|
||||||
|
0, NULL)) == NULL)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (!virCapabilitiesAddGuestDomain(guest, "test", NULL, NULL, 0, NULL))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
|
||||||
|
if (virTestGetDebug()) {
|
||||||
|
char *caps_str;
|
||||||
|
|
||||||
|
caps_str = virCapabilitiesFormatXML(caps);
|
||||||
|
if (!caps_str)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
fprintf(stderr, "Generic driver capabilities:\n%s", caps_str);
|
||||||
|
|
||||||
|
VIR_FREE(caps_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
return caps;
|
||||||
|
|
||||||
|
error:
|
||||||
|
virObjectUnref(caps);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static virDomainDefParserConfig virTestGenericDomainDefParserConfig;
|
||||||
|
static virDomainXMLPrivateDataCallbacks virTestGenericPrivateDataCallbacks;
|
||||||
|
|
||||||
|
virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void)
|
||||||
|
{
|
||||||
|
return virDomainXMLOptionNew(&virTestGenericDomainDefParserConfig,
|
||||||
|
&virTestGenericPrivateDataCallbacks,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
# include "viralloc.h"
|
# include "viralloc.h"
|
||||||
# include "virfile.h"
|
# include "virfile.h"
|
||||||
# include "virstring.h"
|
# include "virstring.h"
|
||||||
|
# include "capabilities.h"
|
||||||
|
# include "domain_conf.h"
|
||||||
|
|
||||||
# define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
|
# define EXIT_AM_SKIP 77 /* tell Automake we're skipping a test */
|
||||||
# define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */
|
# define EXIT_AM_HARDFAIL 99 /* tell Automake that the framework is broken */
|
||||||
@ -104,4 +106,7 @@ int virtTestMain(int argc,
|
|||||||
return virtTestMain(argc, argv, func); \
|
return virtTestMain(argc, argv, func); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virCapsPtr virTestGenericCapsInit(void);
|
||||||
|
virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void);
|
||||||
|
|
||||||
#endif /* __VIT_TEST_UTILS_H__ */
|
#endif /* __VIT_TEST_UTILS_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user