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
|
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static virLXCDriver *driver;
|
2015-11-29 02:55:32 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
static int testSanitizeDef(virDomainDef *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
|
|
|
{
|
2021-09-04 20:37:44 +00:00
|
|
|
g_autofree char *config = NULL;
|
|
|
|
g_autofree char *actualxml = NULL;
|
2021-09-04 19:50:02 +00:00
|
|
|
g_autoptr(virDomainDef) vmdef = NULL;
|
2014-02-05 14:10:00 +00:00
|
|
|
|
2016-05-26 15:01:52 +00:00
|
|
|
if (virTestLoadFile(configfile, &config) < 0)
|
2021-09-04 20:41:46 +00:00
|
|
|
return -1;
|
2014-02-05 14:10:00 +00:00
|
|
|
|
2019-12-03 10:49:49 +00:00
|
|
|
vmdef = lxcParseConfigString(config, driver->caps, driver->xmlopt);
|
2014-02-05 14:10:02 +00:00
|
|
|
if ((vmdef && expectError) || (!vmdef && !expectError))
|
2021-09-04 20:41:46 +00:00
|
|
|
return -1;
|
2014-02-05 14:10:00 +00:00
|
|
|
|
2014-02-05 14:10:02 +00:00
|
|
|
if (vmdef) {
|
2016-02-16 17:07:32 +00:00
|
|
|
if (testSanitizeDef(vmdef) < 0)
|
2021-09-04 20:41:46 +00:00
|
|
|
return -1;
|
2014-02-05 14:10:00 +00:00
|
|
|
|
2019-11-27 11:57:34 +00:00
|
|
|
if (!(actualxml = virDomainDefFormat(vmdef, driver->xmlopt, 0)))
|
2021-09-04 20:41:46 +00:00
|
|
|
return -1;
|
2014-02-05 14:10:02 +00:00
|
|
|
|
2016-05-26 15:01:53 +00:00
|
|
|
if (virTestCompareToFile(actualxml, xmlfile) < 0)
|
2021-09-04 20:41:46 +00:00
|
|
|
return -1;
|
2014-02-05 14:10:00 +00:00
|
|
|
}
|
|
|
|
|
2021-09-04 20:41:46 +00:00
|
|
|
return 0;
|
2014-02-05 14:10:00 +00:00
|
|
|
}
|
|
|
|
|
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
|
2018-11-14 17:25:46 +00:00
|
|
|
testCompareXMLToConfigHelperLegacy(const void *data)
|
2014-02-05 14:10:00 +00:00
|
|
|
{
|
|
|
|
int result = -1;
|
2014-02-05 14:10:02 +00:00
|
|
|
const struct testInfo *info = data;
|
2021-09-04 20:37:44 +00:00
|
|
|
g_autofree char *xml = NULL;
|
|
|
|
g_autofree char *config = NULL;
|
2014-02-05 14:10:00 +00:00
|
|
|
|
2019-10-22 13:26:14 +00: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 14:10:00 +00:00
|
|
|
|
2014-02-05 14:10:02 +00:00
|
|
|
result = testCompareXMLToConfigFiles(xml, config, info->expectError);
|
2014-02-05 14:10:00 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-11-14 17:25:46 +00:00
|
|
|
static int
|
|
|
|
testCompareXMLToConfigHelperV3(const void *data)
|
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
const struct testInfo *info = data;
|
2021-09-04 20:37:44 +00:00
|
|
|
g_autofree char *xml = NULL;
|
|
|
|
g_autofree char *config = NULL;
|
2018-11-14 17:25:46 +00:00
|
|
|
|
2019-10-22 13:26:14 +00: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-14 17:25:46 +00:00
|
|
|
|
|
|
|
result = testCompareXMLToConfigFiles(xml, config, info->expectError);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-05 14:10:00 +00:00
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = EXIT_SUCCESS;
|
|
|
|
|
2019-12-03 10:49:49 +00:00
|
|
|
if (!(driver = testLXCDriverInit()))
|
2015-11-29 02:55:32 +00:00
|
|
|
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, \
|
2018-11-14 17:25:46 +00:00
|
|
|
testCompareXMLToConfigHelperLegacy, \
|
2017-11-03 12:09:47 +00:00
|
|
|
&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);
|
2018-11-30 12:43:37 +00:00
|
|
|
DO_TEST("miscnetwork", 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
|
|
|
|
2018-11-14 17:25:46 +00: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 12:43:37 +00:00
|
|
|
DO_TEST3("miscnetwork", false);
|
2018-11-14 17:25:46 +00: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 10:49:49 +00:00
|
|
|
testLXCDriverFree(driver);
|
2015-11-29 02:55:32 +00:00
|
|
|
|
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 */
|