mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
qemu: Prepare for testing of 'netdev_add' props via qemuxml2argvtest
qemuxml2argv test suite is way more comprehensive than the hotplug suite. Since we share the code paths for monitor and command line hotplug we can easily test the properties of devices against the QAPI schema. To achieve this we'll need to skip the JSON->commandline conversion for the test run so that we can analyze the pure properties. This patch adds flags for the comand line generator and hook them into the JSON->commandline convertor for -netdev. An upcoming patch will make use of this new infrastructure. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
529ad62c0d
commit
78d30aa0bf
@ -7701,7 +7701,8 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
|
|||||||
virNetDevVPortProfileOp vmop,
|
virNetDevVPortProfileOp vmop,
|
||||||
bool standalone,
|
bool standalone,
|
||||||
size_t *nnicindexes,
|
size_t *nnicindexes,
|
||||||
int **nicindexes)
|
int **nicindexes,
|
||||||
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virDomainDefPtr def = vm->def;
|
virDomainDefPtr def = vm->def;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -7930,7 +7931,8 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
|
|||||||
slirpfdName)))
|
slirpfdName)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(host = virQEMUBuildNetdevCommandlineFromJSON(hostnetprops)))
|
if (!(host = virQEMUBuildNetdevCommandlineFromJSON(hostnetprops,
|
||||||
|
(flags & QEMU_BUILD_COMMANDLINE_VALIDATE_KEEP_JSON))))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
virCommandAddArgList(cmd, "-netdev", host, NULL);
|
virCommandAddArgList(cmd, "-netdev", host, NULL);
|
||||||
@ -8006,7 +8008,8 @@ qemuBuildNetCommandLine(virQEMUDriverPtr driver,
|
|||||||
bool standalone,
|
bool standalone,
|
||||||
size_t *nnicindexes,
|
size_t *nnicindexes,
|
||||||
int **nicindexes,
|
int **nicindexes,
|
||||||
unsigned int *bootHostdevNet)
|
unsigned int *bootHostdevNet,
|
||||||
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
int last_good_net = -1;
|
int last_good_net = -1;
|
||||||
@ -8030,7 +8033,7 @@ qemuBuildNetCommandLine(virQEMUDriverPtr driver,
|
|||||||
if (qemuBuildInterfaceCommandLine(driver, vm, logManager, secManager, cmd, net,
|
if (qemuBuildInterfaceCommandLine(driver, vm, logManager, secManager, cmd, net,
|
||||||
qemuCaps, bootNet, vmop,
|
qemuCaps, bootNet, vmop,
|
||||||
standalone, nnicindexes,
|
standalone, nnicindexes,
|
||||||
nicindexes) < 0)
|
nicindexes, flags) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
last_good_net = i;
|
last_good_net = i;
|
||||||
@ -8566,7 +8569,8 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager,
|
|||||||
virQEMUDriverConfigPtr cfg,
|
virQEMUDriverConfigPtr cfg,
|
||||||
const virDomainDef *def,
|
const virDomainDef *def,
|
||||||
virQEMUCapsPtr qemuCaps,
|
virQEMUCapsPtr qemuCaps,
|
||||||
bool chardevStdioLogd)
|
bool chardevStdioLogd,
|
||||||
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT |
|
unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT |
|
||||||
@ -8595,7 +8599,8 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager,
|
|||||||
if (!(netdevprops = qemuBuildChannelGuestfwdNetdevProps(channel)))
|
if (!(netdevprops = qemuBuildChannelGuestfwdNetdevProps(channel)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!(netdevstr = virQEMUBuildNetdevCommandlineFromJSON(netdevprops)))
|
if (!(netdevstr = virQEMUBuildNetdevCommandlineFromJSON(netdevprops,
|
||||||
|
(flags & QEMU_BUILD_COMMANDLINE_VALIDATE_KEEP_JSON))))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
virCommandAddArgList(cmd, "-netdev", netdevstr, NULL);
|
virCommandAddArgList(cmd, "-netdev", netdevstr, NULL);
|
||||||
@ -9531,7 +9536,8 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
|
|||||||
bool standalone,
|
bool standalone,
|
||||||
bool enableFips,
|
bool enableFips,
|
||||||
size_t *nnicindexes,
|
size_t *nnicindexes,
|
||||||
int **nicindexes)
|
int **nicindexes,
|
||||||
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||||
@ -9544,9 +9550,9 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
|
|||||||
bool chardevStdioLogd = priv->chardevStdioLogd;
|
bool chardevStdioLogd = priv->chardevStdioLogd;
|
||||||
|
|
||||||
VIR_DEBUG("driver=%p def=%p mon=%p "
|
VIR_DEBUG("driver=%p def=%p mon=%p "
|
||||||
"qemuCaps=%p migrateURI=%s snapshot=%p vmop=%d",
|
"qemuCaps=%p migrateURI=%s snapshot=%p vmop=%d flags=0x%x",
|
||||||
driver, def, priv->monConfig,
|
driver, def, priv->monConfig,
|
||||||
qemuCaps, migrateURI, snapshot, vmop);
|
qemuCaps, migrateURI, snapshot, vmop, flags);
|
||||||
|
|
||||||
if (qemuBuildCommandLineValidate(driver, def) < 0)
|
if (qemuBuildCommandLineValidate(driver, def) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -9691,7 +9697,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
if (qemuBuildNetCommandLine(driver, vm, logManager, secManager, cmd,
|
if (qemuBuildNetCommandLine(driver, vm, logManager, secManager, cmd,
|
||||||
qemuCaps, vmop, standalone,
|
qemuCaps, vmop, standalone,
|
||||||
nnicindexes, nicindexes, &bootHostdevNet) < 0)
|
nnicindexes, nicindexes, &bootHostdevNet, flags) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (qemuBuildSmartcardCommandLine(logManager, secManager, cmd, cfg, def, qemuCaps,
|
if (qemuBuildSmartcardCommandLine(logManager, secManager, cmd, cfg, def, qemuCaps,
|
||||||
@ -9707,7 +9713,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (qemuBuildChannelsCommandLine(logManager, secManager, cmd, cfg, def, qemuCaps,
|
if (qemuBuildChannelsCommandLine(logManager, secManager, cmd, cfg, def, qemuCaps,
|
||||||
chardevStdioLogd) < 0)
|
chardevStdioLogd, flags) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (qemuBuildConsoleCommandLine(logManager, secManager, cmd, cfg, def, qemuCaps,
|
if (qemuBuildConsoleCommandLine(logManager, secManager, cmd, cfg, def, qemuCaps,
|
||||||
|
@ -43,6 +43,10 @@
|
|||||||
VIR_ENUM_DECL(qemuVideo);
|
VIR_ENUM_DECL(qemuVideo);
|
||||||
VIR_ENUM_DECL(qemuSoundCodec);
|
VIR_ENUM_DECL(qemuSoundCodec);
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
QEMU_BUILD_COMMANDLINE_VALIDATE_KEEP_JSON = 1 << 0,
|
||||||
|
} qemuBuildCommandLineFlags;
|
||||||
|
|
||||||
virCommandPtr qemuBuildCommandLine(virQEMUDriverPtr driver,
|
virCommandPtr qemuBuildCommandLine(virQEMUDriverPtr driver,
|
||||||
virLogManagerPtr logManager,
|
virLogManagerPtr logManager,
|
||||||
virSecurityManagerPtr secManager,
|
virSecurityManagerPtr secManager,
|
||||||
@ -53,7 +57,8 @@ virCommandPtr qemuBuildCommandLine(virQEMUDriverPtr driver,
|
|||||||
bool standalone,
|
bool standalone,
|
||||||
bool enableFips,
|
bool enableFips,
|
||||||
size_t *nnicindexes,
|
size_t *nnicindexes,
|
||||||
int **nicindexes);
|
int **nicindexes,
|
||||||
|
unsigned int flags);
|
||||||
|
|
||||||
/* Generate the object properties for pr-manager */
|
/* Generate the object properties for pr-manager */
|
||||||
virJSONValuePtr qemuBuildPRManagerInfoProps(virStorageSourcePtr src);
|
virJSONValuePtr qemuBuildPRManagerInfoProps(virStorageSourcePtr src);
|
||||||
|
@ -7423,7 +7423,7 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(cmd = qemuProcessCreatePretendCmd(driver, vm, NULL,
|
if (!(cmd = qemuProcessCreatePretendCmd(driver, vm, NULL,
|
||||||
qemuCheckFips(), true,
|
qemuCheckFips(), true, false,
|
||||||
VIR_QEMU_PROCESS_START_COLD)))
|
VIR_QEMU_PROCESS_START_COLD)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
@ -6746,7 +6746,7 @@ qemuProcessLaunch(virConnectPtr conn,
|
|||||||
snapshot, vmop,
|
snapshot, vmop,
|
||||||
false,
|
false,
|
||||||
qemuCheckFips(),
|
qemuCheckFips(),
|
||||||
&nnicindexes, &nicindexes)))
|
&nnicindexes, &nicindexes, 0)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (incoming && incoming->fd != -1)
|
if (incoming && incoming->fd != -1)
|
||||||
@ -7189,8 +7189,11 @@ qemuProcessCreatePretendCmd(virQEMUDriverPtr driver,
|
|||||||
const char *migrateURI,
|
const char *migrateURI,
|
||||||
bool enableFips,
|
bool enableFips,
|
||||||
bool standalone,
|
bool standalone,
|
||||||
|
bool jsonPropsValidation,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
|
unsigned int buildflags = 0;
|
||||||
|
|
||||||
virCheckFlags(VIR_QEMU_PROCESS_START_COLD |
|
virCheckFlags(VIR_QEMU_PROCESS_START_COLD |
|
||||||
VIR_QEMU_PROCESS_START_PAUSED |
|
VIR_QEMU_PROCESS_START_PAUSED |
|
||||||
VIR_QEMU_PROCESS_START_AUTODESTROY, NULL);
|
VIR_QEMU_PROCESS_START_AUTODESTROY, NULL);
|
||||||
@ -7200,6 +7203,9 @@ qemuProcessCreatePretendCmd(virQEMUDriverPtr driver,
|
|||||||
if (standalone)
|
if (standalone)
|
||||||
flags |= VIR_QEMU_PROCESS_START_STANDALONE;
|
flags |= VIR_QEMU_PROCESS_START_STANDALONE;
|
||||||
|
|
||||||
|
if (jsonPropsValidation)
|
||||||
|
buildflags = QEMU_BUILD_COMMANDLINE_VALIDATE_KEEP_JSON;
|
||||||
|
|
||||||
if (qemuProcessInit(driver, vm, NULL, QEMU_ASYNC_JOB_NONE,
|
if (qemuProcessInit(driver, vm, NULL, QEMU_ASYNC_JOB_NONE,
|
||||||
!!migrateURI, flags) < 0)
|
!!migrateURI, flags) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -7218,7 +7224,8 @@ qemuProcessCreatePretendCmd(virQEMUDriverPtr driver,
|
|||||||
standalone,
|
standalone,
|
||||||
enableFips,
|
enableFips,
|
||||||
NULL,
|
NULL,
|
||||||
NULL);
|
NULL,
|
||||||
|
buildflags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -101,6 +101,7 @@ virCommandPtr qemuProcessCreatePretendCmd(virQEMUDriverPtr driver,
|
|||||||
const char *migrateURI,
|
const char *migrateURI,
|
||||||
bool enableFips,
|
bool enableFips,
|
||||||
bool standalone,
|
bool standalone,
|
||||||
|
bool jsonPropsValidation,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
|
||||||
int qemuProcessInit(virQEMUDriverPtr driver,
|
int qemuProcessInit(virQEMUDriverPtr driver,
|
||||||
|
@ -292,16 +292,23 @@ virQEMUBuildCommandLineJSON(virJSONValuePtr value,
|
|||||||
/**
|
/**
|
||||||
* virQEMUBuildNetdevCommandlineFromJSON:
|
* virQEMUBuildNetdevCommandlineFromJSON:
|
||||||
* @props: JSON properties describing a netdev
|
* @props: JSON properties describing a netdev
|
||||||
|
* @rawjson: don't transform to commandline args, but just stringify json
|
||||||
*
|
*
|
||||||
* Converts @props into arguments for -netdev including all the quirks and
|
* Converts @props into arguments for -netdev including all the quirks and
|
||||||
* differences between the monitor and command line syntax.
|
* differences between the monitor and command line syntax.
|
||||||
|
*
|
||||||
|
* @rawjson is meant for testing of the schema in the xml2argvtest
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props)
|
virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props,
|
||||||
|
bool rawjson)
|
||||||
{
|
{
|
||||||
const char *type = virJSONValueObjectGetString(props, "type");
|
const char *type = virJSONValueObjectGetString(props, "type");
|
||||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||||
|
|
||||||
|
if (rawjson)
|
||||||
|
return virJSONValueToString(props, false);
|
||||||
|
|
||||||
virBufferAsprintf(&buf, "%s,", type);
|
virBufferAsprintf(&buf, "%s,", type);
|
||||||
|
|
||||||
if (virQEMUBuildCommandLineJSON(props, &buf, "type", true,
|
if (virQEMUBuildCommandLineJSON(props, &buf, "type", true,
|
||||||
|
@ -50,7 +50,8 @@ int virQEMUBuildCommandLineJSON(virJSONValuePtr value,
|
|||||||
virQEMUBuildCommandLineJSONArrayFormatFunc array);
|
virQEMUBuildCommandLineJSONArrayFormatFunc array);
|
||||||
|
|
||||||
char *
|
char *
|
||||||
virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props);
|
virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props,
|
||||||
|
bool rawjson);
|
||||||
|
|
||||||
int virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf,
|
int virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf,
|
||||||
virJSONValuePtr objprops);
|
virJSONValuePtr objprops);
|
||||||
|
@ -396,7 +396,8 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv,
|
|||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
const char *migrateURI,
|
const char *migrateURI,
|
||||||
struct testQemuInfo *info,
|
struct testQemuInfo *info,
|
||||||
unsigned int flags)
|
unsigned int flags,
|
||||||
|
bool jsonPropsValidation)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@ -471,6 +472,7 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv,
|
|||||||
|
|
||||||
return qemuProcessCreatePretendCmd(drv, vm, migrateURI,
|
return qemuProcessCreatePretendCmd(drv, vm, migrateURI,
|
||||||
(flags & FLAG_FIPS), false,
|
(flags & FLAG_FIPS), false,
|
||||||
|
jsonPropsValidation,
|
||||||
VIR_QEMU_PROCESS_START_COLD);
|
VIR_QEMU_PROCESS_START_COLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -566,7 +568,7 @@ testCompareXMLToArgv(const void *data)
|
|||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
|
||||||
if (!(cmd = testCompareXMLToArgvCreateArgs(&driver, vm, migrateURI, info,
|
if (!(cmd = testCompareXMLToArgvCreateArgs(&driver, vm, migrateURI, info,
|
||||||
flags))) {
|
flags, false))) {
|
||||||
if (flags & FLAG_EXPECT_FAILURE)
|
if (flags & FLAG_EXPECT_FAILURE)
|
||||||
goto ok;
|
goto ok;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
Loading…
Reference in New Issue
Block a user