libvirt/tests/openvzutilstest.c

166 lines
3.8 KiB
C
Raw Normal View History

#include <config.h>
#include "testutils.h"
#ifdef WITH_OPENVZ
# include <unistd.h>
# include "internal.h"
2012-12-13 02:06:53 +08:00
# include "viralloc.h"
# include "openvz/openvz_conf.h"
# include "virstring.h"
# define VIR_FROM_THIS VIR_FROM_OPENVZ
static int
testLocateConfFile(int vpsid ATTRIBUTE_UNUSED, char **conffile,
const char *ext ATTRIBUTE_UNUSED)
{
return virAsprintf(conffile, "%s/openvzutilstest.conf", abs_srcdir);
}
struct testConfigParam {
const char *param;
const char *value;
int ret;
};
static struct testConfigParam configParams[] = {
{ "OSTEMPLATE", "rhel-5-lystor", 1 },
{ "IP_ADDRESS", "194.44.18.88", 1 },
{ "THIS_PARAM_IS_MISSING", NULL, 0 },
};
static int
testReadConfigParam(const void *data ATTRIBUTE_UNUSED)
{
int result = -1;
size_t i;
char *conf = NULL;
char *value = NULL;
if (virAsprintf(&conf, "%s/openvzutilstest.conf", abs_srcdir) < 0)
return -1;
for (i = 0; i < ARRAY_CARDINALITY(configParams); ++i) {
if (openvzReadConfigParam(conf, configParams[i].param,
&value) != configParams[i].ret) {
goto cleanup;
}
if (configParams[i].ret != 1)
continue;
if (STRNEQ(configParams[i].value, value)) {
virTestDifference(stderr, configParams[i].value, value);
goto cleanup;
}
}
result = 0;
cleanup:
VIR_FREE(conf);
VIR_FREE(value);
return result;
}
static int
testReadNetworkConf(const void *data ATTRIBUTE_UNUSED)
{
int result = -1;
virDomainDefPtr def = NULL;
char *actual = NULL;
const char *expected =
"<domain type='openvz'>\n"
" <uuid>00000000-0000-0000-0000-000000000000</uuid>\n"
xml: output memory unit for clarity Make it obvious to 'dumpxml' readers what unit we are using, since our default of KiB for memory (1024) differs from qemu's default of MiB; and differs from our use of bytes for storage. Tests were updated via: $ find tests/*data tests/*out -name '*.xml' | \ xargs sed -i 's/<\(memory\|currentMemory\|hard_limit\|soft_limit\|min_guarantee\|swap_hard_limit\)>/<\1 unit='"'KiB'>/" $ find tests/*data tests/*out -name '*.xml' | \ xargs sed -i 's/<\(capacity\|allocation\|available\)>/<\1 unit='"'bytes'>/" followed by a few fixes for the stragglers. Note that with this patch, the RNG for <memory> still forbids validation of anything except unit='KiB', since the code silently ignores the attribute; a later patch will expand <memory> to allow scaled input in the code and update the RNG to match. * docs/schemas/basictypes.rng (unit): Add 'bytes'. (scaledInteger): New define. * docs/schemas/storagevol.rng (sizing): Use it. * docs/schemas/storagepool.rng (sizing): Likewise. * docs/schemas/domaincommon.rng (memoryKBElement): New define; use for memory elements. * src/conf/storage_conf.c (virStoragePoolDefFormat) (virStorageVolDefFormat): Likewise. * src/conf/domain_conf.h (_virDomainDef): Document unit used internally. * src/conf/storage_conf.h (_virStoragePoolDef, _virStorageVolDef): Likewise. * tests/*data/*.xml: Update all tests. * tests/*out/*.xml: Likewise. * tests/define-dev-segfault: Likewise. * tests/openvzutilstest.c (testReadNetworkConf): Likewise. * tests/qemuargv2xmltest.c (blankProblemElements): Likewise.
2012-02-23 08:48:38 +08:00
" <memory unit='KiB'>0</memory>\n"
" <currentMemory unit='KiB'>0</currentMemory>\n"
" <vcpu placement='static'>0</vcpu>\n"
" <os>\n"
" <type>exe</type>\n"
" <init>/sbin/init</init>\n"
" </os>\n"
" <clock offset='utc'/>\n"
" <on_poweroff>destroy</on_poweroff>\n"
" <on_reboot>destroy</on_reboot>\n"
" <on_crash>destroy</on_crash>\n"
" <devices>\n"
" <interface type='ethernet'>\n"
" <mac address='00:00:00:00:00:00'/>\n"
" <ip address='194.44.18.88' family='ipv4'/>\n"
" </interface>\n"
" <interface type='bridge'>\n"
" <mac address='00:18:51:c1:05:ee'/>\n"
" <target dev='veth105.10'/>\n"
" </interface>\n"
" </devices>\n"
"</domain>\n";
if (!(def = virDomainDefNew()) ||
VIR_STRDUP(def->os.init, "/sbin/init") < 0)
goto cleanup;
def->virtType = VIR_DOMAIN_VIRT_OPENVZ;
def->os.type = VIR_DOMAIN_OSTYPE_EXE;
if (openvzReadNetworkConf(def, 1) < 0) {
fprintf(stderr, "ERROR: %s\n", virGetLastErrorMessage());
goto cleanup;
}
actual = virDomainDefFormat(def, NULL, VIR_DOMAIN_DEF_FORMAT_INACTIVE);
if (actual == NULL) {
fprintf(stderr, "ERROR: %s\n", virGetLastErrorMessage());
goto cleanup;
}
if (STRNEQ(expected, actual)) {
virTestDifference(stderr, expected, actual);
goto cleanup;
}
result = 0;
cleanup:
VIR_FREE(actual);
virDomainDefFree(def);
return result;
}
static int
mymain(void)
{
int result = 0;
openvzLocateConfFile = testLocateConfFile;
# define DO_TEST(_name) \
do { \
if (virTestRun("OpenVZ "#_name, test##_name, \
NULL) < 0) { \
result = -1; \
} \
} while (0)
DO_TEST(ReadConfigParam);
DO_TEST(ReadNetworkConf);
return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
VIR_TEST_MAIN(mymain)
#else
int main(void)
{
return EXIT_AM_SKIP;
}
#endif /* WITH_OPENVZ */