[PATCH 0/4] Implement some job related APIs for test driver

Luke Yue (4): test_driver: Implement virDomainGetJobInfo test_driver: Implement virDomainGetJobStats test_driver: Implement virDomainAbortJob virshtest: add test for domjobinfo src/test/test_driver.c | 170 +++++++++++++++++++++++++++++++++++++++++ tests/virshtest.c | 11 +++ 2 files changed, 181 insertions(+) -- 2.32.0

As in testDomainGetControlInfo, a background job should be running between 0-10000 seconds, so make the testDomainGetJobInfo consistent with it. Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 892dc978f2..29b19d80f0 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2604,6 +2604,56 @@ testDomainGetOSType(virDomainPtr dom G_GNUC_UNUSED) return ret; } +static int +testDomainGetJobInfoImpl(virDomainObj *dom, + virDomainJobInfoPtr info) +{ + testDomainObjPrivate *priv = dom->privateData; + + memset(info, 0, sizeof(*info)); + + if (priv->seconds < 10000) { + info->type = VIR_DOMAIN_JOB_BOUNDED; + info->dataTotal = 10000; + info->dataProcessed = priv->seconds; + info->dataRemaining = 10000 - priv->seconds; + info->timeElapsed = priv->seconds; + info->timeRemaining = 10000 - priv->seconds; + info->memTotal = 1048576; + info->memProcessed = 1048576 - priv->seconds; + info->memRemaining = priv->seconds; + info->fileTotal = 2097152; + info->fileProcessed = 2097152 - priv->seconds; + info->fileRemaining = priv->seconds; + } else if (priv->seconds < 30000 && priv->seconds >= 10000) { + info->type = VIR_DOMAIN_JOB_COMPLETED; + } else { + info->type = VIR_DOMAIN_JOB_NONE; + } + + return 0; +} + +static int +testDomainGetJobInfo(virDomainPtr dom, + virDomainJobInfoPtr info) +{ + virDomainObj *vm; + int ret = -1; + + if (!(vm = testDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto cleanup; + + ret = testDomainGetJobInfoImpl(vm, info); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + static int testDomainGetLaunchSecurityInfo(virDomainPtr domain G_GNUC_UNUSED, @@ -9484,6 +9534,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainMemoryPeek = testDomainMemoryPeek, /* 5.4.0 */ .domainGetBlockInfo = testDomainGetBlockInfo, /* 5.7.0 */ .domainSetLifecycleAction = testDomainSetLifecycleAction, /* 5.7.0 */ + .domainGetJobInfo = testDomainGetJobInfo, /* 7.6.0 */ .domainSnapshotNum = testDomainSnapshotNum, /* 1.1.4 */ .domainSnapshotListNames = testDomainSnapshotListNames, /* 1.1.4 */ -- 2.32.0

On Thu, Jul 22, 2021 at 03:13:22PM +0800, Luke Yue wrote:
As in testDomainGetControlInfo, a background job should be running between 0-10000 seconds, so make the testDomainGetJobInfo consistent with it.
Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 892dc978f2..29b19d80f0 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2604,6 +2604,56 @@ testDomainGetOSType(virDomainPtr dom G_GNUC_UNUSED) return ret; }
+static int +testDomainGetJobInfoImpl(virDomainObj *dom, + virDomainJobInfoPtr info) +{ + testDomainObjPrivate *priv = dom->privateData; + + memset(info, 0, sizeof(*info)); + + if (priv->seconds < 10000) { + info->type = VIR_DOMAIN_JOB_BOUNDED; + info->dataTotal = 10000; + info->dataProcessed = priv->seconds; + info->dataRemaining = 10000 - priv->seconds; + info->timeElapsed = priv->seconds; + info->timeRemaining = 10000 - priv->seconds; + info->memTotal = 1048576; + info->memProcessed = 1048576 - priv->seconds; + info->memRemaining = priv->seconds; + info->fileTotal = 2097152; + info->fileProcessed = 2097152 - priv->seconds; + info->fileRemaining = priv->seconds; + } else if (priv->seconds < 30000 && priv->seconds >= 10000) { + info->type = VIR_DOMAIN_JOB_COMPLETED; + } else { + info->type = VIR_DOMAIN_JOB_NONE; + } +
So this is an interesting approach. However because we are not doing different setups for different domains (all possible ones use the same PrivateAlloc function) we cannot test much here. But then when you think about changing the domain time for some domains it (even by just using virDomainSetTime API) the job output is very much non-intuitive. So I would rather prefer some extra struct member(s) to keep track of the job info. It can then be nicely used for testing domainGetJobInfo with flags as well as aborting and starting jobs in a more interested and I think useful way. Other than that this series looks fine.
+ return 0; +} + +static int +testDomainGetJobInfo(virDomainPtr dom, + virDomainJobInfoPtr info) +{ + virDomainObj *vm; + int ret = -1; + + if (!(vm = testDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto cleanup; + + ret = testDomainGetJobInfoImpl(vm, info); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} +
static int testDomainGetLaunchSecurityInfo(virDomainPtr domain G_GNUC_UNUSED, @@ -9484,6 +9534,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainMemoryPeek = testDomainMemoryPeek, /* 5.4.0 */ .domainGetBlockInfo = testDomainGetBlockInfo, /* 5.7.0 */ .domainSetLifecycleAction = testDomainSetLifecycleAction, /* 5.7.0 */ + .domainGetJobInfo = testDomainGetJobInfo, /* 7.6.0 */
.domainSnapshotNum = testDomainSnapshotNum, /* 1.1.4 */ .domainSnapshotListNames = testDomainSnapshotListNames, /* 1.1.4 */ -- 2.32.0

On Tue, 2021-08-10 at 17:49 +0200, Martin Kletzander wrote:
On Thu, Jul 22, 2021 at 03:13:22PM +0800, Luke Yue wrote:
As in testDomainGetControlInfo, a background job should be running between 0-10000 seconds, so make the testDomainGetJobInfo consistent with it.
Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 892dc978f2..29b19d80f0 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2604,6 +2604,56 @@ testDomainGetOSType(virDomainPtr dom G_GNUC_UNUSED) return ret; }
+static int +testDomainGetJobInfoImpl(virDomainObj *dom, + virDomainJobInfoPtr info) +{ + testDomainObjPrivate *priv = dom->privateData; + + memset(info, 0, sizeof(*info)); + + if (priv->seconds < 10000) { + info->type = VIR_DOMAIN_JOB_BOUNDED; + info->dataTotal = 10000; + info->dataProcessed = priv->seconds; + info->dataRemaining = 10000 - priv->seconds; + info->timeElapsed = priv->seconds; + info->timeRemaining = 10000 - priv->seconds; + info->memTotal = 1048576; + info->memProcessed = 1048576 - priv->seconds; + info->memRemaining = priv->seconds; + info->fileTotal = 2097152; + info->fileProcessed = 2097152 - priv->seconds; + info->fileRemaining = priv->seconds; + } else if (priv->seconds < 30000 && priv->seconds >= 10000) { + info->type = VIR_DOMAIN_JOB_COMPLETED; + } else { + info->type = VIR_DOMAIN_JOB_NONE; + } +
So this is an interesting approach. However because we are not doing different setups for different domains (all possible ones use the same PrivateAlloc function) we cannot test much here. But then when you think about changing the domain time for some domains it (even by just using virDomainSetTime API) the job output is very much non- intuitive. So I would rather prefer some extra struct member(s) to keep track of the job info. It can then be nicely used for testing domainGetJobInfo with flags as well as aborting and starting jobs in a more interested and I think useful way.
Other than that this series looks fine.
Thanks for the review! So if I understand you correctly, we have to add struct member(s) such as unsigned int jobType; to testDomainObjPrivate to store the job info rather than using time. We can change it to VIR_DOMAIN_BLOCK_JOB_CANCELED when we use virDomainAbortJob, and change it to other values when the APIs should start a job, such as virDomainBackupBegin (not implement yet though). But I am a little bit puzzling about testing the domainGetJobInfo with flags, the virDomainGetJobInfo currently don't have flags as parameter, do we have to add one? Or do I misunderstand something? Thanks, Luke
+ return 0; +} + +static int +testDomainGetJobInfo(virDomainPtr dom, + virDomainJobInfoPtr info) +{ + virDomainObj *vm; + int ret = -1; + + if (!(vm = testDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto cleanup; + + ret = testDomainGetJobInfoImpl(vm, info); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} +
static int testDomainGetLaunchSecurityInfo(virDomainPtr domain G_GNUC_UNUSED, @@ -9484,6 +9534,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainMemoryPeek = testDomainMemoryPeek, /* 5.4.0 */ .domainGetBlockInfo = testDomainGetBlockInfo, /* 5.7.0 */ .domainSetLifecycleAction = testDomainSetLifecycleAction, /* 5.7.0 */ + .domainGetJobInfo = testDomainGetJobInfo, /* 7.6.0 */
.domainSnapshotNum = testDomainSnapshotNum, /* 1.1.4 */ .domainSnapshotListNames = testDomainSnapshotListNames, /* 1.1.4 */ -- 2.32.0

On Wed, Aug 11, 2021 at 08:31:03PM +0800, Luke Yue wrote:
On Tue, 2021-08-10 at 17:49 +0200, Martin Kletzander wrote:
On Thu, Jul 22, 2021 at 03:13:22PM +0800, Luke Yue wrote:
As in testDomainGetControlInfo, a background job should be running between 0-10000 seconds, so make the testDomainGetJobInfo consistent with it.
Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 892dc978f2..29b19d80f0 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2604,6 +2604,56 @@ testDomainGetOSType(virDomainPtr dom G_GNUC_UNUSED) return ret; }
+static int +testDomainGetJobInfoImpl(virDomainObj *dom, + virDomainJobInfoPtr info) +{ + testDomainObjPrivate *priv = dom->privateData; + + memset(info, 0, sizeof(*info)); + + if (priv->seconds < 10000) { + info->type = VIR_DOMAIN_JOB_BOUNDED; + info->dataTotal = 10000; + info->dataProcessed = priv->seconds; + info->dataRemaining = 10000 - priv->seconds; + info->timeElapsed = priv->seconds; + info->timeRemaining = 10000 - priv->seconds; + info->memTotal = 1048576; + info->memProcessed = 1048576 - priv->seconds; + info->memRemaining = priv->seconds; + info->fileTotal = 2097152; + info->fileProcessed = 2097152 - priv->seconds; + info->fileRemaining = priv->seconds; + } else if (priv->seconds < 30000 && priv->seconds >= 10000) { + info->type = VIR_DOMAIN_JOB_COMPLETED; + } else { + info->type = VIR_DOMAIN_JOB_NONE; + } +
So this is an interesting approach. However because we are not doing different setups for different domains (all possible ones use the same PrivateAlloc function) we cannot test much here. But then when you think about changing the domain time for some domains it (even by just using virDomainSetTime API) the job output is very much non- intuitive. So I would rather prefer some extra struct member(s) to keep track of the job info. It can then be nicely used for testing domainGetJobInfo with flags as well as aborting and starting jobs in a more interested and I think useful way.
Other than that this series looks fine.
Thanks for the review! So if I understand you correctly, we have to add struct member(s) such as
unsigned int jobType;
to testDomainObjPrivate to store the job info rather than using time.
Yes, if you want you can even use more members if there's a use for them.
We can change it to VIR_DOMAIN_BLOCK_JOB_CANCELED when we use virDomainAbortJob, and change it to other values when the APIs should start a job, such as virDomainBackupBegin (not implement yet though).
Yes, and starting any jobs is not needed right now. But it is way clearer to see what the code does when testDomainAbortJob() does: priv->jobState = VIR_DOMAIN_JOB_CANCELLED compared to: priv->seconds = 10000 and it is also easier to review because it is easy to gloss over the fact that priv->seconds == 10000 does not mean CANCELLED, but COMPLETED. Essentially more readable data structures make it easier to spot errors.
But I am a little bit puzzling about testing the domainGetJobInfo with flags, the virDomainGetJobInfo currently don't have flags as parameter, do we have to add one? Or do I misunderstand something?
Sorry, I meant JobStats, there you can get info for completed jobs and so on. Those are not that important for the test driver, but once the backend is implemented they should be trivial to adapt.
Thanks, Luke
+ return 0; +} + +static int +testDomainGetJobInfo(virDomainPtr dom, + virDomainJobInfoPtr info) +{ + virDomainObj *vm; + int ret = -1; + + if (!(vm = testDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto cleanup; + + ret = testDomainGetJobInfoImpl(vm, info); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} +
static int testDomainGetLaunchSecurityInfo(virDomainPtr domain G_GNUC_UNUSED, @@ -9484,6 +9534,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainMemoryPeek = testDomainMemoryPeek, /* 5.4.0 */ .domainGetBlockInfo = testDomainGetBlockInfo, /* 5.7.0 */ .domainSetLifecycleAction = testDomainSetLifecycleAction, /* 5.7.0 */ + .domainGetJobInfo = testDomainGetJobInfo, /* 7.6.0 */
.domainSnapshotNum = testDomainSnapshotNum, /* 1.1.4 */ .domainSnapshotListNames = testDomainSnapshotListNames, /* 1.1.4 */ -- 2.32.0

On Wed, 2021-08-11 at 15:11 +0200, Martin Kletzander wrote:
On Wed, Aug 11, 2021 at 08:31:03PM +0800, Luke Yue wrote:
On Tue, 2021-08-10 at 17:49 +0200, Martin Kletzander wrote:
On Thu, Jul 22, 2021 at 03:13:22PM +0800, Luke Yue wrote:
As in testDomainGetControlInfo, a background job should be running between 0-10000 seconds, so make the testDomainGetJobInfo consistent with it.
Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 892dc978f2..29b19d80f0 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2604,6 +2604,56 @@ testDomainGetOSType(virDomainPtr dom G_GNUC_UNUSED) return ret; }
+static int +testDomainGetJobInfoImpl(virDomainObj *dom, + virDomainJobInfoPtr info) +{ + testDomainObjPrivate *priv = dom->privateData; + + memset(info, 0, sizeof(*info)); + + if (priv->seconds < 10000) { + info->type = VIR_DOMAIN_JOB_BOUNDED; + info->dataTotal = 10000; + info->dataProcessed = priv->seconds; + info->dataRemaining = 10000 - priv->seconds; + info->timeElapsed = priv->seconds; + info->timeRemaining = 10000 - priv->seconds; + info->memTotal = 1048576; + info->memProcessed = 1048576 - priv->seconds; + info->memRemaining = priv->seconds; + info->fileTotal = 2097152; + info->fileProcessed = 2097152 - priv->seconds; + info->fileRemaining = priv->seconds; + } else if (priv->seconds < 30000 && priv->seconds >= 10000) { + info->type = VIR_DOMAIN_JOB_COMPLETED; + } else { + info->type = VIR_DOMAIN_JOB_NONE; + } +
So this is an interesting approach. However because we are not doing different setups for different domains (all possible ones use the same PrivateAlloc function) we cannot test much here. But then when you think about changing the domain time for some domains it (even by just using virDomainSetTime API) the job output is very much non- intuitive. So I would rather prefer some extra struct member(s) to keep track of the job info. It can then be nicely used for testing domainGetJobInfo with flags as well as aborting and starting jobs in a more interested and I think useful way.
Other than that this series looks fine.
Thanks for the review! So if I understand you correctly, we have to add struct member(s) such as
unsigned int jobType;
to testDomainObjPrivate to store the job info rather than using time.
Yes, if you want you can even use more members if there's a use for them.
We can change it to VIR_DOMAIN_BLOCK_JOB_CANCELED when we use virDomainAbortJob, and change it to other values when the APIs should start a job, such as virDomainBackupBegin (not implement yet though).
Yes, and starting any jobs is not needed right now. But it is way clearer to see what the code does when testDomainAbortJob() does:
priv->jobState = VIR_DOMAIN_JOB_CANCELLED
compared to:
priv->seconds = 10000
and it is also easier to review because it is easy to gloss over the fact that priv->seconds == 10000 does not mean CANCELLED, but COMPLETED. Essentially more readable data structures make it easier to spot errors.
But I am a little bit puzzling about testing the domainGetJobInfo with flags, the virDomainGetJobInfo currently don't have flags as parameter, do we have to add one? Or do I misunderstand something?
Sorry, I meant JobStats, there you can get info for completed jobs and so on. Those are not that important for the test driver, but once the backend is implemented they should be trivial to adapt.
Thanks, I think I got your points now, I will try to implement them in v2.
Thanks, Luke
+ return 0; +} + +static int +testDomainGetJobInfo(virDomainPtr dom, + virDomainJobInfoPtr info) +{ + virDomainObj *vm; + int ret = -1; + + if (!(vm = testDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto cleanup; + + ret = testDomainGetJobInfoImpl(vm, info); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} +
static int testDomainGetLaunchSecurityInfo(virDomainPtr domain G_GNUC_UNUSED, @@ -9484,6 +9534,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainMemoryPeek = testDomainMemoryPeek, /* 5.4.0 */ .domainGetBlockInfo = testDomainGetBlockInfo, /* 5.7.0 */ .domainSetLifecycleAction = testDomainSetLifecycleAction, /* 5.7.0 */ + .domainGetJobInfo = testDomainGetJobInfo, /* 7.6.0 */
.domainSnapshotNum = testDomainSnapshotNum, /* 1.1.4 */ .domainSnapshotListNames = testDomainSnapshotListNames, /* 1.1.4 */ -- 2.32.0

Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 90 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 29b19d80f0..4af8ce42f2 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2654,6 +2654,95 @@ testDomainGetJobInfo(virDomainPtr dom, return ret; } +static int +testDomainJobInfoToParams(virDomainJobInfoPtr info, + int *type, + virTypedParameterPtr *params, + int *nparams) +{ + virTypedParameterPtr par = NULL; + int maxpar = 0; + int npar = 0; + + if (virTypedParamsAddULLong(&par, &npar, &maxpar, + VIR_DOMAIN_JOB_DATA_TOTAL, + info->dataTotal) < 0 || + virTypedParamsAddULLong(&par, &npar, &maxpar, + VIR_DOMAIN_JOB_DATA_PROCESSED, + info->dataProcessed) < 0 || + virTypedParamsAddULLong(&par, &npar, &maxpar, + VIR_DOMAIN_JOB_DATA_REMAINING, + info->dataRemaining) < 0 || + virTypedParamsAddULLong(&par, &npar, &maxpar, + VIR_DOMAIN_JOB_TIME_ELAPSED, + info->timeElapsed) < 0 || + virTypedParamsAddULLong(&par, &npar, &maxpar, + VIR_DOMAIN_JOB_TIME_REMAINING, + info->timeRemaining) < 0 || + virTypedParamsAddULLong(&par, &npar, &maxpar, + VIR_DOMAIN_JOB_MEMORY_TOTAL, + info->memTotal) < 0 || + virTypedParamsAddULLong(&par, &npar, &maxpar, + VIR_DOMAIN_JOB_MEMORY_PROCESSED, + info->memProcessed) < 0 || + virTypedParamsAddULLong(&par, &npar, &maxpar, + VIR_DOMAIN_JOB_MEMORY_REMAINING, + info->memRemaining) < 0 || + virTypedParamsAddULLong(&par, &npar, &maxpar, + VIR_DOMAIN_JOB_DISK_TOTAL, + info->fileTotal) < 0 || + virTypedParamsAddULLong(&par, &npar, &maxpar, + VIR_DOMAIN_JOB_DISK_PROCESSED, + info->fileProcessed) < 0 || + virTypedParamsAddULLong(&par, &npar, &maxpar, + VIR_DOMAIN_JOB_DISK_REMAINING, + info->fileRemaining) < 0) + goto error; + + *type = info->type; + *params = par; + *nparams = npar; + return 0; + + error: + virTypedParamsFree(par, npar); + return -1; +} + +static int +testDomainGetJobStats(virDomainPtr domain, + int *type, + virTypedParameterPtr *params, + int *nparams, + unsigned int flags) +{ + virDomainJobInfo jobInfo; + virDomainObj *dom; + int ret = -1; + + virCheckFlags(0, -1); + + if (!(dom = testDomObjFromDomain(domain))) + return -1; + + if (testDomainGetJobInfoImpl(dom, &jobInfo) < 0) + goto cleanup; + + if (jobInfo.type == VIR_DOMAIN_JOB_NONE) { + *type = VIR_DOMAIN_JOB_NONE; + *params = NULL; + *nparams = 0; + ret = 0; + goto cleanup; + } + + ret = testDomainJobInfoToParams(&jobInfo, type, params, nparams); + + cleanup: + virDomainObjEndAPI(&dom); + + return ret; +} static int testDomainGetLaunchSecurityInfo(virDomainPtr domain G_GNUC_UNUSED, @@ -9535,6 +9624,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainGetBlockInfo = testDomainGetBlockInfo, /* 5.7.0 */ .domainSetLifecycleAction = testDomainSetLifecycleAction, /* 5.7.0 */ .domainGetJobInfo = testDomainGetJobInfo, /* 7.6.0 */ + .domainGetJobStats = testDomainGetJobStats, /* 7.6.0 */ .domainSnapshotNum = testDomainSnapshotNum, /* 1.1.4 */ .domainSnapshotListNames = testDomainSnapshotListNames, /* 1.1.4 */ -- 2.32.0

As the job should be running between 0-10000 seconds, so if the API is triggered between 0-10000 seconds, it will set time to 10000, so that the job status will be completed. Otherwise, there is no job active and report error. Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 4af8ce42f2..b31ab95101 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2744,6 +2744,34 @@ testDomainGetJobStats(virDomainPtr domain, return ret; } +static int +testDomainAbortJob(virDomainPtr dom) +{ + virDomainObj *vm; + int ret = -1; + testDomainObjPrivate *priv; + + if (!(vm = testDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto cleanup; + + priv = vm->privateData; + + if (priv->seconds >= 10000) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("no job is active on the domain")); + } else { + priv->seconds = 10000; + ret = 0; + } + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + static int testDomainGetLaunchSecurityInfo(virDomainPtr domain G_GNUC_UNUSED, virTypedParameterPtr *params G_GNUC_UNUSED, @@ -9625,6 +9653,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainSetLifecycleAction = testDomainSetLifecycleAction, /* 5.7.0 */ .domainGetJobInfo = testDomainGetJobInfo, /* 7.6.0 */ .domainGetJobStats = testDomainGetJobStats, /* 7.6.0 */ + .domainAbortJob = testDomainAbortJob, /* 7.6.0 */ .domainSnapshotNum = testDomainSnapshotNum, /* 1.1.4 */ .domainSnapshotListNames = testDomainSnapshotListNames, /* 1.1.4 */ -- 2.32.0

Signed-off-by: Luke Yue <lukedyue@gmail.com> --- tests/virshtest.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/virshtest.c b/tests/virshtest.c index fe0c420958..88609af89c 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -257,6 +257,13 @@ static int testCompareDomControlInfoByName(const void *data G_GNUC_UNUSED) return testCompareOutputLit(exp, NULL, argv); } +static int testCompareDomJobInfoByName(const void *data G_GNUC_UNUSED) +{ + const char *const argv[] = { VIRSH_CUSTOM, "domjobinfo", "fc4", NULL }; + const char *exp = "Job type: None \n\n"; + return testCompareOutputLit(exp, NULL, argv); +} + struct testInfo { const char *const *argv; const char *result; @@ -345,6 +352,10 @@ mymain(void) testCompareDomControlInfoByName, NULL) != 0) ret = -1; + if (virTestRun("virsh domjobinfo (by name)", + testCompareDomJobInfoByName, 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
participants (2)
-
Luke Yue
-
Martin Kletzander