[PATCH 18/21] qemu: Prepare for testing of 'netdev_add' props via qemuxml2argvtest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/qemu/qemu_command.c  | 28 +++++++++++++++++-----------
 src/qemu/qemu_command.h  |  7 ++++++-
 src/qemu/qemu_driver.c   |  2 +-
 src/qemu/qemu_process.c  | 11 +++++++++--
 src/qemu/qemu_process.h  |  1 +
 src/util/virqemu.c       |  9 ++++++++-
 src/util/virqemu.h       |  3 ++-
 tests/qemuxml2argvtest.c |  6 ++++--
 8 files changed, 48 insertions(+), 19 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2ed8e66f66..f9a2732587 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7691,7 +7691,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;
@@ -7920,7 +7921,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);
@@ -7996,7 +7998,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;
@@ -8020,7 +8023,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;
@@ -8556,7 +8559,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 |
@@ -8585,7 +8589,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);
@@ -9521,7 +9526,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];
@@ -9534,9 +9540,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;
@@ -9681,7 +9687,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,
@@ -9697,7 +9703,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,
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 1daa07982c..55bc67072a 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -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);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index db65862163..dd9ae30bb5 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -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;

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index f7f6793113..ab32d49d6e 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -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);
 }


diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index 3077d3ef9e..15e67b9762 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -101,6 +101,7 @@ virCommandPtr qemuProcessCreatePretendCmd(virQEMUDriverPtr driver,
                                           const char *migrateURI,
                                           bool enableFips,
                                           bool standalone,
+                                          bool jsonPropsValidation,
                                           unsigned int flags);

 int qemuProcessInit(virQEMUDriverPtr driver,
diff --git a/src/util/virqemu.c b/src/util/virqemu.c
index f3e9966598..cf76346bfa 100644
--- a/src/util/virqemu.c
+++ b/src/util/virqemu.c
@@ -290,16 +290,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,
diff --git a/src/util/virqemu.h b/src/util/virqemu.h
index 22f47851df..b1296cb657 100644
--- a/src/util/virqemu.h
+++ b/src/util/virqemu.h
@@ -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);
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 9fa1afd9d0..5123580ee2 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -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;
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux