[RFC][PATCH 7/7] interface: implement test driver

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

 



---
 src/test/test_driver.c |  116 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 113 insertions(+), 3 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 83dcf1a..9ae6e7a 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -85,6 +85,8 @@ struct _testConn {
     virDomainObjList domains;
     virNetworkObjList networks;
     virInterfaceObjList ifaces;
+    int transaction_running:1;
+    virInterfaceObjList backupIfaces;
     virStoragePoolObjList pools;
     virNodeDeviceObjList devs;
     int numCells;
@@ -3433,6 +3435,114 @@ cleanup:
     return ret;
 }
 
+static int testInterfaceChangeStart(virConnectPtr conn,
+                                    unsigned int flags ATTRIBUTE_UNUSED)
+{
+    testConnPtr privconn = conn->privateData;
+    int ret = -1;
+    unsigned int i, cnt;
+
+    testDriverLock(privconn);
+    if (privconn->transaction_running) {
+        testError(VIR_ERR_OPERATION_INVALID, _("there is another change "
+                                               "running."));
+        goto cleanup;
+    }
+
+    privconn->transaction_running = 1;
+
+    cnt = privconn->ifaces.count;
+    for (i = 0; i < cnt; i++) {
+        virInterfaceDefPtr def = privconn->ifaces.objs[i]->def;
+        virInterfaceDefPtr backup;
+        virInterfaceObjPtr iface;
+        char *xml = virInterfaceDefFormat(def);
+
+        if (!xml) {
+            virReportOOMError();
+            goto no_memory;
+        }
+
+        if ((backup = virInterfaceDefParseString(xml)) == NULL) {
+            VIR_FREE(xml);
+            goto cleanup;
+        }
+
+        if ((iface =
+             virInterfaceAssignDef(&privconn->backupIfaces, backup)) == NULL) {
+            VIR_FREE(xml);
+            goto cleanup;
+        }
+
+        virInterfaceObjUnlock(iface);
+
+        conn->refs++;
+
+        VIR_FREE(xml);
+    }
+
+    ret = 0;
+cleanup:
+    testDriverUnlock(privconn);
+    return ret;
+no_memory:
+    virInterfaceObjListFree(&privconn->backupIfaces);
+    goto cleanup;
+}
+
+static int testInterfaceChangeCommit(virConnectPtr conn,
+                                     unsigned int flags ATTRIBUTE_UNUSED)
+{
+    testConnPtr privconn = conn->privateData;
+    int ret = -1;
+
+    testDriverLock(privconn);
+
+    if (!privconn->transaction_running) {
+        testError(VIR_ERR_OPERATION_INVALID, _("no transaction running, "
+                  "nothing to be commited."));
+        goto cleanup;
+    }
+
+    virInterfaceObjListFree(&privconn->backupIfaces);
+    privconn->transaction_running = 0;
+
+    ret = 0;
+
+cleanup:
+    testDriverUnlock(privconn);
+
+    return ret;
+}
+
+static int testInterfaceChangeRollback(virConnectPtr conn,
+                                       unsigned int flags ATTRIBUTE_UNUSED)
+{
+    testConnPtr privconn = conn->privateData;
+    int ret = -1;
+
+    testDriverLock(privconn);
+
+    if (!privconn->transaction_running) {
+        testError(VIR_ERR_OPERATION_INVALID, _("no transaction running, "
+                  "nothing to rollback."));
+        goto cleanup;
+    }
+
+    virInterfaceObjListFree(&privconn->ifaces);
+    privconn->ifaces.count = privconn->backupIfaces.count;
+    privconn->ifaces.objs = privconn->backupIfaces.objs;
+    privconn->backupIfaces.count = 0;
+    privconn->backupIfaces.objs = NULL;
+
+    privconn->transaction_running = 0;
+
+    ret = 0;
+
+cleanup:
+    testDriverUnlock(privconn);
+    return ret;
+}
 
 static char *testInterfaceGetXMLDesc(virInterfacePtr iface,
                                      unsigned int flags ATTRIBUTE_UNUSED)
@@ -5488,9 +5598,9 @@ static virInterfaceDriver testInterfaceDriver = {
     testInterfaceCreate,        /* interfaceCreate */
     testInterfaceDestroy,       /* interfaceDestroy */
     testInterfaceIsActive,      /* interfaceIsActive */
-    NULL,                       /* interfaceChangeStart */
-    NULL,                       /* interfaceChangeCommit */
-    NULL,                       /* interfaceChangeRollback */
+    testInterfaceChangeStart,   /* interfaceChangeStart */
+    testInterfaceChangeCommit,  /* interfaceChangeCommit */
+    testInterfaceChangeRollback, /* interfaceChangeRollback */
 };
 
 
-- 
1.7.5.rc3

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