[PATCH 2/2] tests: add test on virNetDevOpenvswitchInterfaceSetQos and virNetDevOpenvswitchInterfaceClearQos

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

 



From: Jinsheng Zhang <zhangjl02@xxxxxxxxxx>

Test virNetDevOpenvswitchInterfaceSetQos and virNetDevOpenvswitchInterfaceClearQos with dryrun method.

Signed-off-by: zhangjl02 <zhangjl02@xxxxxxxxxx>
---
 tests/virnetdevopenvswitchtest.c | 196 ++++++++++++++++++++++++++++++-
 1 file changed, 195 insertions(+), 1 deletion(-)

diff --git a/tests/virnetdevopenvswitchtest.c b/tests/virnetdevopenvswitchtest.c
index 46172dae90..d1bcca637a 100644
--- a/tests/virnetdevopenvswitchtest.c
+++ b/tests/virnetdevopenvswitchtest.c
@@ -19,7 +19,11 @@
 #include <config.h>
 
 #include "testutils.h"
+#define LIBVIRT_VIRCOMMANDPRIV_H_ALLOW
+#include "vircommandpriv.h"
+#include "virnetdevbandwidth.h"
 #include "virnetdevopenvswitch.h"
+#include "netdev_bandwidth_conf.c"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
@@ -29,6 +33,43 @@ struct _InterfaceParseStatsData {
     const virDomainInterfaceStatsStruct stats;
 };
 
+struct testSetQosStruct {
+    const char *band;
+    const char *exp_cmd;
+    const char *iface;
+};
+
+struct testClearQosStruct {
+    const char *exp_cmd;
+    const char *iface;
+    const unsigned char *vmid;
+};
+
+#define PARSE(xml, var) \
+    do { \
+        int rc; \
+        xmlDocPtr doc; \
+        xmlXPathContextPtr ctxt = NULL; \
+ \
+        if (!xml) \
+            break; \
+ \
+        if (!(doc = virXMLParseStringCtxt((xml), \
+                                          "bandwidth definition", \
+                                          &ctxt))) \
+            goto cleanup; \
+ \
+        rc = virNetDevBandwidthParse(&(var), \
+                                     NULL, \
+                                     ctxt->node, \
+                                     true); \
+        xmlFreeDoc(doc); \
+        xmlXPathFreeContext(ctxt); \
+        if (rc < 0) \
+            goto cleanup; \
+    } while (0)
+
+static const unsigned char vm_id[VIR_UUID_BUFLEN] = "fakeuuid";
 
 static int
 testInterfaceParseStats(const void *opaque)
@@ -111,6 +152,80 @@ testNameEscape(const void *opaque)
 }
 
 
