mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00: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,
|
||||
bool standalone,
|
||||
size_t *nnicindexes,
|
||||
int **nicindexes)
|
||||
int **nicindexes,
|
||||
unsigned int flags)
|
||||
{
|
||||
virDomainDefPtr def = vm->def;
|
||||
int ret = -1;
|
||||
@ -7930,7 +7931,8 @@ qemuBuildInterfaceCommandLine(virQEMUDriverPtr driver,
|
||||
slirpfdName)))
|
||||
goto cleanup;
|
||||
|
||||
if (!(host = virQEMUBuildNetdevCommandlineFromJSON(hostnetprops)))
|
||||
if (!(host = virQEMUBuildNetdevCommandlineFromJSON(hostnetprops,
|
||||
(flags & QEMU_BUILD_COMMANDLINE_VALIDATE_KEEP_JSON))))
|
||||
goto cleanup;
|
||||
|
||||
virCommandAddArgList(cmd, "-netdev", host, NULL);
|
||||
@ -8006,7 +8008,8 @@ qemuBuildNetCommandLine(virQEMUDriverPtr driver,
|
||||
bool standalone,
|
||||
size_t *nnicindexes,
|
||||
int **nicindexes,
|
||||
unsigned int *bootHostdevNet)
|
||||
unsigned int *bootHostdevNet,
|
||||
unsigned int flags)
|
||||
{
|
||||
size_t i;
|
||||
int last_good_net = -1;
|
||||
@ -8030,7 +8033,7 @@ qemuBuildNetCommandLine(virQEMUDriverPtr driver,
|
||||
if (qemuBuildInterfaceCommandLine(driver, vm, logManager, secManager, cmd, net,
|
||||
qemuCaps, bootNet, vmop,
|
||||
standalone, nnicindexes,
|
||||
nicindexes) < 0)
|
||||
nicindexes, flags) < 0)
|
||||
goto error;
|
||||
|
||||
last_good_net = i;
|
||||
@ -8566,7 +8569,8 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager,
|
||||
virQEMUDriverConfigPtr cfg,
|
||||
const virDomainDef *def,
|
||||
virQEMUCapsPtr qemuCaps,
|
||||
bool chardevStdioLogd)
|
||||
bool chardevStdioLogd,
|
||||
unsigned int flags)
|
||||
{
|
||||
size_t i;
|
||||
unsigned int cdevflags = QEMU_BUILD_CHARDEV_TCP_NOWAIT |
|
||||
@ -8595,7 +8599,8 @@ qemuBuildChannelsCommandLine(virLogManagerPtr logManager,
|
||||
if (!(netdevprops = qemuBuildChannelGuestfwdNetdevProps(channel)))
|
||||
return -1;
|
||||
|
||||
if (!(netdevstr = virQEMUBuildNetdevCommandlineFromJSON(netdevprops)))
|
||||
if (!(netdevstr = virQEMUBuildNetdevCommandlineFromJSON(netdevprops,
|
||||
(flags & QEMU_BUILD_COMMANDLINE_VALIDATE_KEEP_JSON))))
|
||||
return -1;
|
||||
|
||||
virCommandAddArgList(cmd, "-netdev", netdevstr, NULL);
|
||||
@ -9531,7 +9536,8 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
|
||||
bool standalone,
|
||||
bool enableFips,
|
||||
size_t *nnicindexes,
|
||||
int **nicindexes)
|
||||
int **nicindexes,
|
||||
unsigned int flags)
|
||||
{
|
||||
size_t i;
|
||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||
@ -9544,9 +9550,9 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
|
||||
bool chardevStdioLogd = priv->chardevStdioLogd;
|
||||
|
||||
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,
|
||||
qemuCaps, migrateURI, snapshot, vmop);
|
||||
qemuCaps, migrateURI, snapshot, vmop, flags);
|
||||
|
||||
if (qemuBuildCommandLineValidate(driver, def) < 0)
|
||||
return NULL;
|
||||
@ -9691,7 +9697,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
|
||||
|
||||
if (qemuBuildNetCommandLine(driver, vm, logManager, secManager, cmd,
|
||||
qemuCaps, vmop, standalone,
|
||||
nnicindexes, nicindexes, &bootHostdevNet) < 0)
|
||||
nnicindexes, nicindexes, &bootHostdevNet, flags) < 0)
|
||||
return NULL;
|
||||
|
||||
if (qemuBuildSmartcardCommandLine(logManager, secManager, cmd, cfg, def, qemuCaps,
|
||||
@ -9707,7 +9713,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
|
||||
return NULL;
|
||||
|
||||
if (qemuBuildChannelsCommandLine(logManager, secManager, cmd, cfg, def, qemuCaps,
|
||||
chardevStdioLogd) < 0)
|
||||
chardevStdioLogd, flags) < 0)
|
||||
return NULL;
|
||||
|
||||
if (qemuBuildConsoleCommandLine(logManager, secManager, cmd, cfg, def, qemuCaps,
|
||||
|
@ -43,6 +43,10 @@
|
||||
VIR_ENUM_DECL(qemuVideo);
|
||||
VIR_ENUM_DECL(qemuSoundCodec);
|
||||
|
||||
typedef enum {
|
||||
QEMU_BUILD_COMMANDLINE_VALIDATE_KEEP_JSON = 1 << 0,
|
||||
} qemuBuildCommandLineFlags;
|
||||
|
||||
virCommandPtr qemuBuildCommandLine(virQEMUDriverPtr driver,
|
||||
virLogManagerPtr logManager,
|
||||
virSecurityManagerPtr secManager,
|
||||
@ -53,7 +57,8 @@ virCommandPtr qemuBuildCommandLine(virQEMUDriverPtr driver,
|
||||
bool standalone,
|
||||
bool enableFips,
|
||||
size_t *nnicindexes,
|
||||
int **nicindexes);
|
||||
int **nicindexes,
|
||||
unsigned int flags);
|
||||
|
||||
/* Generate the object properties for pr-manager */
|
||||
virJSONValuePtr qemuBuildPRManagerInfoProps(virStorageSourcePtr src);
|
||||
|
@ -7423,7 +7423,7 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn,
|
||||
}
|
||||
|
||||
if (!(cmd = qemuProcessCreatePretendCmd(driver, vm, NULL,
|
||||
qemuCheckFips(), true,
|
||||
qemuCheckFips(), true, false,
|
||||
VIR_QEMU_PROCESS_START_COLD)))
|
||||
goto cleanup;
|
||||
|
||||
|
@ -6746,7 +6746,7 @@ qemuProcessLaunch(virConnectPtr conn,
|
||||
snapshot, vmop,
|
||||
false,
|
||||
qemuCheckFips(),
|
||||
&nnicindexes, &nicindexes)))
|
||||
&nnicindexes, &nicindexes, 0)))
|
||||
goto cleanup;
|
||||
|
||||
if (incoming && incoming->fd != -1)
|
||||
@ -7189,8 +7189,11 @@ qemuProcessCreatePretendCmd(virQEMUDriverPtr driver,
|
||||
const char *migrateURI,
|
||||
bool enableFips,
|
||||
bool standalone,
|
||||
bool jsonPropsValidation,
|
||||
unsigned int flags)
|
||||
{
|
||||
unsigned int buildflags = 0;
|
||||
|
||||
virCheckFlags(VIR_QEMU_PROCESS_START_COLD |
|
||||
VIR_QEMU_PROCESS_START_PAUSED |
|
||||
VIR_QEMU_PROCESS_START_AUTODESTROY, NULL);
|
||||
@ -7200,6 +7203,9 @@ qemuProcessCreatePretendCmd(virQEMUDriverPtr driver,
|
||||
if (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,
|
||||
!!migrateURI, flags) < 0)
|
||||
return NULL;
|
||||
@ -7218,7 +7224,8 @@ qemuProcessCreatePretendCmd(virQEMUDriverPtr driver,
|
||||
standalone,
|
||||
enableFips,
|
||||
NULL,
|
||||
NULL);
|
||||
NULL,
|
||||
buildflags);
|
||||
}
|
||||
|
||||
|
||||
|
@ -101,6 +101,7 @@ virCommandPtr qemuProcessCreatePretendCmd(virQEMUDriverPtr driver,
|
||||
const char *migrateURI,
|
||||
bool enableFips,
|
||||
bool standalone,
|
||||
bool jsonPropsValidation,
|
||||
unsigned int flags);
|
||||
|
||||
int qemuProcessInit(virQEMUDriverPtr driver,
|
||||
|
@ -292,16 +292,23 @@ virQEMUBuildCommandLineJSON(virJSONValuePtr value,
|
||||
/**
|
||||
* virQEMUBuildNetdevCommandlineFromJSON:
|
||||
* @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
|
||||
* differences between the monitor and command line syntax.
|
||||
*
|
||||
* @rawjson is meant for testing of the schema in the xml2argvtest
|
||||
*/
|
||||
char *
|
||||
virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props)
|
||||
virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props,
|
||||
bool rawjson)
|
||||
{
|
||||
const char *type = virJSONValueObjectGetString(props, "type");
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
|
||||
if (rawjson)
|
||||
return virJSONValueToString(props, false);
|
||||
|
||||
virBufferAsprintf(&buf, "%s,", type);
|
||||
|
||||
if (virQEMUBuildCommandLineJSON(props, &buf, "type", true,
|
||||
|
@ -50,7 +50,8 @@ int virQEMUBuildCommandLineJSON(virJSONValuePtr value,
|
||||
virQEMUBuildCommandLineJSONArrayFormatFunc array);
|
||||
|
||||
char *
|
||||
virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props);
|
||||
virQEMUBuildNetdevCommandlineFromJSON(virJSONValuePtr props,
|
||||
bool rawjson);
|
||||
|
||||
int virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf,
|
||||
virJSONValuePtr objprops);
|
||||
|
@ -396,7 +396,8 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv,
|
||||
virDomainObjPtr vm,
|
||||
const char *migrateURI,
|
||||
struct testQemuInfo *info,
|
||||
unsigned int flags)
|
||||
unsigned int flags,
|
||||
bool jsonPropsValidation)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@ -471,6 +472,7 @@ testCompareXMLToArgvCreateArgs(virQEMUDriverPtr drv,
|
||||
|
||||
return qemuProcessCreatePretendCmd(drv, vm, migrateURI,
|
||||
(flags & FLAG_FIPS), false,
|
||||
jsonPropsValidation,
|
||||
VIR_QEMU_PROCESS_START_COLD);
|
||||
}
|
||||
|
||||
@ -566,7 +568,7 @@ testCompareXMLToArgv(const void *data)
|
||||
virResetLastError();
|
||||
|
||||
if (!(cmd = testCompareXMLToArgvCreateArgs(&driver, vm, migrateURI, info,
|
||||
flags))) {
|
||||
flags, false))) {
|
||||
if (flags & FLAG_EXPECT_FAILURE)
|
||||
goto ok;
|
||||
goto cleanup;
|
||||
|
Loading…
Reference in New Issue
Block a user