]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
test_driver: Implement virDomainGetControlInfo and add test
authorLuke Yue <lukedyue@gmail.com>
Tue, 13 Jul 2021 12:21:32 +0000 (20:21 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 19 Jul 2021 09:42:00 +0000 (11:42 +0200)
As test driver won't have real background job running, in order to get
all possible states, the time is used here to decide which state to be
returned. The default time will get `ok` as return value.

Note that using `virsh domtime fc4 200` won't take effect for the test
driver, to get other states, you have to enter virsh interactive
terminal and set time.

Signed-off-by: Luke Yue <lukedyue@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/test/test_driver.c
tests/virshtest.c

index ef0ddab54de5f99e4ab023e09b8fa17f2191135f..892dc978f232fe5be8c8de85b39b18c4f97f3ed9 100644 (file)
@@ -2080,6 +2080,68 @@ testDomainGetState(virDomainPtr domain,
     return 0;
 }
 
+static int
+testDomainGetControlInfo(virDomainPtr dom,
+                         virDomainControlInfoPtr info,
+                         unsigned int flags)
+{
+    virDomainObj *vm;
+    testDomainObjPrivate *priv;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    if (!(vm = testDomObjFromDomain(dom)))
+        goto cleanup;
+
+    if (virDomainObjCheckActive(vm) < 0)
+        goto cleanup;
+
+    priv = vm->privateData;
+
+    memset(info, 0, sizeof(*info));
+
+    if (priv->seconds > 0 && priv->seconds < 10000) {
+        info->state = VIR_DOMAIN_CONTROL_JOB;
+        info->stateTime = priv->seconds;
+    } else if (priv->seconds < 30000 && priv->seconds >= 10000) {
+        info->state = VIR_DOMAIN_CONTROL_OCCUPIED;
+        info->stateTime = priv->seconds - 10000;
+    } else if (priv->seconds < 60000 && priv->seconds >= 30000) {
+        info->state = VIR_DOMAIN_CONTROL_ERROR;
+        switch (priv->seconds % 4) {
+        case 0:
+            info->details = VIR_DOMAIN_CONTROL_ERROR_REASON_NONE;
+            break;
+
+        case 1:
+            info->details = VIR_DOMAIN_CONTROL_ERROR_REASON_UNKNOWN;
+            break;
+
+        case 2:
+            info->details = VIR_DOMAIN_CONTROL_ERROR_REASON_MONITOR;
+            break;
+
+        case 3:
+            info->details = VIR_DOMAIN_CONTROL_ERROR_REASON_INTERNAL;
+            break;
+
+        default:
+            info->details = VIR_DOMAIN_CONTROL_ERROR_REASON_NONE;
+            break;
+        }
+        info->stateTime = priv->seconds - 30000;
+    } else {
+        info->state = VIR_DOMAIN_CONTROL_OK;
+    }
+
+    ret = 0;
+
+ cleanup:
+    virDomainObjEndAPI(&vm);
+    return ret;
+}
+
 static int
 testDomainGetTime(virDomainPtr dom,
                   long long *seconds,
@@ -9335,6 +9397,7 @@ static virHypervisorDriver testHypervisorDriver = {
     .domainGetHostname = testDomainGetHostname, /* 5.5.0 */
     .domainGetInfo = testDomainGetInfo, /* 0.1.1 */
     .domainGetState = testDomainGetState, /* 0.9.2 */
+    .domainGetControlInfo = testDomainGetControlInfo, /* 7.6.0 */
     .domainGetTime = testDomainGetTime, /* 5.4.0 */
     .domainSetTime = testDomainSetTime, /* 5.7.0 */
     .domainSave = testDomainSave, /* 0.3.2 */
index c1974c46cb7c75078faaa3ee943452f7f889764f..fe0c420958812f2c889153408170c87251612271 100644 (file)
@@ -250,6 +250,13 @@ static int testCompareDomstateByName(const void *data G_GNUC_UNUSED)
     return testCompareOutputLit(exp, NULL, argv);
 }
 
+static int testCompareDomControlInfoByName(const void *data G_GNUC_UNUSED)
+{
+    const char *const argv[] = { VIRSH_CUSTOM, "domcontrol", "fc4", NULL };
+    const char *exp = "ok\n\n";
+    return testCompareOutputLit(exp, NULL, argv);
+}
+
 struct testInfo {
     const char *const *argv;
     const char *result;
@@ -334,6 +341,10 @@ mymain(void)
                    testCompareDomstateByName, NULL) != 0)
         ret = -1;
 
+    if (virTestRun("virsh domcontrol (by name)",
+                   testCompareDomControlInfoByName, NULL) != 0)
+        ret = -1;
+
     /* It's a bit awkward listing result before argument, but that's a
      * limitation of C99 vararg macros.  */
 # define DO_TEST(i, result, ...) \