[libvirt] [PATCH] qemumonitorjsontest: Validate more commands against schema
by Eric Blake
The DO_TEST() macro in qemumonitorjsontest.c was not passing the
schema through, which meant that we were not validating any of those
tests for correct usage according to the schema.
Tested by using this hack, where the test mistakenly passed pre-patch,
but correctly diagnosed the garbage post-patch:
| diff --git i/src/qemu/qemu_monitor_json.c w/src/qemu/qemu_monitor_json.c
| index 53a7de8b77..86d8450814 100644
| --- i/src/qemu/qemu_monitor_json.c
| +++ w/src/qemu/qemu_monitor_json.c
| @@ -1532,7 +1532,8 @@ qemuMonitorJSONGetStatus(qemuMonitorPtr mon,
| if (reason)
| *reason = VIR_DOMAIN_PAUSED_UNKNOWN;
|
| - if (!(cmd = qemuMonitorJSONMakeCommand("query-status", NULL)))
| + if (!(cmd = qemuMonitorJSONMakeCommand("query-status",
| + "s:garbage", "foo", NULL)))
| return -1;
|
| if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
Suggested-by: Peter Krempa <pkrempa(a)redhat.com>
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
tests/qemumonitorjsontest.c | 251 +++++++++++++++++++++---------------
1 file changed, 149 insertions(+), 102 deletions(-)
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index 0894e748ae..a7f64058d4 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -48,6 +48,12 @@ struct _testQemuMonitorJSONSimpleFuncData {
virHashTablePtr schema;
};
+typedef struct _testGenericData testGenericData;
+struct _testGenericData {
+ virDomainXMLOptionPtr xmlopt;
+ virHashTablePtr schema;
+};
+
const char *queryBlockReply =
"{"
" \"return\": ["
@@ -142,10 +148,11 @@ const char *queryBlockReply =
"}";
static int
-testQemuMonitorJSONGetStatus(const void *data)
+testQemuMonitorJSONGetStatus(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
bool running = false;
virDomainPausedReason reason = 0;
@@ -236,10 +243,11 @@ testQemuMonitorJSONGetStatus(const void *data)
}
static int
-testQemuMonitorJSONGetVersion(const void *data)
+testQemuMonitorJSONGetVersion(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
int major;
int minor;
@@ -339,10 +347,11 @@ testQemuMonitorJSONGetVersion(const void *data)
}
static int
-testQemuMonitorJSONGetMachines(const void *data)
+testQemuMonitorJSONGetMachines(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
qemuMonitorMachineInfoPtr *info;
int ninfo = 0;
@@ -421,10 +430,11 @@ testQemuMonitorJSONGetMachines(const void *data)
static int
-testQemuMonitorJSONGetCPUDefinitions(const void *data)
+testQemuMonitorJSONGetCPUDefinitions(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
qemuMonitorCPUDefInfoPtr *cpus = NULL;
int ncpus = 0;
@@ -504,10 +514,11 @@ testQemuMonitorJSONGetCPUDefinitions(const void *data)
static int
-testQemuMonitorJSONGetCommands(const void *data)
+testQemuMonitorJSONGetCommands(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
char **commands = NULL;
int ncommands = 0;
@@ -569,10 +580,11 @@ testQemuMonitorJSONGetCommands(const void *data)
static int
-testQemuMonitorJSONGetTPMModels(const void *data)
+testQemuMonitorJSONGetTPMModels(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
char **tpmmodels = NULL;
int ntpmmodels = 0;
@@ -622,10 +634,11 @@ testQemuMonitorJSONGetTPMModels(const void *data)
static int
-testQemuMonitorJSONGetCommandLineOptionParameters(const void *data)
+testQemuMonitorJSONGetCommandLineOptionParameters(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
char **params = NULL;
int nparams = 0;
@@ -776,6 +789,7 @@ testQemuMonitorJSONAttachChardev(const void *opaque)
static int
qemuMonitorJSONTestAttachOneChardev(virDomainXMLOptionPtr xmlopt,
+ virHashTablePtr schema,
const char *label,
virDomainChrSourceDefPtr chr,
const char *expectargs,
@@ -801,7 +815,7 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOptionPtr xmlopt,
data.chr = chr;
data.fail = fail;
data.expectPty = expectPty;
- if (!(data.test = qemuMonitorTestNewSimple(true, xmlopt)))
+ if (!(data.test = qemuMonitorTestNewSchema(xmlopt, schema)))
goto cleanup;
if (qemuMonitorTestAddItemExpect(data.test, "chardev-add",
@@ -821,14 +835,15 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOptionPtr xmlopt,
}
static int
-qemuMonitorJSONTestAttachChardev(virDomainXMLOptionPtr xmlopt)
+qemuMonitorJSONTestAttachChardev(virDomainXMLOptionPtr xmlopt,
+ virHashTablePtr schema)
{
virDomainChrSourceDef chr;
int ret = 0;
#define CHECK(label, fail, expectargs) \
- if (qemuMonitorJSONTestAttachOneChardev(xmlopt, label, &chr, expectargs, \
- NULL, NULL, fail) < 0) \
+ if (qemuMonitorJSONTestAttachOneChardev(xmlopt, schema, label, &chr, \
+ expectargs, NULL, NULL, fail) < 0) \
ret = -1
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_NULL };
@@ -840,7 +855,7 @@ qemuMonitorJSONTestAttachChardev(virDomainXMLOptionPtr xmlopt)
"{'id':'alias','backend':{'type':'null','data':{}}}");
chr = (virDomainChrSourceDef) { .type = VIR_DOMAIN_CHR_TYPE_PTY };
- if (qemuMonitorJSONTestAttachOneChardev(xmlopt, "pty", &chr,
+ if (qemuMonitorJSONTestAttachOneChardev(xmlopt, schema, "pty", &chr,
"{'id':'alias',"
"'backend':{'type':'pty',"
"'data':{}}}",
@@ -938,10 +953,11 @@ qemuMonitorJSONTestAttachChardev(virDomainXMLOptionPtr xmlopt)
static int
-testQemuMonitorJSONDetachChardev(const void *data)
+testQemuMonitorJSONDetachChardev(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
if (!test)
@@ -971,10 +987,11 @@ testQemuMonitorJSONDetachChardev(const void *data)
* {"name": "type", "type": "string"}]}
*/
static int
-testQemuMonitorJSONGetListPaths(const void *data)
+testQemuMonitorJSONGetListPaths(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
qemuMonitorJSONListPathPtr *paths;
int npaths = 0;
@@ -1049,10 +1066,11 @@ testQemuMonitorJSONGetListPaths(const void *data)
* {"return": true}
*/
static int
-testQemuMonitorJSONGetObjectProperty(const void *data)
+testQemuMonitorJSONGetObjectProperty(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
qemuMonitorJSONObjectProperty prop;
@@ -1092,10 +1110,11 @@ testQemuMonitorJSONGetObjectProperty(const void *data)
* false is not a good idea...
*/
static int
-testQemuMonitorJSONSetObjectProperty(const void *data)
+testQemuMonitorJSONSetObjectProperty(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
qemuMonitorJSONObjectProperty prop;
@@ -1144,10 +1163,11 @@ testQemuMonitorJSONSetObjectProperty(const void *data)
static int
-testQemuMonitorJSONGetDeviceAliases(const void *data)
+testQemuMonitorJSONGetDeviceAliases(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
char **aliases = NULL;
const char **alias;
@@ -1204,10 +1224,11 @@ testQemuMonitorJSONGetDeviceAliases(const void *data)
}
static int
-testQemuMonitorJSONCPU(const void *data)
+testQemuMonitorJSONCPU(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
bool running = false;
virDomainPausedReason reason = 0;
@@ -1407,10 +1428,11 @@ testQEMUMonitorJSONqemuMonitorJSONQueryCPUsHelper(qemuMonitorTestPtr test,
static int
-testQemuMonitorJSONqemuMonitorJSONQueryCPUs(const void *data)
+testQemuMonitorJSONqemuMonitorJSONQueryCPUs(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
struct qemuMonitorQueryCpusEntry expect_slow[] = {
{0, 17622, (char *) "/machine/unattached/device[0]", true},
@@ -1501,10 +1523,11 @@ testQemuMonitorJSONqemuMonitorJSONQueryCPUs(const void *data)
}
static int
-testQemuMonitorJSONqemuMonitorJSONGetBalloonInfo(const void *data)
+testQemuMonitorJSONqemuMonitorJSONGetBalloonInfo(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
unsigned long long currmem;
@@ -1537,10 +1560,11 @@ testQemuMonitorJSONqemuMonitorJSONGetBalloonInfo(const void *data)
}
static int
-testQemuMonitorJSONqemuMonitorJSONGetVirtType(const void *data)
+testQemuMonitorJSONqemuMonitorJSONGetVirtType(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
virDomainVirtType virtType;
@@ -1614,10 +1638,11 @@ testHashEqualQemuDomainDiskInfo(const void *value1, const void *value2)
}
static int
-testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *data)
+testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
virHashTablePtr blockDevices = NULL, expectedBlockDevices = NULL;
struct qemuDomainDiskInfo *info;
@@ -1693,10 +1718,11 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void *data)
}
static int
-testQemuMonitorJSONqemuMonitorJSONGetAllBlockStatsInfo(const void *data)
+testQemuMonitorJSONqemuMonitorJSONGetAllBlockStatsInfo(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
virHashTablePtr blockstats = NULL;
qemuBlockStatsPtr stats;
int ret = -1;
@@ -1855,10 +1881,11 @@ testQemuMonitorJSONqemuMonitorJSONGetAllBlockStatsInfo(const void *data)
static int
-testQemuMonitorJSONqemuMonitorJSONGetMigrationCacheSize(const void *data)
+testQemuMonitorJSONqemuMonitorJSONGetMigrationCacheSize(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
unsigned long long cacheSize;
@@ -1891,10 +1918,11 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationCacheSize(const void *data)
}
static int
-testQemuMonitorJSONqemuMonitorJSONGetMigrationStats(const void *data)
+testQemuMonitorJSONqemuMonitorJSONGetMigrationStats(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
qemuMonitorMigrationStats stats, expectedStats;
char *error = NULL;
@@ -1986,10 +2014,11 @@ testHashEqualChardevInfo(const void *value1, const void *value2)
static int
-testQemuMonitorJSONqemuMonitorJSONGetChardevInfo(const void *data)
+testQemuMonitorJSONqemuMonitorJSONGetChardevInfo(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
virHashTablePtr info = NULL, expectedInfo = NULL;
qemuMonitorChardevInfo info0 = { NULL, VIR_DOMAIN_CHR_DEVICE_STATE_DEFAULT };
@@ -2107,10 +2136,11 @@ testValidateGetBlockIoThrottle(const virDomainBlockIoTuneInfo *info,
static int
-testQemuMonitorJSONqemuMonitorJSONSetBlockIoThrottle(const void *data)
+testQemuMonitorJSONqemuMonitorJSONSetBlockIoThrottle(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
virDomainBlockIoTuneInfo info, expectedInfo;
@@ -2162,10 +2192,11 @@ testQemuMonitorJSONqemuMonitorJSONSetBlockIoThrottle(const void *data)
}
static int
-testQemuMonitorJSONqemuMonitorJSONGetTargetArch(const void *data)
+testQemuMonitorJSONqemuMonitorJSONGetTargetArch(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
char *arch;
@@ -2199,10 +2230,11 @@ testQemuMonitorJSONqemuMonitorJSONGetTargetArch(const void *data)
}
static int
-testQemuMonitorJSONqemuMonitorJSONGetMigrationCapabilities(const void *data)
+testQemuMonitorJSONqemuMonitorJSONGetMigrationCapabilities(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
const char *cap;
char **caps = NULL;
@@ -2259,10 +2291,11 @@ testQemuMonitorJSONqemuMonitorJSONGetMigrationCapabilities(const void *data)
}
static int
-testQemuMonitorJSONqemuMonitorJSONSendKey(const void *data)
+testQemuMonitorJSONqemuMonitorJSONSendKey(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
unsigned int keycodes[] = {43, 26, 46, 32};
@@ -2284,10 +2317,11 @@ testQemuMonitorJSONqemuMonitorJSONSendKey(const void *data)
}
static int
-testQemuMonitorJSONqemuMonitorJSONSendKeyHoldtime(const void *data)
+testQemuMonitorJSONqemuMonitorJSONSendKeyHoldtime(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
unsigned int keycodes[] = {43, 26, 46, 32};
@@ -2316,10 +2350,11 @@ testQemuMonitorJSONqemuMonitorJSONSendKeyHoldtime(const void *data)
}
static int
-testQemuMonitorJSONqemuMonitorSupportsActiveCommit(const void *data)
+testQemuMonitorJSONqemuMonitorSupportsActiveCommit(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
const char *error1 =
"{"
@@ -2362,10 +2397,11 @@ testQemuMonitorJSONqemuMonitorSupportsActiveCommit(const void *data)
}
static int
-testQemuMonitorJSONqemuMonitorJSONGetDumpGuestMemoryCapability(const void *data)
+testQemuMonitorJSONqemuMonitorJSONGetDumpGuestMemoryCapability(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
int ret = -1;
int cap;
const char *reply =
@@ -2407,6 +2443,7 @@ testQemuMonitorJSONqemuMonitorJSONGetDumpGuestMemoryCapability(const void *data)
struct testCPUData {
const char *name;
virDomainXMLOptionPtr xmlopt;
+ virHashTablePtr schema;
};
@@ -2414,7 +2451,8 @@ static int
testQemuMonitorJSONGetCPUData(const void *opaque)
{
const struct testCPUData *data = opaque;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, data->xmlopt);
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(data->xmlopt,
+ data->schema);
virCPUDataPtr cpuData = NULL;
char *jsonFile = NULL;
char *dataFile = NULL;
@@ -2480,8 +2518,9 @@ testQemuMonitorJSONGetCPUData(const void *opaque)
static int
testQemuMonitorJSONGetNonExistingCPUData(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr) opaque;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
virCPUDataPtr cpuData = NULL;
int rv, ret = -1;
@@ -2522,10 +2561,11 @@ testQemuMonitorJSONGetNonExistingCPUData(const void *opaque)
}
static int
-testQemuMonitorJSONGetIOThreads(const void *data)
+testQemuMonitorJSONGetIOThreads(const void *opaque)
{
- virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+ const testGenericData *data = opaque;
+ virDomainXMLOptionPtr xmlopt = data->xmlopt;
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
qemuMonitorIOThreadInfoPtr *info;
int ninfo = 0;
int ret = -1;
@@ -2596,6 +2636,7 @@ struct testCPUInfoData {
size_t maxvcpus;
virDomainXMLOptionPtr xmlopt;
bool fast;
+ virHashTablePtr schema;
};
@@ -2664,7 +2705,8 @@ static int
testQemuMonitorCPUInfo(const void *opaque)
{
const struct testCPUInfoData *data = opaque;
- qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, data->xmlopt);
+ qemuMonitorTestPtr test = qemuMonitorTestNewSchema(data->xmlopt,
+ data->schema);
virDomainObjPtr vm = NULL;
char *queryCpusFile = NULL;
char *queryHotpluggableFile = NULL;
@@ -2921,8 +2963,11 @@ mymain(void)
}
#define DO_TEST(name) \
- if (virTestRun(# name, testQemuMonitorJSON ## name, driver.xmlopt) < 0) \
- ret = -1
+ do { \
+ testGenericData data = { driver.xmlopt, qapiData.schema }; \
+ if (virTestRun(# name, testQemuMonitorJSON ## name, &data) < 0) \
+ ret = -1; \
+ } while (0)
#define DO_TEST_SIMPLE(CMD, FNC, ...) \
simpleFunc = (testQemuMonitorJSONSimpleFuncData) {.cmd = CMD, .func = FNC, \
@@ -2941,7 +2986,7 @@ mymain(void)
#define DO_TEST_CPU_DATA(name) \
do { \
- struct testCPUData data = { name, driver.xmlopt }; \
+ struct testCPUData data = { name, driver.xmlopt, qapiData.schema }; \
const char *label = "GetCPUData(" name ")"; \
if (virTestRun(label, testQemuMonitorJSONGetCPUData, &data) < 0) \
ret = -1; \
@@ -2949,7 +2994,8 @@ mymain(void)
#define DO_TEST_CPU_INFO(name, maxvcpus) \
do { \
- struct testCPUInfoData data = {name, maxvcpus, driver.xmlopt, false}; \
+ struct testCPUInfoData data = {name, maxvcpus, driver.xmlopt, false, \
+ qapiData.schema}; \
if (virTestRun("GetCPUInfo(" name ")", testQemuMonitorCPUInfo, \
&data) < 0) \
ret = -1; \
@@ -2957,7 +3003,8 @@ mymain(void)
#define DO_TEST_CPU_INFO_FAST(name, maxvcpus) \
do { \
- struct testCPUInfoData data = {name, maxvcpus, driver.xmlopt, true}; \
+ struct testCPUInfoData data = {name, maxvcpus, driver.xmlopt, true, \
+ qapiData.schema }; \
if (virTestRun("GetCPUInfo(" name ")", testQemuMonitorCPUInfo, \
&data) < 0) \
ret = -1; \
@@ -2970,7 +3017,7 @@ mymain(void)
DO_TEST(GetCommands);
DO_TEST(GetTPMModels);
DO_TEST(GetCommandLineOptionParameters);
- if (qemuMonitorJSONTestAttachChardev(driver.xmlopt) < 0)
+ if (qemuMonitorJSONTestAttachChardev(driver.xmlopt, qapiData.schema) < 0)
ret = -1;
DO_TEST(DetachChardev);
DO_TEST(GetListPaths);
--
2.20.1
5 years, 10 months
[libvirt] [PATCH] test_driver: implement virConnectGetLibVersion
by Ilias Stamatis
Signed-off-by: Ilias Stamatis <stamatis.iliass(a)gmail.com>
---
src/test/test_driver.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 1aa79ce898..dc267b6ecd 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1453,6 +1453,14 @@ static char *testConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
}
+static int testConnectGetLibVersion(virConnectPtr conn ATTRIBUTE_UNUSED,
+ unsigned long *libVer)
+{
+ *libVer = LIBVIR_VERSION_NUMBER;
+ return 0;
+}
+
+
static int testConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
{
return 1;
@@ -6988,6 +6996,7 @@ static virHypervisorDriver testHypervisorDriver = {
.connectClose = testConnectClose, /* 0.1.1 */
.connectGetVersion = testConnectGetVersion, /* 0.1.1 */
.connectGetHostname = testConnectGetHostname, /* 0.6.3 */
+ .connectGetLibVersion = testConnectGetLibVersion, /* 5.5.0 */
.connectGetMaxVcpus = testConnectGetMaxVcpus, /* 0.3.2 */
.nodeGetInfo = testNodeGetInfo, /* 0.1.1 */
.nodeGetCPUStats = testNodeGetCPUStats, /* 2.3.0 */
--
2.21.0
5 years, 10 months
[libvirt] [PATCHv2] virt-xml-validate: Allow input to be read from stdin
by Johannes Holmberg
Signed-off-by: Johannes Holmberg <johannes.holmberg(a)dataductus.se>
---
Changes from v1:
- Quotes around $TMPFILE everywhere.
- Explicit -n checks in if statements
- Fixed one instance of incorrect indentation
- Signed-off-by line in commit message
tools/virt-xml-validate.in | 46 ++++++++++++++++++++++++++++----------
1 file changed, 34 insertions(+), 12 deletions(-)
diff --git a/tools/virt-xml-validate.in b/tools/virt-xml-validate.in
index 64aeaaaa33..5cb7dcd276 100644
--- a/tools/virt-xml-validate.in
+++ b/tools/virt-xml-validate.in
@@ -16,7 +16,17 @@
set -e
-case $1 in
+TMPFILE=
+
+cleanup() {
+ if [ -n "$TMPFILE" ]; then
+ rm -f "$TMPFILE"
+ fi
+}
+
+trap cleanup EXIT
+
+case "$1" in
-h | --h | --he | --hel | --help)
cat <<EOF
Usage:
@@ -34,7 +44,7 @@ $0 (libvirt) @VERSION@
EOF
exit ;;
--) shift ;;
- -*)
+ -?*)
echo "$0: unrecognized option '$1'" >&2
exit 1 ;;
esac
@@ -42,18 +52,27 @@ esac
XMLFILE="$1"
TYPE="$2"
-if [ -z "$XMLFILE" ]; then
- echo "syntax: $0 XMLFILE [TYPE]" >&2
- exit 1
-fi
+if [ "$XMLFILE" = "-" ]; then
+ TMPFILE=`mktemp --tmpdir virt-xml.XXXX`
+ cat > "$TMPFILE"
+else
+ if [ -z "$XMLFILE" ]; then
+ echo "syntax: $0 XMLFILE [TYPE]" >&2
+ exit 1
+ fi
-if [ ! -f "$XMLFILE" ]; then
- echo "$0: document $XMLFILE does not exist" >&2
- exit 2
+ if [ ! -f "$XMLFILE" ]; then
+ echo "$0: document $XMLFILE does not exist" >&2
+ exit 2
+ fi
fi
if [ -z "$TYPE" ]; then
- ROOT=`xmllint --stream --debug "$XMLFILE" 2>/dev/null | grep "^0 1 " | awk '{ print $3 }'`
+ if [ -n "$TMPFILE" ]; then
+ ROOT=`xmllint --stream --debug - < "$TMPFILE" 2>/dev/null | grep "^0 1 " | awk '{ print $3 }'`
+ else
+ ROOT=`xmllint --stream --debug "$XMLFILE" 2>/dev/null | grep "^0 1 " | awk '{ print $3 }'`
+ fi
case "$ROOT" in
*domainsnapshot*) # Must come first, since *domain* is a substring
TYPE="domainsnapshot"
@@ -101,6 +120,9 @@ if [ ! -f "$SCHEMA" ]; then
exit 4
fi
-xmllint --noout --relaxng "$SCHEMA" "$XMLFILE"
-
+if [ -n "$TMPFILE" ]; then
+ xmllint --noout --relaxng "$SCHEMA" - < "$TMPFILE"
+else
+ xmllint --noout --relaxng "$SCHEMA" "$XMLFILE"
+fi
exit
--
2.17.1
5 years, 10 months
[libvirt] [PATCH 8.5/13] qemu: Rename qemuDomainSnapshotDiskDataFree to qemuDomainSnapshotDiskDataCleanup
by Peter Krempa
In commit cbb4d229de30b5 I named the function with 'free' suffix, but at
that time it already did some non-freeing tasks. Rename it to make it
obvious that it's not just memory managemet.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_driver.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 9736933143..f1886e37b6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15035,10 +15035,10 @@ typedef qemuDomainSnapshotDiskData *qemuDomainSnapshotDiskDataPtr;
static void
-qemuDomainSnapshotDiskDataFree(qemuDomainSnapshotDiskDataPtr data,
- size_t ndata,
- virQEMUDriverPtr driver,
- virDomainObjPtr vm)
+qemuDomainSnapshotDiskDataCleanup(qemuDomainSnapshotDiskDataPtr data,
+ size_t ndata,
+ virQEMUDriverPtr driver,
+ virDomainObjPtr vm)
{
size_t i;
@@ -15145,7 +15145,7 @@ qemuDomainSnapshotDiskDataCollect(virQEMUDriverPtr driver,
ret = 0;
cleanup:
- qemuDomainSnapshotDiskDataFree(data, ndata, driver, vm);
+ qemuDomainSnapshotDiskDataCleanup(data, ndata, driver, vm);
return ret;
}
@@ -15322,7 +15322,7 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
ret = -1;
cleanup:
- qemuDomainSnapshotDiskDataFree(diskdata, ndiskdata, driver, vm);
+ qemuDomainSnapshotDiskDataCleanup(diskdata, ndiskdata, driver, vm);
virErrorRestore(&orig_err);
return ret;
--
2.21.0
5 years, 10 months
[libvirt] [PATCH 1/2] test_driver: implement virConnectDomainXMLToNative
by Ilias Stamatis
Since this is the test driver, we can pretend that the native hypervisor
representation is the same as libvirt's domain XML.
Signed-off-by: Ilias Stamatis <stamatis.iliass(a)gmail.com>
---
src/test/test_driver.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 1aa79ce898..ec1d3cacbc 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1563,6 +1563,39 @@ static int testConnectNumOfDomains(virConnectPtr conn)
return count;
}
+
+# define TEST_CONFIG_FORMAT_ARGV "test-test"
+
+
+static char *testConnectDomainXMLToNative(virConnectPtr conn,
+ const char *format,
+ const char *dxml,
+ unsigned int flags)
+{
+ char *ret = NULL;
+ virDomainDefPtr def = NULL;
+ testDriverPtr privconn = conn->privateData;
+
+ virCheckFlags(0, NULL);
+
+ if (STRNEQ(format, TEST_CONFIG_FORMAT_ARGV)) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("Unsupported config format '%s'"), format);
+ return NULL;
+ }
+
+ if ((def = virDomainDefParseString(dxml, privconn->caps, privconn->xmlopt, NULL,
+ VIR_DOMAIN_DEF_PARSE_INACTIVE)) == NULL)
+ goto cleanup;
+
+ ret = virDomainDefFormat(def, privconn->caps, 0);
+
+ cleanup:
+ virDomainDefFree(def);
+ return ret;
+}
+
+
static int testDomainIsActive(virDomainPtr dom)
{
virDomainObjPtr obj;
@@ -6998,6 +7031,7 @@ static virHypervisorDriver testHypervisorDriver = {
.connectGetType = testConnectGetType, /* 2.3.0 */
.connectListDomains = testConnectListDomains, /* 0.1.1 */
.connectNumOfDomains = testConnectNumOfDomains, /* 0.1.1 */
+ .connectDomainXMLToNative = testConnectDomainXMLToNative, /* 5.5.0 */
.connectListAllDomains = testConnectListAllDomains, /* 0.9.13 */
.domainCreateXML = testDomainCreateXML, /* 0.1.4 */
.domainLookupByID = testDomainLookupByID, /* 0.1.1 */
--
2.21.0
5 years, 10 months
[libvirt] [PATCH] qemu: check if numa cell's cpu range match with cpu topology count
by Maxiwell S. Garcia
If the XML doesn't have numa cells, this check is not necessary. But
if numa cells are present, it must match with cpu topology count.
Signed-off-by: Maxiwell S. Garcia <maxiwell(a)linux.ibm.com>
---
src/qemu/qemu_domain.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 4d3a8868b2..ab81b9a5be 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4173,15 +4173,24 @@ qemuDomainDefValidate(const virDomainDef *def,
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS)) {
unsigned int topologycpus;
unsigned int granularity;
+ unsigned int numacpus;
/* Starting from QEMU 2.5, max vCPU count and overall vCPU topology
* must agree. We only actually enforce this with QEMU 2.7+, due
* to the capability check above */
- if (virDomainDefGetVcpusTopology(def, &topologycpus) == 0 &&
- topologycpus != virDomainDefGetVcpusMax(def)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("CPU topology doesn't match maximum vcpu count"));
- goto cleanup;
+ if (virDomainDefGetVcpusTopology(def, &topologycpus) == 0) {
+ if (topologycpus != virDomainDefGetVcpusMax(def)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("CPU topology doesn't match maximum vcpu count"));
+ goto cleanup;
+ }
+
+ numacpus = virDomainNumaGetCPUCountTotal(def->numa);
+ if ((numacpus != 0) && (topologycpus != numacpus)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("CPU topology doesn't match numa CPU count"));
+ goto cleanup;
+ }
}
/* vCPU hotplug granularity must be respected */
--
2.20.1
5 years, 10 months
[libvirt] [PATCH] Fix regression in lxcOpenNamespace
by Sergei Turchanov
This fixes regression caused by the 1d39dbaf637db03f6e597ed56b96aa065710b4a1
fdlist[i] erroneously was replaced by fdlist[1] which caused
lxcOpenNamespace to return a list with identical elements.
---
libvirt-lxc-override.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libvirt-lxc-override.c b/libvirt-lxc-override.c
index 60c2e48..d7af154 100644
--- a/libvirt-lxc-override.c
+++ b/libvirt-lxc-override.c
@@ -83,7 +83,7 @@ libvirt_lxc_virDomainLxcOpenNamespace(PyObject *self ATTRIBUTE_UNUSED,
goto error;
for (i = 0; i < c_retval; i++)
- VIR_PY_LIST_APPEND_GOTO(py_retval, libvirt_intWrap(fdlist[1]), error);
+ VIR_PY_LIST_APPEND_GOTO(py_retval, libvirt_intWrap(fdlist[i]), error);
cleanup:
VIR_FREE(fdlist);
--
2.17.1
5 years, 10 months
[libvirt] [PATCH 00/13] qemu: External disk snapshot code refactors/cleanups (blockdev-add saga)
by Peter Krempa
Few cleanups to the snapshot code extracted from my blockdev branch.
Peter Krempa (13):
qemu: snapshot: Pass 'cfg' to external snapshot functions
qemu: Use VIR_AUTOPTR in qemuDomainSnapshotCreateDiskActive
qemu: Use virErrorPreserveLast in qemuDomainSnapshotCreateDiskActive
qemu: Use VIR_AUTO* in qemuDomainSnapshotCreateActiveExternal
qemu: snapshot: Remove unused cleanup section in
qemuDomainSnapshotCreateSingleDiskActive
qemu: snapshot: Always save status and config after
qemuDomainSnapshotCreateDiskActive
qemu: snapshot: Always save config XML after
qemuDomainSnapshotCreateDiskActive
qemu: snapshot: Densely pack data in qemuDomainSnapshotDiskDataCollect
qemu: snapshot: Move all cleanup of snapshot disk data to
qemuDomainSnapshotDiskDataFree
qemu: snapshot: Don't overload 'ret' in
qemuDomainSnapshotCreateDiskActive
qemu: snapshot: Unify 'cleanup' and 'error' in
qemuDomainSnapshotCreateDiskActive
qemu: snapshot: Return early if there's nothing to snapshot
qemu: snapshot: Remove unnecessary 'do_transaction' logic in
qemuDomainSnapshotCreateDiskActive
src/qemu/qemu_driver.c | 189 +++++++++++++++++------------------------
1 file changed, 79 insertions(+), 110 deletions(-)
--
2.21.0
5 years, 10 months
[libvirt] [PATCH 0/4] tests: qemu: Allow QMP schema testing with qemuMonitorTestProcessCommandVerbatim
by Peter Krempa
Allow more tests to be run against QMP schema checker.
Peter Krempa (4):
tests: Refactor cleanup in qemuMonitorTestProcessCommandVerbatim
tests: qemu: Add QMP schema checking in
qemuMonitorTestProcessCommandVerbatim
tests: Allow QMP schema testing in qemuMonitorTestNewFromFileFull
tests: qemuhotplug: Use schema testing with
qemuMonitorTestNewFromFileFull
tests/qemucapabilitiestest.c | 3 ++-
tests/qemuhotplugtest.c | 21 +++++++++++++++++----
tests/qemumonitortestutils.c | 34 +++++++++++++++++++++++++---------
tests/qemumonitortestutils.h | 3 ++-
4 files changed, 46 insertions(+), 15 deletions(-)
--
2.21.0
5 years, 10 months
[libvirt] [PATCH 0/2] gitdm: Add gitdm configuration
by Andrea Bolognani
See the commit message for patch 2/2 for more information; patch
1/2 merely addresses some minor issues in .mailmap that I spotted
while working on the gitdm configuration.
Andrea Bolognani (2):
mailmap: Remove some duplicates
gitdm: Add gitdm configuration
.mailmap | 4 ++
docs/gitdm/aliases | 25 +++++++++
docs/gitdm/companies/canonical | 11 ++++
docs/gitdm/companies/datto | 2 +
docs/gitdm/companies/dreamhost | 4 ++
docs/gitdm/companies/nec | 2 +
docs/gitdm/companies/others | 98 ++++++++++++++++++++++++++++++++++
docs/gitdm/companies/redhat | 6 +++
docs/gitdm/companies/suse | 7 +++
docs/gitdm/companies/virtuozzo | 2 +
docs/gitdm/groups/education | 17 ++++++
docs/gitdm/groups/opensource | 12 +++++
docs/gitdm/groups/unaffiliated | 83 ++++++++++++++++++++++++++++
gitdm.config | 37 +++++++++++++
14 files changed, 310 insertions(+)
create mode 100644 docs/gitdm/aliases
create mode 100644 docs/gitdm/companies/canonical
create mode 100644 docs/gitdm/companies/datto
create mode 100644 docs/gitdm/companies/dreamhost
create mode 100644 docs/gitdm/companies/nec
create mode 100644 docs/gitdm/companies/others
create mode 100644 docs/gitdm/companies/redhat
create mode 100644 docs/gitdm/companies/suse
create mode 100644 docs/gitdm/companies/virtuozzo
create mode 100644 docs/gitdm/groups/education
create mode 100644 docs/gitdm/groups/opensource
create mode 100644 docs/gitdm/groups/unaffiliated
create mode 100644 gitdm.config
--
2.21.0
5 years, 10 months