2014-02-05 14:10:00 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "testutils.h"
|
|
|
|
|
|
|
|
#ifdef WITH_LXC
|
|
|
|
|
|
|
|
# include "lxc/lxc_native.h"
|
2015-11-29 02:55:32 +00:00
|
|
|
# include "lxc/lxc_conf.h"
|
|
|
|
# include "testutilslxc.h"
|
2014-02-05 14:10:00 +00:00
|
|
|
|
|
|
|
# define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
2015-11-29 02:55:32 +00:00
|
|
|
static virCapsPtr caps;
|
|
|
|
static virDomainXMLOptionPtr xmlopt;
|
|
|
|
|
2016-02-16 17:07:32 +00:00
|
|
|
static int testSanitizeDef(virDomainDefPtr vmdef)
|
2014-02-05 14:10:00 +00:00
|
|
|
{
|
2016-02-16 17:07:32 +00:00
|
|
|
/* Remove UUID randomness */
|
|
|
|
if (virUUIDParse("c7a5fdbd-edaf-9455-926a-d65c16db1809", vmdef->uuid) < 0)
|
2014-02-05 14:10:00 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-02-16 17:07:32 +00:00
|
|
|
testCompareXMLToConfigFiles(const char *xmlfile,
|
2014-02-05 14:10:02 +00:00
|
|
|
const char *configfile,
|
|
|
|
bool expectError)
|
2014-02-05 14:10:00 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
char *config = NULL;
|
|
|
|
char *actualxml = NULL;
|
|
|
|
virDomainDefPtr vmdef = NULL;
|
|
|
|
|
2016-05-26 15:01:52 +00:00
|
|
|
if (virTestLoadFile(configfile, &config) < 0)
|
2014-02-05 14:10:00 +00:00
|
|
|
goto fail;
|
|
|
|
|
2015-11-29 02:55:32 +00:00
|
|
|
vmdef = lxcParseConfigString(config, caps, xmlopt);
|
2014-02-05 14:10:02 +00:00
|
|
|
if ((vmdef && expectError) || (!vmdef && !expectError))
|
2014-02-05 14:10:00 +00:00
|
|
|
goto fail;
|
|
|
|
|
2014-02-05 14:10:02 +00:00
|
|
|
if (vmdef) {
|
2016-02-16 17:07:32 +00:00
|
|
|
if (testSanitizeDef(vmdef) < 0)
|
2014-02-05 14:10:02 +00:00
|
|
|
goto fail;
|
2014-02-05 14:10:00 +00:00
|
|
|
|
2016-02-16 17:07:32 +00:00
|
|
|
if (!(actualxml = virDomainDefFormat(vmdef, caps, 0)))
|
2014-02-05 14:10:02 +00:00
|
|
|
goto fail;
|
|
|
|
|
2016-05-26 15:01:53 +00:00
|
|
|
if (virTestCompareToFile(actualxml, xmlfile) < 0)
|
2014-02-05 14:10:02 +00:00
|
|
|
goto fail;
|
2014-02-05 14:10:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
fail:
|
2014-02-05 14:10:00 +00:00
|
|
|
VIR_FREE(actualxml);
|
|
|
|
VIR_FREE(config);
|
|
|
|
virDomainDefFree(vmdef);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-05 14:10:02 +00:00
|
|
|
struct testInfo {
|
|
|
|
const char *name;
|
|
|
|
bool expectError;
|
|
|
|
};
|
|
|
|
|
2014-02-05 14:10:00 +00:00
|
|
|
static int
|
|
|
|
testCompareXMLToConfigHelper(const void *data)
|
|
|
|
{
|
|
|
|
int result = -1;
|
2014-02-05 14:10:02 +00:00
|
|
|
const struct testInfo *info = data;
|
2014-02-05 14:10:00 +00:00
|
|
|
char *xml = NULL;
|
|
|
|
char *config = NULL;
|
|
|
|
|
|
|
|
if (virAsprintf(&xml, "%s/lxcconf2xmldata/lxcconf2xml-%s.xml",
|
2014-02-05 14:10:02 +00:00
|
|
|
abs_srcdir, info->name) < 0 ||
|
2014-02-05 14:10:00 +00:00
|
|
|
virAsprintf(&config, "%s/lxcconf2xmldata/lxcconf2xml-%s.config",
|
2014-02-05 14:10:02 +00:00
|
|
|
abs_srcdir, info->name) < 0)
|
2014-02-05 14:10:00 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-02-05 14:10:02 +00:00
|
|
|
result = testCompareXMLToConfigFiles(xml, config, info->expectError);
|
2014-02-05 14:10:00 +00:00
|
|
|
|
2014-03-25 06:53:44 +00:00
|
|
|
cleanup:
|
2014-02-05 14:10:00 +00:00
|
|
|
VIR_FREE(xml);
|
|
|
|
VIR_FREE(config);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = EXIT_SUCCESS;
|
|
|
|
|
2015-11-29 02:55:32 +00:00
|
|
|
if (!(caps = testLXCCapsInit()))
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
if (!(xmlopt = lxcDomainXMLConfInit())) {
|
|
|
|
virObjectUnref(caps);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-11-03 12:09:47 +00:00
|
|
|
# define DO_TEST(name, expectError) \
|
|
|
|
do { \
|
2014-02-05 14:10:02 +00:00
|
|
|
const struct testInfo info = { name, expectError }; \
|
2017-11-03 12:09:47 +00:00
|
|
|
if (virTestRun("LXC Native-2-XML " name, \
|
|
|
|
testCompareXMLToConfigHelper, \
|
|
|
|
&info) < 0) \
|
|
|
|
ret = EXIT_FAILURE; \
|
2014-02-05 14:10:02 +00:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
DO_TEST("simple", false);
|
|
|
|
DO_TEST("fstab", true);
|
2014-02-05 14:10:03 +00:00
|
|
|
DO_TEST("nonetwork", false);
|
|
|
|
DO_TEST("nonenetwork", false);
|
2014-02-05 14:10:05 +00:00
|
|
|
DO_TEST("physnetwork", false);
|
2014-02-05 14:10:07 +00:00
|
|
|
DO_TEST("macvlannetwork", false);
|
2014-02-05 14:10:15 +00:00
|
|
|
DO_TEST("vlannetwork", false);
|
2014-02-05 14:10:08 +00:00
|
|
|
DO_TEST("idmap", false);
|
2014-02-05 14:10:09 +00:00
|
|
|
DO_TEST("memtune", false);
|
2014-02-05 14:10:10 +00:00
|
|
|
DO_TEST("cputune", false);
|
2014-02-05 14:10:11 +00:00
|
|
|
DO_TEST("cpusettune", false);
|
2014-02-05 14:10:12 +00:00
|
|
|
DO_TEST("blkiotune", false);
|
2016-05-13 17:20:54 +00:00
|
|
|
DO_TEST("ethernet", false);
|
2014-02-05 14:10:00 +00:00
|
|
|
|
2015-11-29 02:55:32 +00:00
|
|
|
virObjectUnref(xmlopt);
|
|
|
|
virObjectUnref(caps);
|
|
|
|
|
2014-02-05 14:10:00 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-29 14:45:42 +00:00
|
|
|
VIR_TEST_MAIN(mymain)
|
2014-02-05 14:10:00 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WITH_LXC */
|