mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
qemumonitortestutils: Split up creation of the test to allow reuse
The instrumentation for the monitor test can be hacked for qemu agent testing. Split out the monitor specific stuff to allow using the code in guest agent tests in the future.
This commit is contained in:
parent
a63a7a5af9
commit
3383480430
@ -440,16 +440,11 @@ static qemuMonitorCallbacks qemuCallbacks = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define QEMU_JSON_GREETING "{\"QMP\": {\"version\": {\"qemu\": {\"micro\": 1, \"minor\": 0, \"major\": 1}, \"package\": \" (qemu-kvm-1.0.1)\"}, \"capabilities\": []}}"
|
static qemuMonitorTestPtr
|
||||||
/* We skip the normal handshake reply of "{\"execute\":\"qmp_capabilities\"}" */
|
qemuMonitorCommonTestNew(virDomainXMLOptionPtr xmlopt,
|
||||||
|
virDomainChrSourceDefPtr src)
|
||||||
#define QEMU_TEXT_GREETING "QEMU 1.0,1 monitor - type 'help' for more information"
|
|
||||||
|
|
||||||
qemuMonitorTestPtr
|
|
||||||
qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt)
|
|
||||||
{
|
{
|
||||||
qemuMonitorTestPtr test = NULL;
|
qemuMonitorTestPtr test = NULL;
|
||||||
virDomainChrSourceDef src;
|
|
||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
char *tmpdir_template = NULL;
|
char *tmpdir_template = NULL;
|
||||||
|
|
||||||
@ -477,7 +472,6 @@ qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt)
|
|||||||
if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", test->tmpdir) < 0)
|
if (virAsprintf(&path, "%s/qemumonitorjsontest.sock", test->tmpdir) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
test->json = json;
|
|
||||||
if (!(test->vm = virDomainObjNew(xmlopt)))
|
if (!(test->vm = virDomainObjNew(xmlopt)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
@ -485,29 +479,36 @@ qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt)
|
|||||||
&test->server) < 0)
|
&test->server) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
memset(&src, 0, sizeof(src));
|
memset(src, 0, sizeof(*src));
|
||||||
src.type = VIR_DOMAIN_CHR_TYPE_UNIX;
|
src->type = VIR_DOMAIN_CHR_TYPE_UNIX;
|
||||||
src.data.nix.path = (char *)path;
|
src->data.nix.path = (char *)path;
|
||||||
src.data.nix.listen = false;
|
src->data.nix.listen = false;
|
||||||
|
|
||||||
if (virNetSocketListen(test->server, 1) < 0)
|
if (virNetSocketListen(test->server, 1) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(test->mon = qemuMonitorOpen(test->vm,
|
cleanup:
|
||||||
&src,
|
return test;
|
||||||
json,
|
|
||||||
&qemuCallbacks)))
|
error:
|
||||||
goto error;
|
VIR_FREE(tmpdir_template);
|
||||||
virObjectLock(test->mon);
|
qemuMonitorTestFree(test);
|
||||||
|
test = NULL;
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuMonitorCommonTestInit(qemuMonitorTestPtr test)
|
||||||
|
{
|
||||||
|
if (!test)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (virNetSocketAccept(test->server, &test->client) < 0)
|
if (virNetSocketAccept(test->server, &test->client) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
if (!test->client)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (qemuMonitorTestAddReponse(test, json ?
|
if (!test->client)
|
||||||
QEMU_JSON_GREETING :
|
|
||||||
QEMU_TEXT_GREETING) < 0)
|
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virNetSocketAddIOCallback(test->client,
|
if (virNetSocketAddIOCallback(test->client,
|
||||||
@ -528,15 +529,63 @@ qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt)
|
|||||||
test->running = true;
|
test->running = true;
|
||||||
virMutexUnlock(&test->lock);
|
virMutexUnlock(&test->lock);
|
||||||
|
|
||||||
cleanup:
|
return 0;
|
||||||
VIR_FREE(path);
|
|
||||||
|
error:
|
||||||
|
qemuMonitorTestFree(test);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define QEMU_JSON_GREETING "{\"QMP\":"\
|
||||||
|
" {\"version\":"\
|
||||||
|
" {\"qemu\":"\
|
||||||
|
" {\"micro\": 1,"\
|
||||||
|
" \"minor\": 0,"\
|
||||||
|
" \"major\": 1"\
|
||||||
|
" },"\
|
||||||
|
" \"package\": \"(qemu-kvm-1.0.1)"\
|
||||||
|
" \"},"\
|
||||||
|
" \"capabilities\": []"\
|
||||||
|
" }"\
|
||||||
|
"}"
|
||||||
|
/* We skip the normal handshake reply of "{\"execute\":\"qmp_capabilities\"}" */
|
||||||
|
|
||||||
|
#define QEMU_TEXT_GREETING "QEMU 1.0,1 monitor - type 'help' for more information"
|
||||||
|
|
||||||
|
qemuMonitorTestPtr
|
||||||
|
qemuMonitorTestNew(bool json, virDomainXMLOptionPtr xmlopt)
|
||||||
|
{
|
||||||
|
qemuMonitorTestPtr test = NULL;
|
||||||
|
virDomainChrSourceDef src;
|
||||||
|
|
||||||
|
if (!(test = qemuMonitorCommonTestNew(xmlopt, &src)))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
test->json = json;
|
||||||
|
if (!(test->mon = qemuMonitorOpen(test->vm,
|
||||||
|
&src,
|
||||||
|
json,
|
||||||
|
&qemuCallbacks)))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
virObjectLock(test->mon);
|
||||||
|
|
||||||
|
if (qemuMonitorTestAddReponse(test, json ?
|
||||||
|
QEMU_JSON_GREETING :
|
||||||
|
QEMU_TEXT_GREETING) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (qemuMonitorCommonTestInit(test) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
virDomainChrSourceDefClear(&src);
|
||||||
|
|
||||||
return test;
|
return test;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
VIR_FREE(tmpdir_template);
|
|
||||||
qemuMonitorTestFree(test);
|
qemuMonitorTestFree(test);
|
||||||
test = NULL;
|
return NULL;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user