+static int
+testVirNetDevOpenvswitchInterfaceSetQos(const void *data)
+{
+    int ret = -1;
+    const struct testSetQosStruct *info = data;
+    const char *iface = info->iface;
+    g_autoptr(virNetDevBandwidth) band = NULL;
+    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+    char *actual_cmd = NULL;
+    g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
+
+    PARSE(info->band, band);
+
+    if (!iface)
+        iface = "tap-fake";
+
+    virCommandSetDryRun(dryRunToken, &buf, false, false, NULL, NULL);
+
+    if (virNetDevOpenvswitchInterfaceSetQos(iface, band, vm_id, true) < 0)
+        goto cleanup;
+
+    if (!(actual_cmd = virBufferContentAndReset(&buf))) {
+        /* This is interesting, no command has been executed.
+         * Maybe that's expected, actually. */
+    }
+
+    if (STRNEQ_NULLABLE(info->exp_cmd, actual_cmd)) {
+        virTestDifference(stderr,
+                          NULLSTR(info->exp_cmd),
+                          NULLSTR(actual_cmd));
+        goto cleanup;
+    }
+
+    ret = 0;
+    cleanup:
+    VIR_FREE(actual_cmd);
+    return ret;
+}
+
+
+static int
+testVirNetDevOpenvswitchInterfaceClearQos(const void *data)
+{
+    int ret = -1;
+    const struct testClearQosStruct *info = data;
+    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+    char *actual_cmd = NULL;
+    const char *iface = info->iface;
+    const unsigned char *vmid = info->vmid;
+    g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
+
+    virCommandSetDryRun(dryRunToken, &buf, false, false, NULL, NULL);
+
+    if (virNetDevOpenvswitchInterfaceClearQos(iface, vmid) < 0)
+        goto cleanup;
+
+    if (!(actual_cmd = virBufferContentAndReset(&buf))) {
+        /* This is interesting, no command has been executed.
+         * Maybe that's expected, actually. */
+    }
+
+    if (STRNEQ_NULLABLE(info->exp_cmd, actual_cmd)) {
+        virTestDifference(stderr,
+                          NULLSTR(info->exp_cmd),
+                          NULLSTR(actual_cmd));
+        goto cleanup;
+    }
+
+    ret = 0;
+    cleanup:
+    VIR_FREE(actual_cmd);
+    return ret;
+}
+
 static int
 mymain(void)
 {
@@ -146,7 +261,86 @@ mymain(void)
     TEST_NAME_ESCAPE("\"vhost\"user1\"", NULL);
     TEST_NAME_ESCAPE("\"\\\\", NULL);
 
+#define DO_TEST_SET(Band, Exp_cmd, ...) \
+    do { \
+        struct testSetQosStruct data = {.band = Band, \
+                                     .exp_cmd = Exp_cmd, \
+                                     __VA_ARGS__}; \
+        if (virTestRun("virNetDevOpenvswitchInterfaceSetQos", \
+                       testVirNetDevOpenvswitchInterfaceSetQos, \
+                       &data) < 0) \
+            ret = -1; \
+    } while (0)
+
+    DO_TEST_SET(("<bandwidth>"
+                 "  <inbound average='20000'/>"
+                 "</bandwidth>"),
+                (OVS_VSCTL " --timeout=5 --no-heading --columns=_uuid find queue"
+                           " 'external-ids:vm-id=\"66616b65-7575-6964-0000-000000000000\"'"
+                           " 'external-ids:ifname=\"tap-fake\"'\n"
+                 OVS_VSCTL " --timeout=5 --no-heading --columns=_uuid find qos"
+                           " 'external-ids:vm-id=\"66616b65-7575-6964-0000-000000000000\"'"
+                           " 'external-ids:ifname=\"tap-fake\"'\n"
+                 OVS_VSCTL " --timeout=5 set port tap-fake qos=@qos1"
+                           " 'external-ids:vm-id=\"66616b65-7575-6964-0000-000000000000\"'"
+                           " 'external-ids:ifname=\"tap-fake\"'"
+                           " -- --id=@qos1 create qos type=linux-htb other_config:min-rate=163840000"
+                           " queues:0=@queue0 'external-ids:vm-id=\"66616b65-7575-6964-0000-000000000000\"'"
+                           " 'external-ids:ifname=\"tap-fake\"'"
+                           " -- --id=@queue0 create queue other_config:min-rate=163840000 "
+                           "'external-ids:vm-id=\"66616b65-7575-6964-0000-000000000000\"'"
+                           " 'external-ids:ifname=\"tap-fake\"'\n"
+                 OVS_VSCTL " --timeout=5 set Interface tap-fake ingress_policing_rate=0 ingress_policing_burst=0\n"));
+
+    DO_TEST_SET(NULL, NULL);
+
+    DO_TEST_SET("<bandwidth/>", NULL);
+
+    DO_TEST_SET(("<bandwidth>"
+                 "  <inbound average='0' />"
+                 "</bandwidth>"),
+                (OVS_VSCTL " --timeout=5 --no-heading --columns=_uuid find qos"
+                           " 'external-ids:vm-id=\"66616b65-7575-6964-0000-000000000000\"'"
+                           " 'external-ids:ifname=\"tap-fake\"'\n"
+                 OVS_VSCTL " --timeout=5 --no-heading --columns=_uuid find queue"
+                           " 'external-ids:vm-id=\"66616b65-7575-6964-0000-000000000000\"'"
+                           " 'external-ids:ifname=\"tap-fake\"'\n"
+                 OVS_VSCTL " --timeout=5 set Interface tap-fake ingress_policing_rate=0 ingress_policing_burst=0\n"));
+
+    DO_TEST_SET(("<bandwidth>"
+                 "  <inbound average='0' />"
+                 "  <outbound average='5000' />"
+                 "</bandwidth>"),
+                (OVS_VSCTL " --timeout=5 --no-heading --columns=_uuid find qos"
+                           " 'external-ids:vm-id=\"66616b65-7575-6964-0000-000000000000\"'"
+                           " 'external-ids:ifname=\"tap-fake\"'\n"
+                 OVS_VSCTL " --timeout=5 --no-heading --columns=_uuid find queue"
+                           " 'external-ids:vm-id=\"66616b65-7575-6964-0000-000000000000\"'"
+                           " 'external-ids:ifname=\"tap-fake\"'\n"
+                 OVS_VSCTL " --timeout=5 set Interface tap-fake ingress_policing_rate=40000\n"));
+
+#define DO_TEST_CLEAR_QOS(Iface, Vmid, Exp_cmd, ...) \
+    do { \
+        struct testClearQosStruct data = {.iface = Iface, \
+                                        .vmid = Vmid, \
+                                        .exp_cmd = Exp_cmd, \
+                                        __VA_ARGS__}; \
+        if (virTestRun("virNetDevOpenvswitchInterfaceClearQos", \
+                       testVirNetDevOpenvswitchInterfaceClearQos, \
+                       &data) < 0) \
+            ret = -1; \
+    } while (0)
+
+    DO_TEST_CLEAR_QOS(("fake-iface"), vm_id,
+                      (OVS_VSCTL " --timeout=5 --no-heading --columns=_uuid find qos"
+                                 " 'external-ids:vm-id=\"66616b65-7575-6964-0000-000000000000\"'"
+                                 " 'external-ids:ifname=\"fake-iface\"'\n"
+                       OVS_VSCTL " --timeout=5 --no-heading --columns=_uuid find queue"
+                                 " 'external-ids:vm-id=\"66616b65-7575-6964-0000-000000000000\"'"
+                                 " 'external-ids:ifname=\"fake-iface\"'\n"
+                       OVS_VSCTL " --timeout=5 set Interface fake-iface ingress_policing_rate=0 ingress_policing_burst=0\n"));
+
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-VIR_TEST_MAIN(mymain);
+VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virnetdevbandwidth"))
-- 
2.30.2.windows.1




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

  Powered by Linux