[PATCH] test_driver: Implement virDomainGetControlInfo and add test

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

 



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@xxxxxxxxx>
---
 src/test/test_driver.c | 63 ++++++++++++++++++++++++++++++++++++++++++
 tests/virshtest.c      | 11 ++++++++
 2 files changed, 74 insertions(+)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index ef0ddab54d..892dc978f2 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -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 */
diff --git a/tests/virshtest.c b/tests/virshtest.c
index c1974c46cb..fe0c420958 100644
--- a/tests/virshtest.c
+++ b/tests/virshtest.c
@@ -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, ...) \
-- 
2.32.0




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

  Powered by Linux