mirror of https://gitee.com/openkylin/libvirt.git
qemu: add test for qemuAgentGetFSInfo
Add test cases for qemuAgentGetFSInfo, with a sample agent response for the qemu-get-fsinfo command and a configuration xml. Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama@hds.com>
This commit is contained in:
parent
5c9cfa4976
commit
733b56a4b9
|
@ -103,6 +103,7 @@ EXTRA_DIST = \
|
|||
nwfilterxml2xmlin \
|
||||
nwfilterxml2xmlout \
|
||||
oomtrace.pl \
|
||||
qemuagentdata \
|
||||
qemucapabilitiesdata \
|
||||
qemucaps2xmldata \
|
||||
qemuhelpdata \
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<domain type='qemu'>
|
||||
<name>QEMUGuest1</name>
|
||||
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
|
||||
<memory unit='KiB'>219136</memory>
|
||||
<currentMemory unit='KiB'>219136</currentMemory>
|
||||
<vcpu placement='static'>1</vcpu>
|
||||
<os>
|
||||
<type arch='i686' machine='pc'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<clock offset='utc'/>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu</emulator>
|
||||
<disk type='file' device='disk'>
|
||||
<source file='/tmp/idedisk.img'/>
|
||||
<target dev='hdc' bus='ide'/>
|
||||
<address type='drive' controller='0' bus='1' target='0' unit='0'/>
|
||||
</disk>
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2'/>
|
||||
<source file='/tmp/virtio-blk1.qcow2'/>
|
||||
<target dev='vda' bus='virtio'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
|
||||
</disk>
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2'/>
|
||||
<source file='/tmp/virtio-blk2.qcow2'/>
|
||||
<target dev='vdb' bus='virtio'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
|
||||
</disk>
|
||||
<controller type='ide' index='0'>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
|
||||
</controller>
|
||||
<memballoon model='virtio'/>
|
||||
</devices>
|
||||
</domain>
|
|
@ -163,6 +163,149 @@ testQemuAgentFSTrim(const void *data)
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
testQemuAgentGetFSInfo(const void *data)
|
||||
{
|
||||
virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
|
||||
virCapsPtr caps = testQemuCapsInit();
|
||||
qemuMonitorTestPtr test = qemuMonitorTestNewAgent(xmlopt);
|
||||
char *domain_filename = NULL;
|
||||
char *domain_xml = NULL;
|
||||
virDomainDefPtr def = NULL;
|
||||
virDomainFSInfoPtr *info = NULL;
|
||||
int ret = -1, ninfo = 0, i;
|
||||
|
||||
if (!test)
|
||||
return -1;
|
||||
|
||||
if (virAsprintf(&domain_filename, "%s/qemuagentdata/qemuagent-fsinfo.xml",
|
||||
abs_srcdir) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virtTestLoadFile(domain_filename, &domain_xml) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(def = virDomainDefParseString(domain_xml, caps, xmlopt,
|
||||
QEMU_EXPECTED_VIRT_TYPES,
|
||||
VIR_DOMAIN_XML_INACTIVE)))
|
||||
goto cleanup;
|
||||
|
||||
if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuMonitorTestAddItem(test, "guest-get-fsinfo",
|
||||
"{\"return\": ["
|
||||
" {\"name\": \"sda1\", \"mountpoint\": \"/\","
|
||||
" \"disk\": ["
|
||||
" {\"bus-type\": \"ide\","
|
||||
" \"bus\": 1, \"unit\": 0,"
|
||||
" \"pci-controller\": {"
|
||||
" \"bus\": 0, \"slot\": 1,"
|
||||
" \"domain\": 0, \"function\": 1},"
|
||||
" \"target\": 0}],"
|
||||
" \"type\": \"ext4\"},"
|
||||
" {\"name\": \"dm-1\","
|
||||
" \"mountpoint\": \"/opt\","
|
||||
" \"disk\": ["
|
||||
" {\"bus-type\": \"virtio\","
|
||||
" \"bus\": 0, \"unit\": 0,"
|
||||
" \"pci-controller\": {"
|
||||
" \"bus\": 0, \"slot\": 6,"
|
||||
" \"domain\": 0, \"function\": 0},"
|
||||
" \"target\": 0},"
|
||||
" {\"bus-type\": \"virtio\","
|
||||
" \"bus\": 0, \"unit\": 0,"
|
||||
" \"pci-controller\": {"
|
||||
" \"bus\": 0, \"slot\": 7,"
|
||||
" \"domain\": 0, \"function\": 0},"
|
||||
" \"target\": 0}],"
|
||||
" \"type\": \"vfat\"},"
|
||||
" {\"name\": \"sdb1\","
|
||||
" \"mountpoint\": \"/mnt/disk\","
|
||||
" \"disk\": [], \"type\": \"xfs\"}]}") < 0)
|
||||
goto cleanup;
|
||||
|
||||
if ((ninfo = qemuAgentGetFSInfo(qemuMonitorTestGetAgent(test),
|
||||
&info, def)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (ninfo != 3) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"expected 3 filesystems information, got %d", ninfo);
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
if (STRNEQ(info[2]->name, "sda1") ||
|
||||
STRNEQ(info[2]->mountpoint, "/") ||
|
||||
STRNEQ(info[2]->fstype, "ext4") ||
|
||||
info[2]->ndevAlias != 1 ||
|
||||
!info[2]->devAlias || !info[2]->devAlias[0] ||
|
||||
STRNEQ(info[2]->devAlias[0], "hdc")) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"unexpected filesystems information returned for sda1 (%s,%s)",
|
||||
info[2]->name, info[2]->devAlias ? info[2]->devAlias[0] : "null");
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
if (STRNEQ(info[1]->name, "dm-1") ||
|
||||
STRNEQ(info[1]->mountpoint, "/opt") ||
|
||||
STRNEQ(info[1]->fstype, "vfat") ||
|
||||
info[1]->ndevAlias != 2 ||
|
||||
!info[1]->devAlias || !info[1]->devAlias[0] || !info[1]->devAlias[1] ||
|
||||
STRNEQ(info[1]->devAlias[0], "vda") ||
|
||||
STRNEQ(info[1]->devAlias[1], "vdb")) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"unexpected filesystems information returned for dm-1 (%s,%s)",
|
||||
info[0]->name, info[0]->devAlias ? info[0]->devAlias[0] : "null");
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
if (STRNEQ(info[0]->name, "sdb1") ||
|
||||
STRNEQ(info[0]->mountpoint, "/mnt/disk") ||
|
||||
STRNEQ(info[0]->fstype, "xfs") ||
|
||||
info[0]->ndevAlias != 0 || info[0]->devAlias) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"unexpected filesystems information returned for sdb1 (%s,%s)",
|
||||
info[0]->name, info[0]->devAlias ? info[0]->devAlias[0] : "null");
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuMonitorTestAddItem(test, "guest-get-fsinfo",
|
||||
"{\"error\":"
|
||||
" {\"class\":\"CommandDisabled\","
|
||||
" \"desc\":\"The command guest-get-fsinfo "
|
||||
"has been disabled for "
|
||||
"this instance\","
|
||||
" \"data\":{\"name\":\"guest-get-fsinfo\"}"
|
||||
" }"
|
||||
"}") < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuAgentGetFSInfo(qemuMonitorTestGetAgent(test), &info, def) != -1) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
"agent get-fsinfo command should have failed");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
for (i = 0; i < ninfo; i++)
|
||||
virDomainFSInfoFree(info[i]);
|
||||
VIR_FREE(info);
|
||||
VIR_FREE(domain_filename);
|
||||
VIR_FREE(domain_xml);
|
||||
virObjectUnref(caps);
|
||||
virDomainDefFree(def);
|
||||
qemuMonitorTestFree(test);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
testQemuAgentSuspend(const void *data)
|
||||
{
|
||||
|
@ -605,6 +748,7 @@ mymain(void)
|
|||
DO_TEST(FSFreeze);
|
||||
DO_TEST(FSThaw);
|
||||
DO_TEST(FSTrim);
|
||||
DO_TEST(GetFSInfo);
|
||||
DO_TEST(Suspend);
|
||||
DO_TEST(Shutdown);
|
||||
DO_TEST(CPU);
|
||||
|
|
Loading…
Reference in New Issue