[PATCH 09/10] network: implement virNetworkUpdate for test_driver

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

 



The test driver does nothing outside of keeping track of each
network's config/state in the in-memory database maintained by
network_conf functions, so all we have to do is call the function that
updates the network's entry in the in-memory database.
---
 src/test/test_driver.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index d635f3d..017708b 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3123,7 +3123,9 @@ cleanup:
     return ret;
 }
 
-static virNetworkPtr testNetworkDefine(virConnectPtr conn, const char *xml) {
+static
+virNetworkPtr testNetworkDefine(virConnectPtr conn, const char *xml)
+{
     testConnPtr privconn = conn->privateData;
     virNetworkDefPtr def;
     virNetworkObjPtr net = NULL;
@@ -3180,6 +3182,57 @@ cleanup:
     return ret;
 }
 
+static int
+testNetworkUpdate(virNetworkPtr net,
+                  unsigned int section,
+                  int parentIndex ATTRIBUTE_UNUSED,
+                  const char *xml ATTRIBUTE_UNUSED,
+                  unsigned int flags)
+{
+    testConnPtr privconn = net->conn->privateData;
+    virNetworkObjPtr network = NULL;
+    int isActive, ret = -1;
+
+    virCheckFlags(VIR_NETWORK_UPDATE_AFFECT_LIVE |
+                  VIR_NETWORK_UPDATE_AFFECT_CONFIG |
+                  VIR_NETWORK_UPDATE_EXISTING |
+                  VIR_NETWORK_UPDATE_DELETE |
+                  VIR_NETWORK_UPDATE_ADD_LAST |
+                  VIR_NETWORK_UPDATE_ADD_FIRST,
+                  -1);
+
+    testDriverLock(privconn);
+
+    network = virNetworkFindByUUID(&privconn->networks, net->uuid);
+    if (!network) {
+        virReportError(VIR_ERR_NO_NETWORK,
+                       "%s", _("no network with matching uuid"));
+        goto cleanup;
+    }
+
+    /* VIR_NETWORK_UPDATE_AFFECT_CURRENT means "change LIVE if network
+     * is active, else change CONFIG
+    */
+    isActive = virNetworkObjIsActive(network);
+    if ((flags & (VIR_NETWORK_UPDATE_AFFECT_LIVE
+                   | VIR_NETWORK_UPDATE_AFFECT_CONFIG)) ==
+        VIR_NETWORK_UPDATE_AFFECT_CURRENT) {
+        if (isActive)
+            flags |= VIR_NETWORK_UPDATE_AFFECT_LIVE;
+        else
+            flags |= VIR_NETWORK_UPDATE_AFFECT_CONFIG;
+    }
+
+    /* update the network config in memory/on disk */
+    if (virNetworkObjUpdate(network, section, parentIndex, xml, flags) < 0)
+       goto cleanup;
+
+    ret = 0;
+cleanup:
+    testDriverUnlock(privconn);
+    return ret;
+}
+
 static int testNetworkStart(virNetworkPtr network) {
     testConnPtr privconn = network->conn->privateData;
     virNetworkObjPtr privnet;
@@ -5719,6 +5772,7 @@ static virNetworkDriver testNetworkDriver = {
     .networkCreateXML = testNetworkCreate, /* 0.3.2 */
     .networkDefineXML = testNetworkDefine, /* 0.3.2 */
     .networkUndefine = testNetworkUndefine, /* 0.3.2 */
+    .networkUpdate = testNetworkUpdate, /* 0.10.2 */
     .networkCreate = testNetworkStart, /* 0.3.2 */
     .networkDestroy = testNetworkDestroy, /* 0.3.2 */
     .networkGetXMLDesc = testNetworkGetXMLDesc, /* 0.3.2 */
-- 
1.7.11.4

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