[PATCH 05/10] test: Allow specifying object transient state in driver XML

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

 



Similar to the runstate commit, allow a block like:

  <testdriver>
    <transient/>
  </testdriver>

Wire it up for domains and networks. Generalize the boolean lookup
pattern since we are going to use it for other bits as well.
---
 src/test/test_driver.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 4be20b1..3775906 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -860,6 +860,41 @@ error:
 }
 
 /*
+ * Parse object bool value from passed in XML, transient example:
+ * <domain>
+ *   ...
+ *   <testdriver>
+ *     <transient/>
+ *   </testdriver>
+ * </domain>
+ */
+static int
+testParseXMLObjectBool(xmlXPathContextPtr ctxt,
+                       xmlNodePtr node,
+                       const char *name,
+                       bool *val)
+{
+    int ret = -1;
+    char *xpath = NULL;
+
+    if (virAsprintf(&xpath, "boolean(%s/testdriver/%s)",
+                    xmlGetNodePath(node), name) < 0)
+        goto error;
+
+    ret = virXPathBoolean(xpath, ctxt);
+    if (ret == -1) {
+        virReportError(VIR_ERR_XML_ERROR, _("invalid %s"), name);
+        goto error;
+    }
+    *val = ret;
+
+    ret = 0;
+error:
+    VIR_FREE(xpath);
+    return ret;
+}
+
+/*
  * Unlink custom <testdriver> XML before handing the node off
  * to the object parsing handler, since it may complain about unrecognized
  * elements (if not now, then in the future)
@@ -904,6 +939,7 @@ testParseDomains(testConnPtr privconn,
 
     for (i = 0; i < num; i++) {
         unsigned int runstate;
+        bool transient;
         virDomainDefPtr def;
         xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file, "domain");
         if (!node)
@@ -913,6 +949,8 @@ testParseDomains(testConnPtr privconn,
                                        VIR_DOMAIN_LAST, VIR_DOMAIN_RUNNING,
                                        &runstate) < 0)
             goto error;
+        if (testParseXMLObjectBool(ctxt, node, "transient", &transient) < 0)
+            goto error;
 
         if (testNodeUnlinkCustomXML(ctxt, node) < 0)
             goto error;
@@ -933,7 +971,7 @@ testParseDomains(testConnPtr privconn,
             goto error;
         }
 
-        obj->persistent = 1;
+        obj->persistent = !transient;
         if (runstate != VIR_DOMAIN_SHUTOFF) {
             if (testDomainStartState(privconn, obj,
                                      VIR_DOMAIN_RUNNING_BOOTED) < 0) {
@@ -970,6 +1008,7 @@ testParseNetworks(testConnPtr privconn,
     }
 
     for (i = 0; i < num; i++) {
+        bool transient;
         unsigned int runstate;
         virNetworkDefPtr def;
         xmlNodePtr node = testParseXMLDocFromFile(nodes[i], file, "network");
@@ -978,6 +1017,8 @@ testParseNetworks(testConnPtr privconn,
 
         if (testParseXMLObjectRunstate(ctxt, node, 1, 1, &runstate) < 0)
             goto error;
+        if (testParseXMLObjectBool(ctxt, node, "transient", &transient) < 0)
+            goto error;
 
         if (testNodeUnlinkCustomXML(ctxt, node) < 0)
             goto error;
@@ -991,7 +1032,7 @@ testParseNetworks(testConnPtr privconn,
             goto error;
         }
 
-        obj->persistent = 1;
+        obj->persistent = !transient;
         obj->active = runstate;
         virNetworkObjUnlock(obj);
     }
-- 
1.8.3.1

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




[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]