[PATCH 4/5] qemu: add test for qemuAgentGetFSInfo

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

 



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@xxxxxxx>
---
 tests/Makefile.am                        |    1 
 tests/qemuagentdata/qemuagent-fsinfo.xml |   27 +++++++
 tests/qemuagenttest.c                    |  118 ++++++++++++++++++++++++++++++
 3 files changed, 146 insertions(+)
 create mode 100644 tests/qemuagentdata/qemuagent-fsinfo.xml

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 293611b..e3fbb66 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -102,6 +102,7 @@ EXTRA_DIST =		\
 	nwfilterxml2xmlin \
 	nwfilterxml2xmlout \
 	oomtrace.pl \
+	qemuagentdata \
 	qemucapabilitiesdata \
 	qemucaps2xmldata \
 	qemuhelpdata \
diff --git a/tests/qemuagentdata/qemuagent-fsinfo.xml b/tests/qemuagentdata/qemuagent-fsinfo.xml
new file mode 100644
index 0000000..beae1f3
--- /dev/null
+++ b/tests/qemuagentdata/qemuagent-fsinfo.xml
@@ -0,0 +1,27 @@
+<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>
+    <controller type='ide' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+    </controller>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c
index bc649b4..f8ea1d5 100644
--- a/tests/qemuagenttest.c
+++ b/tests/qemuagenttest.c
@@ -164,6 +164,123 @@ 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, *i;
+    int ret = -1;
+
+    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\": \"sdb1\","
+                               "   \"mountpoint\": \"/mnt/disk\","
+                               "   \"disk\": [], \"type\": \"xfs\"}]}") < 0)
+        goto cleanup;
+
+    if ((ret = qemuAgentGetFSInfo(qemuMonitorTestGetAgent(test),
+                                  &info, def)) < 0)
+        goto cleanup;
+
+    if (ret != 2) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "expected 2 filesystems information, got %d", ret);
+        ret = -1;
+        goto cleanup;
+    }
+    if (STRNEQ(info[1]->name, "sda1") ||
+        STRNEQ(info[1]->mountpoint, "/") ||
+        STRNEQ(info[1]->type, "ext4") ||
+        !info[1]->devAlias || !info[1]->devAlias[0] || info[1]->devAlias[1] ||
+        STRNEQ(info[1]->devAlias[0], "hdc")) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+            "unexpected filesystems information returned for sda1 (%s,%s)",
+            info[1]->name, info[1]->devAlias ? info[1]->devAlias[0] : "null");
+        ret = -1;
+        goto cleanup;
+    }
+    if (STRNEQ(info[0]->name, "sdb1") ||
+        STRNEQ(info[0]->mountpoint, "/mnt/disk") ||
+        STRNEQ(info[0]->type, "xfs") ||
+        (info[0]->devAlias && info[0]->devAlias[0])) {
+        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;
+    }
+
+    for (i = info; i && *i; i++)
+        virDomainFSInfoFree(*i);
+    VIR_FREE(info);
+
+    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 = info; i && *i; i++)
+        virDomainFSInfoFree(*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)
 {
     virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
@@ -605,6 +722,7 @@ mymain(void)
     DO_TEST(FSFreeze);
     DO_TEST(FSThaw);
     DO_TEST(FSTrim);
+    DO_TEST(GetFSInfo);
     DO_TEST(Suspend);
     DO_TEST(Shutdown);
     DO_TEST(CPU);

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




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