[libvirt] [PATCH 1/2] test: Add testDomainShutdownState helper

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

 



Performs changes needed when stopping a VM (which are currently duplicated
in several places, and forgotten in others).

Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
---
 src/test/test_driver.c |   42 +++++++++++++++++++++++-------------------
 1 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index df9090e..35299d5 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -469,6 +469,15 @@ cleanup:
     return ret;
 }
 
+static void
+testDomainShutdownState(virDomainPtr domain,
+                        virDomainObjPtr privdom)
+{
+    privdom->state = VIR_DOMAIN_SHUTOFF;
+    privdom->def->id = -1;
+    domain->id = -1;
+}
+
 static int testOpenDefault(virConnectPtr conn) {
     int u;
     struct timeval tv;
@@ -1365,19 +1374,17 @@ static int testDestroyDomain (virDomainPtr domain)
         goto cleanup;
     }
 
-    privdom->state = VIR_DOMAIN_SHUTOFF;
-    privdom->def->id = -1;
-    domain->id = -1;
+    testDomainShutdownState(domain, privdom);
     event = virDomainEventNewFromObj(privdom,
                                      VIR_DOMAIN_EVENT_STOPPED,
                                      VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
+
     if (!privdom->persistent) {
         virDomainRemoveInactive(&privconn->domains,
                                 privdom);
         privdom = NULL;
     }
 
-
     ret = 0;
 cleanup:
     if (privdom)
@@ -1494,19 +1501,18 @@ static int testShutdownDomain (virDomainPtr domain)
         goto cleanup;
     }
 
-    privdom->state = VIR_DOMAIN_SHUTOFF;
-    domain->id = -1;
-    privdom->def->id = -1;
+    testDomainShutdownState(domain, privdom);
     event = virDomainEventNewFromObj(privdom,
                                      VIR_DOMAIN_EVENT_STOPPED,
                                      VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
+
     if (!privdom->persistent) {
         virDomainRemoveInactive(&privconn->domains,
                                 privdom);
         privdom = NULL;
     }
-    ret = 0;
 
+    ret = 0;
 cleanup:
     if (privdom)
         virDomainObjUnlock(privdom);
@@ -1538,8 +1544,6 @@ static int testRebootDomain (virDomainPtr domain,
     switch (privdom->def->onReboot) {
     case VIR_DOMAIN_LIFECYCLE_DESTROY:
         privdom->state = VIR_DOMAIN_SHUTOFF;
-        domain->id = -1;
-        privdom->def->id = -1;
         break;
 
     case VIR_DOMAIN_LIFECYCLE_RESTART:
@@ -1548,8 +1552,6 @@ static int testRebootDomain (virDomainPtr domain,
 
     case VIR_DOMAIN_LIFECYCLE_PRESERVE:
         privdom->state = VIR_DOMAIN_SHUTOFF;
-        domain->id = -1;
-        privdom->def->id = -1;
         break;
 
     case VIR_DOMAIN_LIFECYCLE_RESTART_RENAME:
@@ -1558,15 +1560,15 @@ static int testRebootDomain (virDomainPtr domain,
 
     default:
         privdom->state = VIR_DOMAIN_SHUTOFF;
-        domain->id = -1;
-        privdom->def->id = -1;
         break;
     }
 
     if (privdom->state == VIR_DOMAIN_SHUTOFF) {
+        testDomainShutdownState(domain, privdom);
         event = virDomainEventNewFromObj(privdom,
                                          VIR_DOMAIN_EVENT_STOPPED,
                                          VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
+
         if (!privdom->persistent) {
             virDomainRemoveInactive(&privconn->domains,
                                     privdom);
@@ -1575,7 +1577,6 @@ static int testRebootDomain (virDomainPtr domain,
     }
 
     ret = 0;
-
 cleanup:
     if (privdom)
         virDomainObjUnlock(privdom);
@@ -1689,17 +1690,18 @@ static int testDomainSave(virDomainPtr domain,
     }
     fd = -1;
 
-    privdom->state = VIR_DOMAIN_SHUTOFF;
+    testDomainShutdownState(domain, privdom);
     event = virDomainEventNewFromObj(privdom,
                                      VIR_DOMAIN_EVENT_STOPPED,
                                      VIR_DOMAIN_EVENT_STOPPED_SAVED);
+
     if (!privdom->persistent) {
         virDomainRemoveInactive(&privconn->domains,
                                 privdom);
         privdom = NULL;
     }
-    ret = 0;
 
+    ret = 0;
 cleanup:
     VIR_FREE(xml);
 
@@ -1842,17 +1844,19 @@ static int testDomainCoreDump(virDomainPtr domain,
                              domain->name, to);
         goto cleanup;
     }
-    privdom->state = VIR_DOMAIN_SHUTOFF;
+
+    testDomainShutdownState(domain, privdom);
     event = virDomainEventNewFromObj(privdom,
                                      VIR_DOMAIN_EVENT_STOPPED,
                                      VIR_DOMAIN_EVENT_STOPPED_CRASHED);
+
     if (!privdom->persistent) {
         virDomainRemoveInactive(&privconn->domains,
                                 privdom);
         privdom = NULL;
     }
-    ret = 0;
 
+    ret = 0;
 cleanup:
     if (fd != -1)
         close(fd);
-- 
1.6.5.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]