test_driver: Implement virDomainGetControlInfo and add test

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>
This commit is contained in:
Luke Yue 2021-07-13 20:21:32 +08:00 committed by Michal Privoznik
parent e7ad645a8e
commit 3ea1ec7fa2
2 changed files with 74 additions and 0 deletions

View 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 */

View 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, ...) \