2018-03-19 22:45:51 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011-2013 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "virjson.h"
|
|
|
|
#include "virbuffer.h"
|
|
|
|
#include "virxml.h"
|
2020-08-07 14:02:03 +00:00
|
|
|
#include "virhash.h"
|
2018-03-19 22:45:51 +00:00
|
|
|
#include "testutils.h"
|
|
|
|
#include "testutilsqemu.h"
|
2020-08-07 14:02:03 +00:00
|
|
|
#include "tests/testutilsqemuschema.h"
|
2018-03-19 22:45:51 +00:00
|
|
|
#include "qemumonitortestutils.h"
|
|
|
|
#include "qemu/qemu_migration_params.h"
|
2018-12-13 14:53:50 +00:00
|
|
|
#define LIBVIRT_QEMU_MIGRATION_PARAMSPRIV_H_ALLOW
|
2018-03-19 22:45:51 +00:00
|
|
|
#include "qemu/qemu_migration_paramspriv.h"
|
|
|
|
#include "qemu/qemu_monitor.h"
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
|
|
|
typedef struct _qemuMigParamsData qemuMigParamsData;
|
|
|
|
struct _qemuMigParamsData {
|
|
|
|
virDomainXMLOptionPtr xmlopt;
|
|
|
|
const char *name;
|
2020-10-22 17:04:18 +00:00
|
|
|
GHashTable *qmpschema;
|
2018-03-19 22:45:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
qemuMigParamsTestFormatXML(virBufferPtr buf,
|
|
|
|
qemuMigrationParamsPtr migParams)
|
|
|
|
{
|
|
|
|
virBufferAddLit(buf, "<test>\n");
|
|
|
|
virBufferAdjustIndent(buf, 2);
|
|
|
|
|
|
|
|
if (migParams)
|
|
|
|
qemuMigrationParamsFormat(buf, migParams);
|
|
|
|
|
|
|
|
virBufferAdjustIndent(buf, -2);
|
|
|
|
virBufferAddLit(buf, "</test>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
qemuMigParamsTestXML2XML(const void *opaque)
|
|
|
|
{
|
|
|
|
const qemuMigParamsData *data = opaque;
|
2020-07-02 23:35:41 +00:00
|
|
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
2020-07-28 19:57:28 +00:00
|
|
|
g_autofree char *xmlFile = NULL;
|
2020-07-28 19:58:18 +00:00
|
|
|
g_autoptr(xmlDoc) doc = NULL;
|
|
|
|
g_autoptr(xmlXPathContext) ctxt = NULL;
|
|
|
|
g_autoptr(qemuMigrationParams) migParams = NULL;
|
2020-07-28 19:57:28 +00:00
|
|
|
g_autofree char *actualXML = NULL;
|
2018-03-19 22:45:51 +00:00
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
xmlFile = g_strdup_printf("%s/qemumigparamsdata/%s.xml", abs_srcdir,
|
|
|
|
data->name);
|
2018-03-19 22:45:51 +00:00
|
|
|
|
|
|
|
if (!(doc = virXMLParseFileCtxt(xmlFile, &ctxt)))
|
2020-07-28 21:17:02 +00:00
|
|
|
return -1;
|
2018-03-19 22:45:51 +00:00
|
|
|
|
|
|
|
if (qemuMigrationParamsParse(ctxt, &migParams) < 0)
|
2020-07-28 21:17:02 +00:00
|
|
|
return -1;
|
2018-03-19 22:45:51 +00:00
|
|
|
|
|
|
|
qemuMigParamsTestFormatXML(&buf, migParams);
|
|
|
|
|
|
|
|
if (!(actualXML = virBufferContentAndReset(&buf)))
|
2020-07-28 21:17:02 +00:00
|
|
|
return -1;
|
2018-03-19 22:45:51 +00:00
|
|
|
|
|
|
|
if (virTestCompareToFile(actualXML, xmlFile) < 0)
|
2020-07-28 21:17:02 +00:00
|
|
|
return -1;
|
2018-03-19 22:45:51 +00:00
|
|
|
|
2020-07-28 21:17:02 +00:00
|
|
|
return 0;
|
2018-03-19 22:45:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
qemuMigParamsTestXML(const void *opaque)
|
|
|
|
{
|
|
|
|
const qemuMigParamsData *data = opaque;
|
2020-07-02 23:35:41 +00:00
|
|
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
2020-07-28 19:57:28 +00:00
|
|
|
g_autofree char *replyFile = NULL;
|
|
|
|
g_autofree char *xmlFile = NULL;
|
2018-03-19 22:45:51 +00:00
|
|
|
qemuMonitorTestPtr mon = NULL;
|
2020-07-28 19:58:18 +00:00
|
|
|
g_autoptr(virJSONValue) params = NULL;
|
|
|
|
g_autoptr(qemuMigrationParams) migParams = NULL;
|
2020-07-28 19:57:28 +00:00
|
|
|
g_autofree char *actualXML = NULL;
|
2018-03-19 22:45:51 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
replyFile = g_strdup_printf("%s/qemumigparamsdata/%s.reply",
|
|
|
|
abs_srcdir, data->name);
|
|
|
|
xmlFile = g_strdup_printf("%s/qemumigparamsdata/%s.xml",
|
|
|
|
abs_srcdir, data->name);
|
2018-03-19 22:45:51 +00:00
|
|
|
|
|
|
|
if (!(mon = qemuMonitorTestNewFromFile(replyFile, data->xmlopt, true)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorGetMigrationParams(qemuMonitorTestGetMonitor(mon),
|
|
|
|
¶ms) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(migParams = qemuMigrationParamsFromJSON(params)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
qemuMigParamsTestFormatXML(&buf, migParams);
|
|
|
|
|
|
|
|
if (!(actualXML = virBufferContentAndReset(&buf)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virTestCompareToFile(actualXML, xmlFile) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
qemuMonitorTestFree(mon);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
qemuMigParamsTestJSON(const void *opaque)
|
|
|
|
{
|
|
|
|
const qemuMigParamsData *data = opaque;
|
2020-07-28 19:57:28 +00:00
|
|
|
g_autofree char *replyFile = NULL;
|
|
|
|
g_autofree char *jsonFile = NULL;
|
2018-03-19 22:45:51 +00:00
|
|
|
qemuMonitorTestPtr mon = NULL;
|
2020-07-28 19:58:18 +00:00
|
|
|
g_autoptr(virJSONValue) paramsIn = NULL;
|
|
|
|
g_autoptr(virJSONValue) paramsOut = NULL;
|
|
|
|
g_autoptr(qemuMigrationParams) migParams = NULL;
|
2020-07-28 19:57:28 +00:00
|
|
|
g_autofree char *actualJSON = NULL;
|
2020-08-07 14:02:03 +00:00
|
|
|
g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER;
|
2018-03-19 22:45:51 +00:00
|
|
|
int ret = -1;
|
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
replyFile = g_strdup_printf("%s/qemumigparamsdata/%s.reply",
|
|
|
|
abs_srcdir, data->name);
|
|
|
|
jsonFile = g_strdup_printf("%s/qemumigparamsdata/%s.json",
|
|
|
|
abs_srcdir, data->name);
|
2018-03-19 22:45:51 +00:00
|
|
|
|
|
|
|
if (!(mon = qemuMonitorTestNewFromFile(replyFile, data->xmlopt, true)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (qemuMonitorGetMigrationParams(qemuMonitorTestGetMonitor(mon),
|
|
|
|
¶msIn) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(migParams = qemuMigrationParamsFromJSON(paramsIn)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(paramsOut = qemuMigrationParamsToJSON(migParams)) ||
|
|
|
|
!(actualJSON = virJSONValueToString(paramsOut, true)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2020-08-07 14:02:03 +00:00
|
|
|
if (testQEMUSchemaValidateCommand("migrate-set-parameters",
|
|
|
|
paramsOut,
|
|
|
|
data->qmpschema,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
&debug) < 0) {
|
|
|
|
VIR_TEST_VERBOSE("failed to validate migration params '%s' against QMP schema: %s",
|
|
|
|
actualJSON, virBufferCurrentContent(&debug));
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2018-03-19 22:45:51 +00:00
|
|
|
if (virTestCompareToFile(actualJSON, jsonFile) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
qemuMonitorTestFree(mon);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
2020-10-22 17:04:18 +00:00
|
|
|
g_autoptr(GHashTable) qmpschema = NULL;
|
2018-03-19 22:45:51 +00:00
|
|
|
virQEMUDriver driver;
|
|
|
|
int ret = 0;
|
|
|
|
|
2019-09-16 16:44:23 +00:00
|
|
|
if (qemuTestDriverInit(&driver) < 0)
|
2018-03-19 22:45:51 +00:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
virEventRegisterDefaultImpl();
|
|
|
|
|
2020-08-07 14:02:03 +00:00
|
|
|
if (!(qmpschema = testQEMUSchemaLoadLatest("x86_64"))) {
|
|
|
|
VIR_TEST_VERBOSE("failed to load QMP schema");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2018-03-19 22:45:51 +00:00
|
|
|
#define DO_TEST(name) \
|
|
|
|
do { \
|
|
|
|
qemuMigParamsData data = { \
|
2020-08-07 14:02:03 +00:00
|
|
|
driver.xmlopt, name, qmpschema \
|
2018-03-19 22:45:51 +00:00
|
|
|
}; \
|
|
|
|
if (virTestRun(name " (xml)", qemuMigParamsTestXML, &data) < 0) \
|
|
|
|
ret = -1; \
|
|
|
|
if (virTestRun(name " (json)", qemuMigParamsTestJSON, &data) < 0) \
|
|
|
|
ret = -1; \
|
|
|
|
if (virTestRun(name " (xml2xml)", qemuMigParamsTestXML2XML, &data) < 0) \
|
|
|
|
ret = -1; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
DO_TEST("unsupported");
|
2018-03-19 22:46:46 +00:00
|
|
|
DO_TEST("empty");
|
|
|
|
DO_TEST("basic");
|
2018-03-19 22:42:01 +00:00
|
|
|
DO_TEST("tls");
|
|
|
|
DO_TEST("tls-enabled");
|
|
|
|
DO_TEST("tls-hostname");
|
2018-03-19 22:45:51 +00:00
|
|
|
|
|
|
|
qemuTestDriverFree(&driver);
|
|
|
|
|
|
|
|
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_TEST_MAIN(mymain)
|