[libvirt] [PATCH 07/10] tests: qemucapsprobemock: Prepare 'qemucapsprobe' for the new format

Peter Krempa posted 10 patches 6 years, 11 months ago
[libvirt] [PATCH 07/10] tests: qemucapsprobemock: Prepare 'qemucapsprobe' for the new format
Posted by Peter Krempa 6 years, 11 months ago
Change the output of qemucapsprobe to record the commands used for
querying. This allows to easily identify which reply belongs to which
command and also will allow to test whether we use stable queries.

This change includes changing dropping of the QMP greeting from the file
and reformatting of the query and output to stdout.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 tests/qemucapsprobemock.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/tests/qemucapsprobemock.c b/tests/qemucapsprobemock.c
index a0d2acb69a..5936975505 100644
--- a/tests/qemucapsprobemock.c
+++ b/tests/qemucapsprobemock.c
@@ -37,6 +37,7 @@
         } \
     } while (0)

+static bool first = true;

 static void
 printLineSkipEmpty(const char *line,
@@ -60,9 +61,22 @@ int
 qemuMonitorSend(qemuMonitorPtr mon,
                 qemuMonitorMessagePtr msg)
 {
+    char *reformatted;
+
     REAL_SYM(realQemuMonitorSend);

-    fprintf(stderr, "%s", msg->txBuffer);
+    if (!(reformatted = virJSONStringReformat(msg->txBuffer, true))) {
+        fprintf(stderr, "Failed to reformat command string '%s'\n", msg->txBuffer);
+        abort();
+    }
+
+    if (first)
+        first = false;
+    else
+        printLineSkipEmpty("\n", stdout);
+
+    printLineSkipEmpty(reformatted, stdout);
+    VIR_FREE(reformatted);

     return realQemuMonitorSend(mon, msg);
 }
@@ -77,7 +91,6 @@ qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon,
                              const char *line,
                              qemuMonitorMessagePtr msg)
 {
-    static bool first = true;
     virJSONValuePtr value = NULL;
     char *json = NULL;
     int ret;
@@ -93,14 +106,14 @@ qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon,
             abort();
         }

-        if (first) {
+        /* Ignore QMP greeting */
+        if (virJSONValueObjectHasKey(value, "QMP"))
+            goto cleanup;
+
+        if (first)
             first = false;
-        } else {
-            /* Ignore QMP greeting if it's not the first one */
-            if (virJSONValueObjectHasKey(value, "QMP"))
-                goto cleanup;
-            putchar('\n');
-        }
+        else
+            printLineSkipEmpty("\n", stdout);

         printLineSkipEmpty(json, stdout);
     }
-- 
2.16.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 07/10] tests: qemucapsprobemock: Prepare 'qemucapsprobe' for the new format
Posted by John Ferlan 6 years, 11 months ago

On 06/04/2018 09:58 AM, Peter Krempa wrote:
> Change the output of qemucapsprobe to record the commands used for
> querying. This allows to easily identify which reply belongs to which
> command and also will allow to test whether we use stable queries.

Yay!  So painful to try and matching things up.

> 
> This change includes changing dropping of the QMP greeting from the file
> and reformatting of the query and output to stdout.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  tests/qemucapsprobemock.c | 31 ++++++++++++++++++++++---------
>  1 file changed, 22 insertions(+), 9 deletions(-)
> 

Looks like there's two different things in this patch, but maybe I'm
wrong too.

The qemuMonitorJSONIOProcessLine changes seem to be separable, true?
Although the bool first move out has me slightly doubting...

Then the qemuMonitorSend does what the first commit paragraph states, right?

Doesn't the greeting get dropped in the old code too or am I missing
something subtle this late at night?

The code is fine - your call on the separation.

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list