]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
test_driver: implement virDomainSetLifecycleAction
authorIlias Stamatis <stamatis.iliass@gmail.com>
Tue, 13 Aug 2019 12:28:10 +0000 (15:28 +0300)
committerErik Skultety <eskultet@redhat.com>
Wed, 14 Aug 2019 16:10:09 +0000 (18:10 +0200)
Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/test/test_driver.c

index 89ebcc5df10691e416e763d87b3feb69e88339a8..c39eef2d4b4b7c674b3063df1155852b51a549af 100755 (executable)
@@ -8129,6 +8129,63 @@ testDomainGetBlockInfo(virDomainPtr dom,
 }
 
 
+static void
+testDomainModifyLifecycleAction(virDomainDefPtr def,
+                                virDomainLifecycle type,
+                                virDomainLifecycleAction action)
+{
+    switch (type) {
+    case VIR_DOMAIN_LIFECYCLE_POWEROFF:
+        def->onPoweroff = action;
+        break;
+    case VIR_DOMAIN_LIFECYCLE_REBOOT:
+        def->onReboot = action;
+        break;
+    case VIR_DOMAIN_LIFECYCLE_CRASH:
+        def->onCrash = action;
+        break;
+    case VIR_DOMAIN_LIFECYCLE_LAST:
+        break;
+    }
+}
+
+
+static int
+testDomainSetLifecycleAction(virDomainPtr dom,
+                             unsigned int type,
+                             unsigned int action,
+                             unsigned int flags)
+{
+    virDomainObjPtr vm = NULL;
+    virDomainDefPtr def = NULL;
+    virDomainDefPtr persistentDef = NULL;
+    int ret = -1;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG, -1);
+
+    if (!virDomainDefLifecycleActionAllowed(type, action))
+        return -1;
+
+    if (!(vm = testDomObjFromDomain(dom)))
+        return -1;
+
+    if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
+        goto cleanup;
+
+    if (def)
+        testDomainModifyLifecycleAction(def, type, action);
+
+    if (persistentDef)
+        testDomainModifyLifecycleAction(persistentDef, type, action);
+
+    ret = 0;
+ cleanup:
+    virDomainObjEndAPI(&vm);
+    return ret;
+}
+
+
 /*
  * Snapshot APIs
  */
@@ -9434,6 +9491,7 @@ static virHypervisorDriver testHypervisorDriver = {
     .domainMemoryStats = testDomainMemoryStats, /* 5.7.0 */
     .domainMemoryPeek = testDomainMemoryPeek, /* 5.4.0 */
     .domainGetBlockInfo = testDomainGetBlockInfo, /* 5.7.0 */
+    .domainSetLifecycleAction = testDomainSetLifecycleAction, /* 5.7.0 */
 
     .domainSnapshotNum = testDomainSnapshotNum, /* 1.1.4 */
     .domainSnapshotListNames = testDomainSnapshotListNames, /* 1.1.4 */