2014-02-05 22:10:00 +08:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "testutils.h"
|
|
|
|
|
|
|
|
#ifdef WITH_LXC
|
|
|
|
|
|
|
|
# include "lxc/lxc_native.h"
|
2015-11-29 10:55:32 +08:00
|
|
|
# include "lxc/lxc_conf.h"
|
|
|
|
# include "testutilslxc.h"
|
2014-02-05 22:10:00 +08:00
|
|
|
|
|
|
|
# define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
2021-03-11 15:16:13 +08:00
|
|
|
static virLXCDriver *driver;
|
2015-11-29 10:55:32 +08:00
|
|
|
|
2021-03-11 15:16:13 +08:00
|
|
|
static int testSanitizeDef(virDomainDef *vmdef)
|
2014-02-05 22:10:00 +08:00
|
|
|
{
|
2016-02-17 01:07:32 +08:00
|
|
|
/* Remove UUID randomness */
|
|
|
|
if (virUUIDParse("c7a5fdbd-edaf-9455-926a-d65c16db1809", vmdef->uuid) < 0)
|
2014-02-05 22:10:00 +08:00
|
|
|
return -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-02-17 01:07:32 +08:00
|
|
|
testCompareXMLToConfigFiles(const char *xmlfile,
|
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 *actualxml = NULL;
|
2021-03-11 15:16:13 +08:00
|
|
|
virDomainDef *vmdef = NULL;
|
2014-02-05 22:10:00 +08:00
|
|
|
|
2016-05-26 23:01:52 +08:00
|
|
|
if (virTestLoadFile(configfile, &config) < 0)
|
2014-02-05 22:10:00 +08:00
|
|
|
goto fail;
|
|
|
|
|
2019-12-03 18:49:49 +08:00
|
|
|
vmdef = lxcParseConfigString(config, driver->caps, driver->xmlopt);
|
2014-02-05 22:10:02 +08:00
|
|
|
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) {
|
2016-02-17 01:07:32 +08:00
|
|
|
if (testSanitizeDef(vmdef) < 0)
|
2014-02-05 22:10:02 +08:00
|
|
|
goto fail;
|
2014-02-05 22:10:00 +08:00
|
|
|
|
2019-11-27 19:57:34 +08:00
|
|
|
if (!(actualxml = virDomainDefFormat(vmdef, driver->xmlopt, 0)))
|
2014-02-05 22:10:02 +08:00
|
|
|
goto fail;
|
|
|
|
|
2016-05-26 23:01:53 +08:00
|
|
|
if (virTestCompareToFile(actualxml, xmlfile) < 0)
|
2014-02-05 22:10:02 +08:00
|
|
|
goto fail;
|
2014-02-05 22:10:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 14:53:44 +08:00
|
|
|
fail:
|
2014-02-05 22:10:00 +08:00
|
|
|
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
|
2018-11-15 01:25:46 +08:00
|
|
|
testCompareXMLToConfigHelperLegacy(const void *data)
|
2014-02-05 22:10:00 +08:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2019-10-22 21:26:14 +08:00
|
|
|
xml = g_strdup_printf("%s/lxcconf2xmldata/lxcconf2xml-%s.xml",
|
|
|
|
abs_srcdir, info->name);
|
|
|
|
config = g_strdup_printf("%s/lxcconf2xmldata/lxcconf2xml-%s.config",
|
|
|
|
abs_srcdir, info->name);
|
2014-02-05 22:10:00 +08:00
|
|
|
|
2014-02-05 22:10:02 +08:00
|
|
|
result = testCompareXMLToConfigFiles(xml, config, info->expectError);
|
2014-02-05 22:10:00 +08:00
|
|
|
|
|
|
|
VIR_FREE(xml);
|
|
|
|
VIR_FREE(config);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-11-15 01:25:46 +08:00
|
|
|
static int
|
|
|
|
testCompareXMLToConfigHelperV3(const void *data)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
const struct testInfo *info = data;
|
|
|
|
char *xml = NULL;
|
|
|
|
char *config = NULL;
|
|
|
|
|
2019-10-22 21:26:14 +08:00
|
|
|
xml = g_strdup_printf("%s/lxcconf2xmldata/lxcconf2xml-%s.xml",
|
|
|
|
abs_srcdir, info->name);
|
|
|
|
config = g_strdup_printf("%s/lxcconf2xmldata/lxcconf2xml-%s-v3.config",
|
|
|
|
abs_srcdir, info->name);
|
2018-11-15 01:25:46 +08:00
|
|
|
|
|
|
|
result = testCompareXMLToConfigFiles(xml, config, info->expectError);
|
|
|
|
|
|
|
|
VIR_FREE(xml);
|
|
|
|
VIR_FREE(config);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-05 22:10:00 +08:00
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = EXIT_SUCCESS;
|
|
|
|
|
2019-12-03 18:49:49 +08:00
|
|
|
if (!(driver = testLXCDriverInit()))
|
2015-11-29 10:55:32 +08:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
2017-11-03 20:09:47 +08:00
|
|
|
# define DO_TEST(name, expectError) \
|
|
|
|
do { \
|
2014-02-05 22:10:02 +08:00
|
|
|
const struct testInfo info = { name, expectError }; \
|
2017-11-03 20:09:47 +08:00
|
|
|
if (virTestRun("LXC Native-2-XML " name, \
|
2018-11-15 01:25:46 +08:00
|
|
|
testCompareXMLToConfigHelperLegacy, \
|
2017-11-03 20:09:47 +08:00
|
|
|
&info) < 0) \
|
|
|
|
ret = EXIT_FAILURE; \
|
2014-02-05 22:10:02 +08:00
|
|
|
} 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:07 +08:00
|
|
|
DO_TEST("macvlannetwork", false);
|
2014-02-05 22:10:15 +08:00
|
|
|
DO_TEST("vlannetwork", false);
|
2018-11-30 20:43:37 +08:00
|
|
|
DO_TEST("miscnetwork", false);
|
2014-02-05 22:10:08 +08:00
|
|
|
DO_TEST("idmap", false);
|
2014-02-05 22:10:09 +08:00
|
|
|
DO_TEST("memtune", false);
|
2014-02-05 22:10:10 +08:00
|
|
|
DO_TEST("cputune", false);
|
2014-02-05 22:10:11 +08:00
|
|
|
DO_TEST("cpusettune", false);
|
2014-02-05 22:10:12 +08:00
|
|
|
DO_TEST("blkiotune", false);
|
2016-05-14 01:20:54 +08:00
|
|
|
DO_TEST("ethernet", false);
|
2014-02-05 22:10:00 +08:00
|
|
|
|
2018-11-15 01:25:46 +08:00
|
|
|
/* Tests for LXC 3.0 and higher */
|
|
|
|
# define DO_TEST3(name, expectError) \
|
|
|
|
do { \
|
|
|
|
const struct testInfo info = { name, expectError }; \
|
|
|
|
if (virTestRun("LXC Native-3-XML " name, \
|
|
|
|
testCompareXMLToConfigHelperV3, \
|
|
|
|
&info) < 0) \
|
|
|
|
ret = EXIT_FAILURE; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
DO_TEST3("simple", false);
|
|
|
|
DO_TEST3("fstab", true);
|
|
|
|
DO_TEST3("nonetwork", false);
|
|
|
|
DO_TEST3("nonenetwork", false);
|
|
|
|
DO_TEST3("physnetwork", false);
|
|
|
|
DO_TEST3("macvlannetwork", false);
|
|
|
|
DO_TEST3("vlannetwork", false);
|
2018-11-30 20:43:37 +08:00
|
|
|
DO_TEST3("miscnetwork", false);
|
2018-11-15 01:25:46 +08:00
|
|
|
DO_TEST3("idmap", false);
|
|
|
|
DO_TEST3("memtune", false);
|
|
|
|
DO_TEST3("cputune", false);
|
|
|
|
DO_TEST3("cpusettune", false);
|
|
|
|
DO_TEST3("blkiotune", false);
|
|
|
|
DO_TEST3("ethernet", false);
|
|
|
|
|
2019-12-03 18:49:49 +08:00
|
|
|
testLXCDriverFree(driver);
|
2015-11-29 10:55:32 +08:00
|
|
|
|
2014-02-05 22:10:00 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-03-29 22:45:42 +08:00
|
|
|
VIR_TEST_MAIN(mymain)
|
2014-02-05 22:10:00 +08:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WITH_LXC */
|