[PATCH 20/21] testutilsqemuschema: Allow loading non-latest schema

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

 



Add testQEMUSchemaLoad and refactor internals so that we can load the
QMP schema from an arbitrary caps replies file.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tests/testutilsqemuschema.c | 64 ++++++++++++++++++++++++-------------
 tests/testutilsqemuschema.h |  3 ++
 2 files changed, 45 insertions(+), 22 deletions(-)

diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c
index 060a5d7054..d9b55fd787 100644
--- a/tests/testutilsqemuschema.c
+++ b/tests/testutilsqemuschema.c
@@ -607,37 +607,23 @@ testQEMUSchemaValidateCommand(const char *command,
 }


-/**
- * testQEMUSchemaGetLatest:
- *
- * Returns the schema data as the qemu monitor would reply from the latest
- * replies file used for qemucapabilitiestest for the x86_64 architecture.
- */
-virJSONValuePtr
-testQEMUSchemaGetLatest(const char* arch)
+static virJSONValuePtr
+testQEMUSchemaLoadReplies(const char *filename)
 {
-    g_autofree char *capsLatestFile = NULL;
-    g_autofree char *capsLatest = NULL;
+    g_autofree char *caps = NULL;
     char *schemaReply;
     char *end;
     g_autoptr(virJSONValue) reply = NULL;
     virJSONValuePtr schema = NULL;

-    if (!(capsLatestFile = testQemuGetLatestCapsForArch(arch, "replies"))) {
-        VIR_TEST_VERBOSE("failed to find latest caps replies");
+    if (virTestLoadFile(filename, &caps) < 0)
         return NULL;
-    }

-    VIR_TEST_DEBUG("replies file: '%s'", capsLatestFile);
-
-    if (virTestLoadFile(capsLatestFile, &capsLatest) < 0)
-        return NULL;
-
-    if (!(schemaReply = strstr(capsLatest, "\"execute\": \"query-qmp-schema\"")) ||
+    if (!(schemaReply = strstr(caps, "\"execute\": \"query-qmp-schema\"")) ||
         !(schemaReply = strstr(schemaReply, "\n\n")) ||
         !(end = strstr(schemaReply + 2, "\n\n"))) {
         VIR_TEST_VERBOSE("failed to find reply to 'query-qmp-schema' in '%s'",
-                         capsLatestFile);
+                         filename);
         return NULL;
     }

@@ -646,13 +632,13 @@ testQEMUSchemaGetLatest(const char* arch)

     if (!(reply = virJSONValueFromString(schemaReply))) {
         VIR_TEST_VERBOSE("failed to parse 'query-qmp-schema' reply from '%s'",
-                         capsLatestFile);
+                         filename);
         return NULL;
     }

     if (!(schema = virJSONValueObjectStealArray(reply, "return"))) {
         VIR_TEST_VERBOSE("missing qapi schema data in reply in '%s'",
-                         capsLatestFile);
+                         filename);
         return NULL;
     }

@@ -660,6 +646,28 @@ testQEMUSchemaGetLatest(const char* arch)
 }


+/**
+ * testQEMUSchemaGetLatest:
+ *
+ * Returns the schema data as the qemu monitor would reply from the latest
+ * replies file used for qemucapabilitiestest for the x86_64 architecture.
+ */
+virJSONValuePtr
+testQEMUSchemaGetLatest(const char *arch)
+{
+    g_autofree char *capsLatestFile = NULL;
+
+    if (!(capsLatestFile = testQemuGetLatestCapsForArch(arch, "replies"))) {
+        VIR_TEST_VERBOSE("failed to find latest caps replies");
+        return NULL;
+    }
+
+    VIR_TEST_DEBUG("replies file: '%s'", capsLatestFile);
+
+    return testQEMUSchemaLoadReplies(capsLatestFile);
+}
+
+
 virHashTablePtr
 testQEMUSchemaLoadLatest(const char *arch)
 {
@@ -670,3 +678,15 @@ testQEMUSchemaLoadLatest(const char *arch)

     return virQEMUQAPISchemaConvert(schema);
 }
+
+
+virHashTablePtr
+testQEMUSchemaLoad(const char *filename)
+{
+    virJSONValuePtr schema;
+
+    if (!(schema = testQEMUSchemaLoadReplies(filename)))
+        return NULL;
+
+    return virQEMUQAPISchemaConvert(schema);
+}
diff --git a/tests/testutilsqemuschema.h b/tests/testutilsqemuschema.h
index acedb77677..c90a6b626d 100644
--- a/tests/testutilsqemuschema.h
+++ b/tests/testutilsqemuschema.h
@@ -42,3 +42,6 @@ testQEMUSchemaGetLatest(const char* arch);

 virHashTablePtr
 testQEMUSchemaLoadLatest(const char *arch);
+
+virHashTablePtr
+testQEMUSchemaLoad(const char *filename);
-- 
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