From nobody Mon Feb 9 16:45:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=126.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1628474838907794.0410833456081; Sun, 8 Aug 2021 19:07:18 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-66-ufzqtmEKOtChO_2CXu7saw-1; Sun, 08 Aug 2021 22:07:15 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 80226801FCD; Mon, 9 Aug 2021 02:07:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4025460C81; Mon, 9 Aug 2021 02:07:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3840B4A7CA; Mon, 9 Aug 2021 02:07:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17926E9T010514 for ; Sun, 8 Aug 2021 22:06:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9765E10087DD; Mon, 9 Aug 2021 02:06:14 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 92A59110FBFC for ; Mon, 9 Aug 2021 02:06:13 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 90D43800260 for ; Mon, 9 Aug 2021 02:06:13 +0000 (UTC) Received: from m15113.mail.126.com (m15113.mail.126.com [220.181.15.113]) by relay.mimecast.com with ESMTP id us-mta-43-CpS2JtKLOGOBjRb7Nu2xTA-1; Sun, 08 Aug 2021 22:06:10 -0400 Received: from zhangjl0200.home.langchao.com (unknown [223.104.194.187]) by smtp3 (Coremail) with SMTP id DcmowAAnd8OMjRBhXsB1Tw--.2037S4; Mon, 09 Aug 2021 10:06:07 +0800 (CST) X-MC-Unique: ufzqtmEKOtChO_2CXu7saw-1 X-MC-Unique: CpS2JtKLOGOBjRb7Nu2xTA-1 From: zhangjl02 To: libvir-list@redhat.com Subject: [PATCH 2/2] tests: add test on virNetDevOpenvswitchInterfaceSetQos and virNetDevOpenvswitchInterfaceClearQos Date: Mon, 9 Aug 2021 10:06:00 +0800 Message-Id: <20210809020600.647-3-jx8zjs@126.com> In-Reply-To: <20210809020600.647-1-jx8zjs@126.com> References: <20210809020600.647-1-jx8zjs@126.com> MIME-Version: 1.0 X-CM-TRANSID: DcmowAAnd8OMjRBhXsB1Tw--.2037S4 X-Coremail-Antispam: 1Uf129KBjvJXoW3Jr4kuFW3JF43KF1rXrW5Jrb_yoW3Ww1DpF sxG3Z0kr48Jr1xK3y7ur1rGrWUGr10kF48Ga4xW3y5trn8Jryaqw17Ka1IkanIyr4fX3s5 Xa15JFWqkw17taDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2FALUUUUU= X-Originating-IP: [223.104.194.187] X-CM-SenderInfo: dm0y6ybv6rjloofrz/1tbiIQ-pSFpECDD+VAAAsD X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: shenjiatong@inspur.com, zhangjl02@inspur.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1628474841630100002 Content-Type: text/plain; charset="utf-8" From: Jinsheng Zhang Test virNetDevOpenvswitchInterfaceSetQos and virNetDevOpenvswitchInterfaceC= learQos with dryrun method. Signed-off-by: zhangjl02 --- tests/virnetdevopenvswitchtest.c | 196 ++++++++++++++++++++++++++++++- 1 file changed, 195 insertions(+), 1 deletion(-) diff --git a/tests/virnetdevopenvswitchtest.c b/tests/virnetdevopenvswitcht= est.c index 46172dae90..d1bcca637a 100644 --- a/tests/virnetdevopenvswitchtest.c +++ b/tests/virnetdevopenvswitchtest.c @@ -19,7 +19,11 @@ #include =20 #include "testutils.h" +#define LIBVIRT_VIRCOMMANDPRIV_H_ALLOW +#include "vircommandpriv.h" +#include "virnetdevbandwidth.h" #include "virnetdevopenvswitch.h" +#include "netdev_bandwidth_conf.c" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 @@ -29,6 +33,43 @@ struct _InterfaceParseStatsData { const virDomainInterfaceStatsStruct stats; }; =20 +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 =3D NULL; \ + \ + if (!xml) \ + break; \ + \ + if (!(doc =3D virXMLParseStringCtxt((xml), \ + "bandwidth definition", \ + &ctxt))) \ + goto cleanup; \ + \ + rc =3D 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] =3D "fakeuuid"; =20 static int testInterfaceParseStats(const void *opaque) @@ -111,6 +152,80 @@ testNameEscape(const void *opaque) } =20 =20 +static int +testVirNetDevOpenvswitchInterfaceSetQos(const void *data) +{ + int ret =3D -1; + const struct testSetQosStruct *info =3D data; + const char *iface =3D info->iface; + g_autoptr(virNetDevBandwidth) band =3D NULL; + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + char *actual_cmd =3D NULL; + g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDryRunToken= New(); + + PARSE(info->band, band); + + if (!iface) + iface =3D "tap-fake"; + + virCommandSetDryRun(dryRunToken, &buf, false, false, NULL, NULL); + + if (virNetDevOpenvswitchInterfaceSetQos(iface, band, vm_id, true) < 0) + goto cleanup; + + if (!(actual_cmd =3D 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 =3D 0; + cleanup: + VIR_FREE(actual_cmd); + return ret; +} + + +static int +testVirNetDevOpenvswitchInterfaceClearQos(const void *data) +{ + int ret =3D -1; + const struct testClearQosStruct *info =3D data; + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + char *actual_cmd =3D NULL; + const char *iface =3D info->iface; + const unsigned char *vmid =3D info->vmid; + g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDryRunToken= New(); + + virCommandSetDryRun(dryRunToken, &buf, false, false, NULL, NULL); + + if (virNetDevOpenvswitchInterfaceClearQos(iface, vmid) < 0) + goto cleanup; + + if (!(actual_cmd =3D 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 =3D 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); =20 +#define DO_TEST_SET(Band, Exp_cmd, ...) \ + do { \ + struct testSetQosStruct data =3D {.band =3D Band, \ + .exp_cmd =3D Exp_cmd, \ + __VA_ARGS__}; \ + if (virTestRun("virNetDevOpenvswitchInterfaceSetQos", \ + testVirNetDevOpenvswitchInterfaceSetQos, \ + &data) < 0) \ + ret =3D -1; \ + } while (0) + + DO_TEST_SET(("" + " " + ""), + (OVS_VSCTL " --timeout=3D5 --no-heading --columns=3D_uuid = find queue" + " 'external-ids:vm-id=3D\"66616b65-7575-6964-00= 00-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'\n" + OVS_VSCTL " --timeout=3D5 --no-heading --columns=3D_uuid = find qos" + " 'external-ids:vm-id=3D\"66616b65-7575-6964-00= 00-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'\n" + OVS_VSCTL " --timeout=3D5 set port tap-fake qos=3D@qos1" + " 'external-ids:vm-id=3D\"66616b65-7575-6964-00= 00-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'" + " -- --id=3D@qos1 create qos type=3Dlinux-htb o= ther_config:min-rate=3D163840000" + " queues:0=3D@queue0 'external-ids:vm-id=3D\"66= 616b65-7575-6964-0000-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'" + " -- --id=3D@queue0 create queue other_config:m= in-rate=3D163840000 " + "'external-ids:vm-id=3D\"66616b65-7575-6964-000= 0-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'\n" + OVS_VSCTL " --timeout=3D5 set Interface tap-fake ingress_= policing_rate=3D0 ingress_policing_burst=3D0\n")); + + DO_TEST_SET(NULL, NULL); + + DO_TEST_SET("", NULL); + + DO_TEST_SET(("" + " " + ""), + (OVS_VSCTL " --timeout=3D5 --no-heading --columns=3D_uuid = find qos" + " 'external-ids:vm-id=3D\"66616b65-7575-6964-00= 00-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'\n" + OVS_VSCTL " --timeout=3D5 --no-heading --columns=3D_uuid = find queue" + " 'external-ids:vm-id=3D\"66616b65-7575-6964-00= 00-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'\n" + OVS_VSCTL " --timeout=3D5 set Interface tap-fake ingress_= policing_rate=3D0 ingress_policing_burst=3D0\n")); + + DO_TEST_SET(("" + " " + " " + ""), + (OVS_VSCTL " --timeout=3D5 --no-heading --columns=3D_uuid = find qos" + " 'external-ids:vm-id=3D\"66616b65-7575-6964-00= 00-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'\n" + OVS_VSCTL " --timeout=3D5 --no-heading --columns=3D_uuid = find queue" + " 'external-ids:vm-id=3D\"66616b65-7575-6964-00= 00-000000000000\"'" + " 'external-ids:ifname=3D\"tap-fake\"'\n" + OVS_VSCTL " --timeout=3D5 set Interface tap-fake ingress_= policing_rate=3D40000\n")); + +#define DO_TEST_CLEAR_QOS(Iface, Vmid, Exp_cmd, ...) \ + do { \ + struct testClearQosStruct data =3D {.iface =3D Iface, \ + .vmid =3D Vmid, \ + .exp_cmd =3D Exp_cmd, \ + __VA_ARGS__}; \ + if (virTestRun("virNetDevOpenvswitchInterfaceClearQos", \ + testVirNetDevOpenvswitchInterfaceClearQos, \ + &data) < 0) \ + ret =3D -1; \ + } while (0) + + DO_TEST_CLEAR_QOS(("fake-iface"), vm_id, + (OVS_VSCTL " --timeout=3D5 --no-heading --columns=3D= _uuid find qos" + " 'external-ids:vm-id=3D\"66616b65-7575-6= 964-0000-000000000000\"'" + " 'external-ids:ifname=3D\"fake-iface\"'\= n" + OVS_VSCTL " --timeout=3D5 --no-heading --columns=3D= _uuid find queue" + " 'external-ids:vm-id=3D\"66616b65-7575-6= 964-0000-000000000000\"'" + " 'external-ids:ifname=3D\"fake-iface\"'\= n" + OVS_VSCTL " --timeout=3D5 set Interface fake-iface = ingress_policing_rate=3D0 ingress_policing_burst=3D0\n")); + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 -VIR_TEST_MAIN(mymain); +VIR_TEST_MAIN_PRELOAD(mymain, VIR_TEST_MOCK("virnetdevbandwidth")) --=20 2.30.2.windows.1