mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
qemuxmlactivetest: Prepare for proper active/inactive -> active/inactive testing
Currently the xml->xml testing we have in qemuxml2xmltest covers only 3 of the 4 possibilities: By invocation: active -> active; inactive -> inactive; by unintentionally: active -> inactive (for configs which don't set an 'id' as the formatter assumes it's inactive) To do it better introduce proper active -> inactive/active testing into qemuxmlactivetest. It's chosen such as we only really parse an XML as live when restoring a status XML. To give users possibility to avoid constructing a full status XML add a simpler variant. As of such it will be used only for configs where we specifically cared about parsing live data. To ensure that the formatter doesn't decide that a config is inactive because it doesn't have an ID we fill in a domain ID if it was not present in the source. In this patch the tests are not yet added. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
3b04d48192
commit
a895686bd1
@ -87,12 +87,118 @@ testRunStatus(const char *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
testqemuActiveXML2XMLCommon(testQemuInfo *info,
|
||||||
|
bool live)
|
||||||
|
{
|
||||||
|
g_autofree char *actual = NULL;
|
||||||
|
const char *outfile = info->out_xml_active;
|
||||||
|
unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE;
|
||||||
|
|
||||||
|
/* Prepare the test data and parse the input just once */
|
||||||
|
if (!info->def) {
|
||||||
|
if (testQemuInfoInitArgs((testQemuInfo *) info) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
virFileCacheClear(driver.qemuCapsCache);
|
||||||
|
|
||||||
|
if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (!(info->def = virDomainDefParseFile(info->infile,
|
||||||
|
driver.xmlopt, NULL,
|
||||||
|
info->parseFlags)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (!virDomainDefCheckABIStability(info->def, info->def, driver.xmlopt)) {
|
||||||
|
VIR_TEST_DEBUG("ABI stability check failed on %s", info->infile);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* make sure that the XML definition looks active, by setting an ID
|
||||||
|
* as otherwise the XML formatter will simply assume that it's inactive */
|
||||||
|
if (info->def->id == -1)
|
||||||
|
info->def->id = 1337;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!live) {
|
||||||
|
format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE;
|
||||||
|
outfile = info->out_xml_inactive;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(actual = virDomainDefFormat(info->def, driver.xmlopt, format_flags))) {
|
||||||
|
VIR_TEST_VERBOSE("failed to format output XML\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virTestCompareToFile(actual, outfile) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
testqemuActiveXML2XMLActive(const void *opaque)
|
||||||
|
{
|
||||||
|
testQemuInfo *info = (testQemuInfo *) opaque;
|
||||||
|
|
||||||
|
return testqemuActiveXML2XMLCommon(info, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
testqemuActiveXML2XMLInactive(const void *opaque)
|
||||||
|
{
|
||||||
|
testQemuInfo *info = (testQemuInfo *) opaque;
|
||||||
|
|
||||||
|
return testqemuActiveXML2XMLCommon(info, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void G_GNUC_UNUSED
|
||||||
|
testRunActive(const char *name,
|
||||||
|
const char *suffix,
|
||||||
|
struct testQemuConf *testConf,
|
||||||
|
int *ret,
|
||||||
|
...)
|
||||||
|
{
|
||||||
|
g_autofree char *name_active = g_strdup_printf("QEMU active-XML -> active-XML %s", name);
|
||||||
|
g_autofree char *name_inactive = g_strdup_printf("QEMU activeXML -> inactive-XMLXML %s", name);
|
||||||
|
g_autoptr(testQemuInfo) info = g_new0(testQemuInfo, 1);
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
info->name = name;
|
||||||
|
info->conf = testConf;
|
||||||
|
|
||||||
|
va_start(ap, ret);
|
||||||
|
testQemuInfoSetArgs(info, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
info->infile = g_strdup_printf("%s/qemuxml2argvdata/%s.xml", abs_srcdir,
|
||||||
|
info->name);
|
||||||
|
|
||||||
|
info->out_xml_active = g_strdup_printf("%s/qemuxmlactive2xmldata/%s-active%s.xml",
|
||||||
|
abs_srcdir, info->name, suffix);
|
||||||
|
|
||||||
|
info->out_xml_inactive = g_strdup_printf("%s/qemuxmlactive2xmldata/%s-inactive%s.xml",
|
||||||
|
abs_srcdir, info->name, suffix);
|
||||||
|
|
||||||
|
virTestRunLog(ret, name_inactive, testqemuActiveXML2XMLInactive, info);
|
||||||
|
virTestRunLog(ret, name_active, testqemuActiveXML2XMLActive, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
mymain(void)
|
mymain(void)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
g_autoptr(virConnect) conn = NULL;
|
g_autoptr(virConnect) conn = NULL;
|
||||||
struct testQemuConf testConf = { NULL, NULL, NULL, NULL, NULL };
|
g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps();
|
||||||
|
g_autoptr(GHashTable) capscache = virHashNew(virObjectUnref);
|
||||||
|
struct testQemuConf testConf = { .capslatest = capslatest,
|
||||||
|
.capscache = capscache,
|
||||||
|
.qapiSchemaCache = NULL };
|
||||||
|
|
||||||
if (qemuTestDriverInit(&driver) < 0)
|
if (qemuTestDriverInit(&driver) < 0)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -107,6 +213,10 @@ mymain(void)
|
|||||||
virSetConnectSecret(conn);
|
virSetConnectSecret(conn);
|
||||||
virSetConnectStorage(conn);
|
virSetConnectStorage(conn);
|
||||||
|
|
||||||
|
#define DO_TEST_ACTIVE_CAPS_LATEST(_name) \
|
||||||
|
testRunActive(_name, ".x86_64-latest", &testConf, &ret, \
|
||||||
|
ARG_CAPS_ARCH, "x86_64", ARG_CAPS_VER, "latest", ARG_END);
|
||||||
|
|
||||||
#define DO_TEST_STATUS(_name) \
|
#define DO_TEST_STATUS(_name) \
|
||||||
do { \
|
do { \
|
||||||
if (testRunStatus(_name, &testConf, ARG_END) < 0) \
|
if (testRunStatus(_name, &testConf, ARG_END) < 0) \
|
||||||
|
@ -958,7 +958,10 @@ testQemuInfoFree(testQemuInfo *info)
|
|||||||
{
|
{
|
||||||
VIR_FREE(info->infile);
|
VIR_FREE(info->infile);
|
||||||
VIR_FREE(info->outfile);
|
VIR_FREE(info->outfile);
|
||||||
|
VIR_FREE(info->out_xml_active);
|
||||||
|
VIR_FREE(info->out_xml_inactive);
|
||||||
VIR_FREE(info->errfile);
|
VIR_FREE(info->errfile);
|
||||||
|
virDomainDefFree(info->def);
|
||||||
virObjectUnref(info->qemuCaps);
|
virObjectUnref(info->qemuCaps);
|
||||||
g_clear_pointer(&info->args.fakeCapsAdd, virBitmapFree);
|
g_clear_pointer(&info->args.fakeCapsAdd, virBitmapFree);
|
||||||
g_clear_pointer(&info->args.fakeCapsDel, virBitmapFree);
|
g_clear_pointer(&info->args.fakeCapsDel, virBitmapFree);
|
||||||
|
@ -100,7 +100,10 @@ struct _testQemuInfo {
|
|||||||
const char *name;
|
const char *name;
|
||||||
char *infile;
|
char *infile;
|
||||||
char *outfile;
|
char *outfile;
|
||||||
|
char *out_xml_active;
|
||||||
|
char *out_xml_inactive;
|
||||||
char *errfile;
|
char *errfile;
|
||||||
|
virDomainDef *def; /* parsed domain definition */
|
||||||
virQEMUCaps *qemuCaps;
|
virQEMUCaps *qemuCaps;
|
||||||
qemuNbdkitCaps *nbdkitCaps;
|
qemuNbdkitCaps *nbdkitCaps;
|
||||||
const char *migrateFrom;
|
const char *migrateFrom;
|
||||||
|
Loading…
Reference in New Issue
Block a user