2014-02-05 22:10:00 +08:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "testutils.h"
|
|
|
|
|
|
|
|
#ifdef WITH_LXC
|
|
|
|
|
|
|
|
# include "lxc/lxc_native.h"
|
|
|
|
|
|
|
|
# define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
|
|
|
static int
|
|
|
|
blankProblemElements(char *data)
|
|
|
|
{
|
|
|
|
if (virtTestClearLineRegex("<uuid>([[:alnum:]]|-)+</uuid>", data) < 0)
|
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
testCompareXMLToConfigFiles(const char *xml,
|
2014-02-05 22:10:02 +08:00
|
|
|
const char *configfile,
|
|
|
|
bool expectError)
|
2014-02-05 22:10:00 +08:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
char *config = NULL;
|
|
|
|
char *expectxml = NULL;
|
|
|
|
char *actualxml = NULL;
|
|
|
|
virDomainDefPtr vmdef = NULL;
|
|
|
|
|
|
|
|
if (virtTestLoadFile(configfile, &config) < 0)
|
|
|
|
goto fail;
|
|
|
|
|
2014-02-05 22:10:02 +08:00
|
|
|
vmdef = lxcParseConfigString(config);
|
|
|
|
if ((vmdef && expectError) || (!vmdef && !expectError))
|
2014-02-05 22:10:00 +08:00
|
|
|
goto fail;
|
|
|
|
|
2014-02-05 22:10:02 +08:00
|
|
|
if (vmdef) {
|
|
|
|
if (!(actualxml = virDomainDefFormat(vmdef, 0)))
|
|
|
|
goto fail;
|
2014-02-05 22:10:00 +08:00
|
|
|
|
2014-02-05 22:10:02 +08:00
|
|
|
if (virtTestLoadFile(xml, &expectxml) < 0)
|
|
|
|
goto fail;
|
2014-02-05 22:10:00 +08:00
|
|
|
|
2014-02-05 22:10:02 +08:00
|
|
|
if (blankProblemElements(expectxml) < 0 ||
|
|
|
|
blankProblemElements(actualxml) < 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (STRNEQ(expectxml, actualxml)) {
|
|
|
|
virtTestDifference(stderr, expectxml, actualxml);
|
|
|
|
goto fail;
|
|
|
|
}
|
2014-02-05 22:10:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
VIR_FREE(expectxml);
|
|
|
|
VIR_FREE(actualxml);
|
|
|
|
VIR_FREE(config);
|
|
|
|
virDomainDefFree(vmdef);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-05 22:10:02 +08:00
|
|
|
struct testInfo {
|
|
|
|
const char *name;
|
|
|
|
bool expectError;
|
|
|
|
};
|
|
|
|
|
2014-02-05 22:10:00 +08:00
|
|
|
static int
|
|
|
|
testCompareXMLToConfigHelper(const void *data)
|
|
|
|
{
|
|
|
|
int result = -1;
|
2014-02-05 22:10:02 +08:00
|
|
|
const struct testInfo *info = data;
|
2014-02-05 22:10:00 +08:00
|
|
|
char *xml = NULL;
|
|
|
|
char *config = NULL;
|
|
|
|
|
|
|
|
if (virAsprintf(&xml, "%s/lxcconf2xmldata/lxcconf2xml-%s.xml",
|
2014-02-05 22:10:02 +08:00
|
|
|
abs_srcdir, info->name) < 0 ||
|
2014-02-05 22:10:00 +08:00
|
|
|
virAsprintf(&config, "%s/lxcconf2xmldata/lxcconf2xml-%s.config",
|
2014-02-05 22:10:02 +08:00
|
|
|
abs_srcdir, info->name) < 0)
|
2014-02-05 22:10:00 +08:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-02-05 22:10:02 +08:00
|
|
|
result = testCompareXMLToConfigFiles(xml, config, info->expectError);
|
2014-02-05 22:10:00 +08:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(xml);
|
|
|
|
VIR_FREE(config);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = EXIT_SUCCESS;
|
|
|
|
|
2014-02-05 22:10:02 +08:00
|
|
|
# define DO_TEST(name, expectError) \
|
|
|
|
do { \
|
|
|
|
const struct testInfo info = { name, expectError }; \
|
|
|
|
if (virtTestRun("LXC Native-2-XML " name, \
|
|
|
|
testCompareXMLToConfigHelper, \
|
|
|
|
&info) < 0) \
|
|
|
|
ret = EXIT_FAILURE; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
DO_TEST("simple", false);
|
|
|
|
DO_TEST("fstab", true);
|
2014-02-05 22:10:03 +08:00
|
|
|
DO_TEST("nonetwork", false);
|
|
|
|
DO_TEST("nonenetwork", false);
|
2014-02-05 22:10:05 +08:00
|
|
|
DO_TEST("physnetwork", false);
|
2014-02-05 22:10:00 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIRT_TEST_MAIN(mymain)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WITH_LXC */
|