From nobody Sat May 4 21:32:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525337547154106.09918550602106; Thu, 3 May 2018 01:52:27 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id CBE1130B8FB7; Thu, 3 May 2018 08:52:25 +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 79CAB60F8C; Thu, 3 May 2018 08:52:25 +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 11BE74CAA7; Thu, 3 May 2018 08:52:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w438jMfe032363 for ; Thu, 3 May 2018 04:45:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9AE7F2022AAC; Thu, 3 May 2018 08:45:22 +0000 (UTC) Received: from katerina.brq.redhat.com (unknown [10.34.245.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF3AF2022AA9; Thu, 3 May 2018 08:45:21 +0000 (UTC) From: Katerina Koukiou To: libvir-list@redhat.com Date: Thu, 3 May 2018 10:45:14 +0200 Message-Id: <20180503084519.7421-2-kkoukiou@redhat.com> In-Reply-To: <20180503084519.7421-1-kkoukiou@redhat.com> References: <20180503084519.7421-1-kkoukiou@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [dbus RFC PATCH 1/6] Abandon usage of all *TypeToString functions in domain.c 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 03 May 2018 08:52:26 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Converting ENUMS to str can be user friendly though it can be problematic between libvirt versions. In particular when some translated type will introduce a new constant to the ENUM libvirt-dbus will fail with: size of array =E2=80=98_GStaticAssertCompileTimeAssertion_5=E2=80=99 is neg= ative Since it's not main use case of livirt-dbus API to be invoked interactively by user, having all ENUM types passed as unsigned int is preferable to avoid the previous issue. Signed-off-by: Katerina Koukiou --- data/org.libvirt.Domain.xml | 14 ++-- src/domain.c | 172 ++++------------------------------------= ---- tests/test_domain.py | 6 +- 3 files changed, 25 insertions(+), 167 deletions(-) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index db43b1c..6448a46 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -191,19 +191,19 @@ value=3D"See https://libvirt.org/html/libvirt-libvirt-domain.html#= virDomainGetBlockJobInfo"/> - + - + - + - + - + @@ -319,7 +319,7 @@ - + @@ -492,7 +492,7 @@ - + diff --git a/src/domain.c b/src/domain.c index e305fa3..40cf2f7 100644 --- a/src/domain.c +++ b/src/domain.c @@ -3,75 +3,6 @@ =20 #include =20 -VIRT_DBUS_ENUM_DECL(virtDBusDomainBlockJob) -VIRT_DBUS_ENUM_IMPL(virtDBusDomainBlockJob, - VIR_DOMAIN_BLOCK_JOB_TYPE_LAST, - "unknown", - "pull", - "copy", - "commit", - "active-commit") - -VIRT_DBUS_ENUM_DECL(virtDBusDomainControlErrorReason) -VIRT_DBUS_ENUM_IMPL(virtDBusDomainControlErrorReason, - VIR_DOMAIN_CONTROL_ERROR_REASON_LAST, - "none", - "unknown", - "monitor", - "internal") - -VIRT_DBUS_ENUM_DECL(virtDBusDomainControlState) -VIRT_DBUS_ENUM_IMPL(virtDBusDomainControlState, - VIR_DOMAIN_CONTROL_LAST, - "ok", - "job", - "occupied", - "error") - -VIRT_DBUS_ENUM_DECL(virtDBusDomainDiskError) -VIRT_DBUS_ENUM_IMPL(virtDBusDomainDiskError, - VIR_DOMAIN_DISK_ERROR_LAST, - "none", - "unspec", - "no-space") - -VIRT_DBUS_ENUM_DECL(virtDBusDomainInterfaceAddressesSource) -VIRT_DBUS_ENUM_IMPL(virtDBusDomainInterfaceAddressesSource, - VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LAST, - "lease", - "agent") - -VIRT_DBUS_ENUM_DECL(virtDBusDomainJob) -VIRT_DBUS_ENUM_IMPL(virtDBusDomainJob, - VIR_DOMAIN_JOB_LAST, - "none", - "bounded", - "unbounded", - "completed", - "failed", - "canceled") - -VIRT_DBUS_ENUM_DECL(virtDBusDomainMemoryStat) -VIRT_DBUS_ENUM_IMPL(virtDBusDomainMemoryStat, - VIR_DOMAIN_MEMORY_STAT_LAST, - "swap_in", - "swap_out", - "major_fault", - "minor_fault", - "unused", - "available", - "actual_baloon", - "rss", - "usable", - "last_update") - -VIRT_DBUS_ENUM_DECL(virtDBusDomainMetadata) -VIRT_DBUS_ENUM_IMPL(virtDBusDomainMetadata, - VIR_DOMAIN_METADATA_LAST, - "description", - "title", - "element") - struct _virtDBusDomainFSInfoList { virDomainFSInfoPtr *info; gint count; @@ -137,12 +68,8 @@ virtDBusDomainMemoryStatsToGVariant(virDomainMemoryStat= Ptr stats, =20 g_variant_builder_init(&builder, G_VARIANT_TYPE("a{st}")); =20 - for (gint i =3D 0; i < nr_stats; i++) { - const gchar *memoryStat =3D virtDBusDomainMemoryStatTypeToString(s= tats[i].tag); - if (!memoryStat) - continue; - g_variant_builder_add(&builder, "{st}", memoryStat, stats[i].val); - } + for (gint i =3D 0; i < nr_stats; i++) + g_variant_builder_add(&builder, "{ut}", stats[i].tag, stats[i].val= ); =20 return g_variant_builder_end(&builder); } @@ -1032,7 +959,6 @@ virtDBusDomainGetBlockJobInfo(GVariant *inArgs, virDomainBlockJobInfo info; const gchar *disk; guint flags; - const gchar *blockJobTypeStr; =20 g_variant_get(inArgs, "(&su)", &disk, &flags); =20 @@ -1043,15 +969,7 @@ virtDBusDomainGetBlockJobInfo(GVariant *inArgs, if (virDomainGetBlockJobInfo(domain, disk, &info, flags) < 0) return virtDBusUtilSetLastVirtError(error); =20 - blockJobTypeStr =3D virtDBusDomainBlockJobTypeToString(info.type); - if (!blockJobTypeStr) { - g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT, - "Can't format virDomainBlockJobType '%d' to string.", - info.type); - return; - } - - *outArgs =3D g_variant_new("((sttt))", blockJobTypeStr, info.bandwidth, + *outArgs =3D g_variant_new("((uttt))", info.type, info.bandwidth, info.cur, info.end); } =20 @@ -1067,8 +985,6 @@ virtDBusDomainGetControlInfo(GVariant *inArgs, virtDBusConnect *connect =3D userData; g_autoptr(virDomain) domain =3D NULL; g_autofree virDomainControlInfoPtr controlInfo =3D NULL; - const gchar *stateStr; - const gchar *errorReasonStr; guint flags; =20 g_variant_get(inArgs, "(u)", &flags); @@ -1081,23 +997,8 @@ virtDBusDomainGetControlInfo(GVariant *inArgs, if (virDomainGetControlInfo(domain, controlInfo, flags) < 0) return virtDBusUtilSetLastVirtError(error); =20 - stateStr =3D virtDBusDomainControlStateTypeToString(controlInfo->state= ); - if (!stateStr) { - g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT, - "Can't format virDomainControlState '%d' to string.", - controlInfo->state); - return; - } - errorReasonStr =3D virtDBusDomainControlErrorReasonTypeToString(contro= lInfo->details); - if (!errorReasonStr) { - g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT, - "Can't format virDomainControlErrorReason '%d' to stri= ng.", - controlInfo->details); - return; - } - - *outArgs =3D g_variant_new("((sst))", stateStr, - errorReasonStr, controlInfo->stateTime); + *outArgs =3D g_variant_new("((uut))", controlInfo->state, + controlInfo->details, controlInfo->stateTime); } =20 static void @@ -1137,15 +1038,11 @@ virtDBusDomainGetDiskErrors(GVariant *inArgs, return virtDBusUtilSetLastVirtError(error); } =20 - g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ss)")); + g_variant_builder_init(&builder, G_VARIANT_TYPE("a(su)")); for (gint i =3D 0; i < count; i++) { - const gchar *err =3D virtDBusDomainDiskErrorTypeToString(disks[i].= error); - - if (!err) - continue; - g_variant_builder_open(&builder, G_VARIANT_TYPE("(ss)")); + g_variant_builder_open(&builder, G_VARIANT_TYPE("(su)")); g_variant_builder_add(&builder, "s", disks[i].disk); - g_variant_builder_add(&builder, "s", err); + g_variant_builder_add(&builder, "u", disks[i].error); g_variant_builder_close(&builder); } res =3D g_variant_builder_end(&builder); @@ -1355,7 +1252,6 @@ virtDBusDomainGetJobInfo(GVariant *inArgs G_GNUC_UNUS= ED, virtDBusConnect *connect =3D userData; g_autoptr(virDomain) domain =3D NULL; g_autofree virDomainJobInfoPtr jobInfo =3D NULL; - const gchar *jobTypeStr; =20 domain =3D virtDBusDomainGetVirDomain(connect, objectPath, error); if (!domain) @@ -1365,13 +1261,7 @@ virtDBusDomainGetJobInfo(GVariant *inArgs G_GNUC_UNU= SED, if (virDomainGetJobInfo(domain, jobInfo) < 0) return virtDBusUtilSetLastVirtError(error); =20 - jobTypeStr =3D virtDBusDomainJobTypeToString(jobInfo->type); - if (!jobTypeStr) { - g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT, - "Can't format virDomainJobType '%d' to string.", jobIn= fo->type); - return; - } - *outArgs =3D g_variant_new("((sttttttttttt))", jobTypeStr, + *outArgs =3D g_variant_new("((uttttttttttt))", jobInfo->type, jobInfo->timeElapsed, jobInfo->timeRemaining, jobInfo->dataTotal, jobInfo->dataProcessed, jobInfo->dataRemaining, jobInfo->memTotal, @@ -1393,7 +1283,6 @@ virtDBusDomainGetJobStats(GVariant *inArgs, g_autoptr(virDomain) domain =3D NULL; g_auto(virtDBusUtilTypedParams) params =3D { 0 }; guint flags; - const gchar *typeStr; gint type; GVariant *grecords; GVariantBuilder builder; @@ -1412,15 +1301,8 @@ virtDBusDomainGetJobStats(GVariant *inArgs, =20 grecords =3D virtDBusUtilTypedParamsToGVariant(params.params, params.n= params); =20 - typeStr =3D virtDBusDomainJobTypeToString(type); - if (!typeStr) { - g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT, - "Can't format virDomainJobType '%d' to string.", type); - return; - } - - g_variant_builder_init(&builder, G_VARIANT_TYPE("(sa{sv})")); - g_variant_builder_add(&builder, "s", typeStr); + g_variant_builder_init(&builder, G_VARIANT_TYPE("(ua{sv})")); + g_variant_builder_add(&builder, "u", type); g_variant_builder_add_value(&builder, grecords); gret =3D g_variant_builder_end(&builder); =20 @@ -1474,13 +1356,12 @@ virtDBusDomainGetMetadata(GVariant *inArgs, { virtDBusConnect *connect =3D userData; g_autoptr(virDomain) domain =3D NULL; - const gchar *typeStr; gint type; const gchar *uri; guint flags; g_autofree gchar *ret =3D NULL; =20 - g_variant_get(inArgs, "(&s&su)", &typeStr, &uri, &flags); + g_variant_get(inArgs, "(u&su)", &type, &uri, &flags); if (g_str_equal(uri, "")) uri =3D NULL; =20 @@ -1488,14 +1369,6 @@ virtDBusDomainGetMetadata(GVariant *inArgs, if (!domain) return; =20 - type =3D virtDBusDomainMetadataTypeFromString(typeStr); - if (type < 0) { - g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT, - "Can't get valid virDomainMetadataType from string '%s= '.", - typeStr); - return; - } - ret =3D virDomainGetMetadata(domain, type, uri, flags); if (!ret) return virtDBusUtilSetLastVirtError(error); @@ -1787,25 +1660,17 @@ virtDBusDomainInterfaceAddresses(GVariant *inArgs, virtDBusConnect *connect =3D userData; g_autoptr(virDomain) domain =3D NULL; gint source; - const gchar *sourceStr; g_auto(virtDBusDomainInterfaceList) ifaces =3D { 0 }; guint flags; GVariantBuilder builder; GVariant *res; =20 - g_variant_get(inArgs, "(&su)", &sourceStr, &flags); + g_variant_get(inArgs, "(uu)", &source, &flags); =20 domain =3D virtDBusDomainGetVirDomain(connect, objectPath, error); if (!domain) return; =20 - source =3D virtDBusDomainInterfaceAddressesSourceTypeFromString(source= Str); - if (source < 0) { - g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT, - "Can't get valid virDomainInterfaceAddressesSource fro= m string '%s'.", - sourceStr); - return; - } ifaces.count =3D virDomainInterfaceAddresses(domain, &(ifaces.ifaces), source, flags); if (ifaces.count < 0) @@ -2617,14 +2482,13 @@ virtDBusDomainSetMetadata(GVariant *inArgs, { virtDBusConnect *connect =3D userData; g_autoptr(virDomain) domain =3D NULL; - const gchar *typeStr; gint type; const gchar *metadata; const gchar *key; const gchar *uri; guint flags; =20 - g_variant_get(inArgs, "(&s&s&s&su)", &typeStr, &metadata, &key, &uri, = &flags); + g_variant_get(inArgs, "(u&s&s&su)", &type, &metadata, &key, &uri, &fla= gs); if (g_str_equal(key, "")) key =3D NULL; if (g_str_equal(uri, "")) @@ -2634,14 +2498,6 @@ virtDBusDomainSetMetadata(GVariant *inArgs, if (!domain) return; =20 - type =3D virtDBusDomainMetadataTypeFromString(typeStr); - if (type < 0) { - g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT, - "Can't get valid virDomainMetadataType from string '%s= '.", - typeStr); - return; - } - if (virDomainSetMetadata(domain, type, metadata, key, uri, flags) < 0) virtDBusUtilSetLastVirtError(error); } diff --git a/tests/test_domain.py b/tests/test_domain.py index d0cebcd..0e83f72 100755 --- a/tests/test_domain.py +++ b/tests/test_domain.py @@ -64,10 +64,12 @@ class TestDomain(libvirttest.BaseTestClass): self.main_loop() =20 def test_domain_metadata(self): + metadata_description =3D 0 obj, domain =3D self.domain() description_expected =3D "This is the Test domain" - domain.SetMetadata('description', description_expected, "", "", 0) - assert description_expected =3D=3D domain.GetMetadata('description= ', "", 0) + domain.SetMetadata(metadata_description, + description_expected, "", "", 0) + assert description_expected =3D=3D domain.GetMetadata(metadata_des= cription, "", 0) =20 def test_resume(self): def domain_resumed(path, _event): --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 21:32:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525337145567764.461183737548; Thu, 3 May 2018 01:45:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CAB1528209; Thu, 3 May 2018 08:45:43 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8F43460175; Thu, 3 May 2018 08:45:43 +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 A5AB51806104; Thu, 3 May 2018 08:45:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w438jNJh032373 for ; Thu, 3 May 2018 04:45:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6035E2022AAA; Thu, 3 May 2018 08:45:23 +0000 (UTC) Received: from katerina.brq.redhat.com (unknown [10.34.245.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id D85672022AA9; Thu, 3 May 2018 08:45:22 +0000 (UTC) From: Katerina Koukiou To: libvir-list@redhat.com Date: Thu, 3 May 2018 10:45:15 +0200 Message-Id: <20180503084519.7421-3-kkoukiou@redhat.com> In-Reply-To: <20180503084519.7421-1-kkoukiou@redhat.com> References: <20180503084519.7421-1-kkoukiou@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [dbus RFC PATCH 2/6] Abandon usage of all *TypeToString functions in connect.c 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 03 May 2018 08:45:44 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Converting ENUMS to str can be user friendly though it can be problematic between libvirt versions. In particular when some translated type will introduce a new constant to the ENUM libvirt-dbus will fail with: size of array =E2=80=98_GStaticAssertCompileTimeAssertion_5=E2=80=99 is neg= ative Since it's not main use case of livirt-dbus API to be invoked interactively by user, having all ENUM types passed as unsigned int is preferable to avoid the previous issue. Signed-off-by: Katerina Koukiou --- data/org.libvirt.Connect.xml | 2 +- src/connect.c | 18 +----------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index ee7bfdc..7249fa4 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -37,7 +37,7 @@ value=3D"See https://libvirt.org/html/libvirt-libvirt-host.html#vi= rConnectCompareCPU"/> - + =20 -VIRT_DBUS_ENUM_DECL(virtDBusConnectCPUCompareResult) -VIRT_DBUS_ENUM_IMPL(virtDBusConnectCPUCompareResult, - VIR_CPU_COMPARE_LAST, - "incompatible", - "identical", - "superset") - static gint virtDBusConnectCredType[] =3D { VIR_CRED_AUTHNAME, VIR_CRED_ECHOPROMPT, @@ -263,7 +256,6 @@ virtDBusConnectCompareCPU(GVariant *inArgs, const gchar *xmlDesc; guint flags; gint compareResult; - const gchar* compareResultStr; =20 g_variant_get(inArgs, "(&su)", &xmlDesc, &flags); =20 @@ -274,15 +266,7 @@ virtDBusConnectCompareCPU(GVariant *inArgs, if (compareResult < 0) return virtDBusUtilSetLastVirtError(error); =20 - compareResultStr =3D virtDBusConnectCPUCompareResultTypeToString(compa= reResult); - if (!compareResultStr) { - g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT, - "Can't format virCPUCompareResult '%d' to string.", - compareResult); - return; - } - - *outArgs =3D g_variant_new("(s)", compareResultStr); + *outArgs =3D g_variant_new("(u)", compareResult); } =20 static void --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 21:32:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525337553130476.6034795679898; Thu, 3 May 2018 01:52:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C214019CBCD; Thu, 3 May 2018 08:52:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 829E710016DC; Thu, 3 May 2018 08:52:31 +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 24C29180BAD5; Thu, 3 May 2018 08:52:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w438jOcp032378 for ; Thu, 3 May 2018 04:45:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 293922022AAA; Thu, 3 May 2018 08:45:24 +0000 (UTC) Received: from katerina.brq.redhat.com (unknown [10.34.245.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id A05912022AA9; Thu, 3 May 2018 08:45:23 +0000 (UTC) From: Katerina Koukiou To: libvir-list@redhat.com Date: Thu, 3 May 2018 10:45:16 +0200 Message-Id: <20180503084519.7421-4-kkoukiou@redhat.com> In-Reply-To: <20180503084519.7421-1-kkoukiou@redhat.com> References: <20180503084519.7421-1-kkoukiou@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [dbus RFC PATCH 3/6] Abandon usage of all *TypeToString functions in network.c 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 03 May 2018 08:52:32 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Converting ENUMS to str can be user friendly though it can be problematic between libvirt versions. In particular when some translated type will introduce a new constant to the ENUM libvirt-dbus will fail with: size of array =E2=80=98_GStaticAssertCompileTimeAssertion_5=E2=80=99 is neg= ative Since it's not main use case of livirt-dbus API to be invoked interactively by user, having all ENUM types passed as unsigned int is preferable to avoid the previous issue. Signed-off-by: Katerina Koukiou --- data/org.libvirt.Network.xml | 6 ++-- src/network.c | 66 +++-------------------------------------= ---- tests/test_network.py | 2 +- 3 files changed, 8 insertions(+), 66 deletions(-) diff --git a/data/org.libvirt.Network.xml b/data/org.libvirt.Network.xml index cf05062..e8c1506 100644 --- a/data/org.libvirt.Network.xml +++ b/data/org.libvirt.Network.xml @@ -43,7 +43,7 @@ Empty string will be returned in output for NULL variables.= "/> - + - - + + diff --git a/src/network.c b/src/network.c index 4d00dfe..256940f 100644 --- a/src/network.c +++ b/src/network.c @@ -3,38 +3,6 @@ =20 #include =20 -VIRT_DBUS_ENUM_DECL(virtDBusNetworkIPAddr) -VIRT_DBUS_ENUM_IMPL(virtDBusNetworkIPAddr, - VIR_IP_ADDR_TYPE_LAST, - "ipv4", - "ipv6") - -VIRT_DBUS_ENUM_DECL(virtDBusNetworkUpdateCommand) -VIRT_DBUS_ENUM_IMPL(virtDBusNetworkUpdateCommand, - VIR_NETWORK_UPDATE_COMMAND_LAST, - "none", - "modify", - "delete", - "add-last", - "add-first") - -VIRT_DBUS_ENUM_DECL(virtDBusNetworkUpdateSection) -VIRT_DBUS_ENUM_IMPL(virtDBusNetworkUpdateSection, - VIR_NETWORK_SECTION_LAST, - "none", - "bridge", - "domain", - "ip", - "ip-dhcp-host", - "ip-dhcp-range", - "forward", - "forward-interface", - "forward-pf", - "portgroup", - "dns-host", - "dns-txt", - "dns-srv") - static void virtDBusNetworkDHCPLeaseListFree(virNetworkDHCPLeasePtr *leases) { @@ -284,20 +252,11 @@ virtDBusNetworkGetDHCPLeases(GVariant *inArgs, =20 g_variant_builder_init(&builder, G_VARIANT_TYPE("a(stssssuss)")); for (gint i =3D 0; i < nleases; i++) { - const gchar *typeStr; - virNetworkDHCPLeasePtr lease =3D leases[i]; =20 - typeStr =3D virtDBusNetworkIPAddrTypeToString(lease->type); - if (!typeStr) { - g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT, - "Can't format virIPAddrType '%d' to string.", leas= e->type); - return; - } - - g_variant_builder_add(&builder, "(stssssuss)", + g_variant_builder_add(&builder, "(stusssuss)", lease->iface, lease->expirytime, - typeStr, lease->mac, + lease->type, lease->mac, lease->iaid ? lease->iaid : "" , lease->ipaddr, lease->prefix, lease->hostname ? lease->hostname : "", @@ -366,33 +325,16 @@ virtDBusNetworkUpdate(GVariant *inArgs, { virtDBusConnect *connect =3D userData; g_autoptr(virNetwork) network =3D NULL; - const gchar *commandStr; gint command; - const gchar *sectionStr; gint section; gint parentIndex; const gchar *xml; guint flags; =20 - g_variant_get(inArgs, "(&s&si&su)", - &commandStr, §ionStr, + g_variant_get(inArgs, "(uui&su)", + &command, §ion, &parentIndex, &xml, &flags); =20 - command =3D virtDBusNetworkUpdateCommandTypeFromString(commandStr); - if (command < 0) { - g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT, - "Can't get valid virNetworkUpdateCommand from string '= %s'.", - commandStr); - return; - } - section =3D virtDBusNetworkUpdateSectionTypeFromString(sectionStr); - if (section < 0) { - g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT, - "Can't get valid virNetworkUpdateSection from string '= %s'.", - sectionStr); - return; - } - network =3D virtDBusNetworkGetVirNetwork(connect, objectPath, error); if (!network) return; diff --git a/tests/test_network.py b/tests/test_network.py index 2c1bd21..1340d95 100755 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -80,7 +80,7 @@ class TestNetwork(libvirttest.BaseTestClass): self.main_loop() =20 @pytest.mark.parametrize("command, section, parentIndex, xml_str, flag= s", [ - ('add-first', 'ip-dhcp-host', 0, ip_dhcp_host_xml, 0), + ('4', '4', 0, ip_dhcp_host_xml, 0), # add-first, ip-dhcp-host ]) def test_network_update(self, command, section, parentIndex, xml_str, = flags): _, test_network =3D self.test_network() --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 21:32:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525337155618122.87746909881662; Thu, 3 May 2018 01:45:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B2741883BF; Thu, 3 May 2018 08:45:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0E8CE30001DE; Thu, 3 May 2018 08:45:53 +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 83EAD180BAE5; Thu, 3 May 2018 08:45:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w438jP4N032393 for ; Thu, 3 May 2018 04:45:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id EC61C2022AAA; Thu, 3 May 2018 08:45:24 +0000 (UTC) Received: from katerina.brq.redhat.com (unknown [10.34.245.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66CF02022AA9; Thu, 3 May 2018 08:45:24 +0000 (UTC) From: Katerina Koukiou To: libvir-list@redhat.com Date: Thu, 3 May 2018 10:45:17 +0200 Message-Id: <20180503084519.7421-5-kkoukiou@redhat.com> In-Reply-To: <20180503084519.7421-1-kkoukiou@redhat.com> References: <20180503084519.7421-1-kkoukiou@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [dbus RFC PATCH 4/6] Change DomainEvent argument from string to unsigned int 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 03 May 2018 08:45:54 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Modify the relevant tests to comply with the new signal. Note: argument matching in connect_to_signal method is only usable with string and thus had to be refactored. Signed-off-by: Katerina Koukiou --- data/org.libvirt.Connect.xml | 2 +- src/events.c | 26 +------------------------- tests/libvirttest.py | 13 +++++++++++++ tests/test_connect.py | 12 ++++++++---- tests/test_domain.py | 30 ++++++++++++++++++++---------- 5 files changed, 43 insertions(+), 40 deletions(-) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 7249fa4..386a7bb 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -170,7 +170,7 @@ - + =20 -VIRT_DBUS_ENUM_DECL(virtDBusEventsDomainEvent) -VIRT_DBUS_ENUM_IMPL(virtDBusEventsDomainEvent, - VIR_DOMAIN_EVENT_LAST, - "Defined", - "Undefined", - "Started", - "Suspended", - "Resumed", - "Stopped", - "Shutdown", - "PMSuspended", - "Crashed") - -static const gchar * -virtDBusEventsDomainEventToString(gint event) -{ - const gchar *str =3D virtDBusEventsDomainEventTypeToString(event); - return str ? str : "unknown"; -} - static gint virtDBusEventsDomainLifecycle(virConnectPtr connection G_GNUC_UNUSED, virDomainPtr domain, @@ -33,10 +13,6 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection G= _GNUC_UNUSED, { virtDBusConnect *connect =3D opaque; g_autofree gchar *path =3D NULL; - const gchar *eventStr =3D virtDBusEventsDomainEventToString(event); - - if (!eventStr) - return 0; =20 path =3D virtDBusUtilBusPathForVirDomain(domain, connect->domainPath); =20 @@ -45,7 +21,7 @@ virtDBusEventsDomainLifecycle(virConnectPtr connection G_= GNUC_UNUSED, connect->connectPath, VIRT_DBUS_CONNECT_INTERFACE, "DomainEvent", - g_variant_new("(os)", path, eventStr), + g_variant_new("(ou)", path, event), NULL); =20 return 0; diff --git a/tests/libvirttest.py b/tests/libvirttest.py index d1b71cc..73d51e6 100644 --- a/tests/libvirttest.py +++ b/tests/libvirttest.py @@ -1,3 +1,4 @@ +from enum import IntEnum from dbus.mainloop.glib import DBusGMainLoop from gi.repository import GLib import dbus @@ -18,6 +19,18 @@ def run(): exit(pytest.main(sys.argv)) =20 =20 +class DomainEvent(IntEnum): + DEFINED =3D 0 + UNDEFINED =3D 1 + STARTED =3D 2 + SUSPENDED =3D 3 + RESUMED =3D 4 + STOPPED =3D 5 + SHUTDOWN =3D 6 + PMSUSPENDED =3D 7 + CRASHED =3D 8 + + class BaseTestClass(): """ Base test class for whole test suite """ diff --git a/tests/test_connect.py b/tests/test_connect.py index 57f0658..41cc134 100755 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -31,11 +31,13 @@ class TestConnect(libvirttest.BaseTestClass): ''' =20 def test_connect_domain_create_xml(self): - def domain_started(path, _event): + def domain_started(path, event): + if event !=3D libvirttest.DomainEvent.STARTED: + return assert isinstance(path, dbus.ObjectPath) self.loop.quit() =20 - self.connect.connect_to_signal('DomainEvent', domain_started, arg1= =3D'Started') + self.connect.connect_to_signal('DomainEvent', domain_started) =20 path =3D self.connect.DomainCreateXML(self.minimal_domain_xml, 0) assert isinstance(path, dbus.ObjectPath) @@ -43,11 +45,13 @@ class TestConnect(libvirttest.BaseTestClass): self.main_loop() =20 def test_comnect_domain_define_xml(self): - def domain_defined(path, _event): + def domain_defined(path, event): + if event !=3D libvirttest.DomainEvent.DEFINED: + return assert isinstance(path, dbus.ObjectPath) self.loop.quit() =20 - self.connect.connect_to_signal('DomainEvent', domain_defined, arg1= =3D'Defined') + self.connect.connect_to_signal('DomainEvent', domain_defined) =20 path =3D self.connect.DomainDefineXML(self.minimal_domain_xml) assert isinstance(path, dbus.ObjectPath) diff --git a/tests/test_domain.py b/tests/test_domain.py index 0e83f72..2def6c1 100755 --- a/tests/test_domain.py +++ b/tests/test_domain.py @@ -47,11 +47,13 @@ class TestDomain(libvirttest.BaseTestClass): assert autostart_current =3D=3D dbus.Boolean(autostart_expected) =20 def test_domain_managed_save(self): - def domain_stopped(path, _event): + def domain_stopped(path, event): + if event !=3D libvirttest.DomainEvent.STOPPED: + return assert isinstance(path, dbus.ObjectPath) self.loop.quit() =20 - self.connect.connect_to_signal('DomainEvent', domain_stopped, arg1= =3D'Stopped') + self.connect.connect_to_signal('DomainEvent', domain_stopped) =20 obj, domain =3D self.domain() domain.ManagedSave(0) @@ -72,11 +74,13 @@ class TestDomain(libvirttest.BaseTestClass): assert description_expected =3D=3D domain.GetMetadata(metadata_des= cription, "", 0) =20 def test_resume(self): - def domain_resumed(path, _event): + def domain_resumed(path, event): + if event !=3D libvirttest.DomainEvent.RESUMED: + return assert isinstance(path, dbus.ObjectPath) self.loop.quit() =20 - self.connect.connect_to_signal('DomainEvent', domain_resumed, arg1= =3D'Resumed') + self.connect.connect_to_signal('DomainEvent', domain_resumed) =20 obj, domain =3D self.domain() domain.Suspend() @@ -88,11 +92,13 @@ class TestDomain(libvirttest.BaseTestClass): self.main_loop() =20 def test_shutdown(self): - def domain_stopped(path, _event): + def domain_stopped(path, event): + if event !=3D libvirttest.DomainEvent.STOPPED: + return assert isinstance(path, dbus.ObjectPath) self.loop.quit() =20 - self.connect.connect_to_signal('DomainEvent', domain_stopped, arg1= =3D'Stopped') + self.connect.connect_to_signal('DomainEvent', domain_stopped) =20 obj, domain =3D self.domain() domain.Shutdown(0) @@ -103,11 +109,13 @@ class TestDomain(libvirttest.BaseTestClass): self.main_loop() =20 def test_suspend(self): - def domain_suspended(path, _event): + def domain_suspended(path, event): + if event !=3D libvirttest.DomainEvent.SUSPENDED: + return assert isinstance(path, dbus.ObjectPath) self.loop.quit() =20 - self.connect.connect_to_signal('DomainEvent', domain_suspended, ar= g1=3D'Suspended') + self.connect.connect_to_signal('DomainEvent', domain_suspended) =20 obj, domain =3D self.domain() domain.Suspend() @@ -118,11 +126,13 @@ class TestDomain(libvirttest.BaseTestClass): self.main_loop() =20 def test_undefine(self): - def domain_undefined(path, _event): + def domain_undefined(path, event): + if event !=3D libvirttest.DomainEvent.UNDEFINED: + return assert isinstance(path, dbus.ObjectPath) self.loop.quit() =20 - self.connect.connect_to_signal('DomainEvent', domain_undefined, ar= g1=3D'Undefined') + self.connect.connect_to_signal('DomainEvent', domain_undefined) =20 _, domain =3D self.domain() domain.Shutdown(0) --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 21:32:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525337439924175.34931846367635; Thu, 3 May 2018 01:50:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39C6830F0863; Thu, 3 May 2018 08:50:38 +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 BCA7020154EE; Thu, 3 May 2018 08:50:37 +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 BFC094CAA8; Thu, 3 May 2018 08:50:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w438jPhM032398 for ; Thu, 3 May 2018 04:45:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id B51312022AAA; Thu, 3 May 2018 08:45:25 +0000 (UTC) Received: from katerina.brq.redhat.com (unknown [10.34.245.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 35BB32022AA9; Thu, 3 May 2018 08:45:25 +0000 (UTC) From: Katerina Koukiou To: libvir-list@redhat.com Date: Thu, 3 May 2018 10:45:18 +0200 Message-Id: <20180503084519.7421-6-kkoukiou@redhat.com> In-Reply-To: <20180503084519.7421-1-kkoukiou@redhat.com> References: <20180503084519.7421-1-kkoukiou@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [dbus RFC PATCH 5/6] Change NetworkEvent argument from string to unsigned int 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 03 May 2018 08:50:39 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Modify the relevant tests to comply with the new signal. Note: argument matching in connect_to_signal method is only usable with string and thus had to be refactored. Signed-off-by: Katerina Koukiou --- data/org.libvirt.Connect.xml | 2 +- src/events.c | 14 +------------- tests/libvirttest.py | 7 +++++++ tests/test_connect.py | 12 ++++++++---- tests/test_network.py | 18 ++++++++++++------ 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 386a7bb..8272da6 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -176,7 +176,7 @@ - + diff --git a/src/events.c b/src/events.c index 601d898..1b584f7 100644 --- a/src/events.c +++ b/src/events.c @@ -146,14 +146,6 @@ virtDBusEventsDomainDiskChange(virConnectPtr connectio= n G_GNUC_UNUSED, return 0; } =20 -VIRT_DBUS_ENUM_DECL(virtDBusEventsNetworkEvent) -VIRT_DBUS_ENUM_IMPL(virtDBusEventsNetworkEvent, - VIR_NETWORK_EVENT_LAST, - "Defined", - "Undefined", - "Started", - "Stopped") - static gint virtDBusEventsNetworkLifecycle(virConnectPtr connection G_GNUC_UNUSED, virNetworkPtr network, @@ -163,10 +155,6 @@ virtDBusEventsNetworkLifecycle(virConnectPtr connectio= n G_GNUC_UNUSED, { virtDBusConnect *connect =3D opaque; g_autofree gchar *path =3D NULL; - const gchar *eventStr =3D virtDBusEventsNetworkEventTypeToString(event= ); - - if (!eventStr) - return 0; =20 path =3D virtDBusUtilBusPathForVirNetwork(network, connect->networkPat= h); =20 @@ -175,7 +163,7 @@ virtDBusEventsNetworkLifecycle(virConnectPtr connection= G_GNUC_UNUSED, connect->connectPath, VIRT_DBUS_CONNECT_INTERFACE, "NetworkEvent", - g_variant_new("(os)", path, eventStr), + g_variant_new("(ou)", path, event), NULL); =20 return 0; diff --git a/tests/libvirttest.py b/tests/libvirttest.py index 73d51e6..fc3ed5e 100644 --- a/tests/libvirttest.py +++ b/tests/libvirttest.py @@ -31,6 +31,13 @@ class DomainEvent(IntEnum): CRASHED =3D 8 =20 =20 +class NetworkEvent(IntEnum): + DEFINED =3D 0 + UNDEFINED =3D 1 + STARTED =3D 2 + STOPPED =3D 3 + + class BaseTestClass(): """ Base test class for whole test suite """ diff --git a/tests/test_connect.py b/tests/test_connect.py index 41cc134..7748822 100755 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -125,11 +125,13 @@ class TestConnect(libvirttest.BaseTestClass): assert isinstance(self.connect.GetCPUModelNames(arch, 0), dbus.Arr= ay) =20 def test_connect_network_create_xml(self): - def network_started(path, _event): + def network_started(path, event): + if event !=3D libvirttest.NetworkEvent.STARTED: + return assert isinstance(path, dbus.ObjectPath) self.loop.quit() =20 - self.connect.connect_to_signal('NetworkEvent', network_started, ar= g1=3D'Started') + self.connect.connect_to_signal('NetworkEvent', network_started) =20 path =3D self.connect.NetworkCreateXML(self.minimal_network_xml) assert isinstance(path, dbus.ObjectPath) @@ -137,11 +139,13 @@ class TestConnect(libvirttest.BaseTestClass): self.main_loop() =20 def test_connect_network_define_xml(self): - def network_defined(path, _event): + def network_defined(path, event): + if event !=3D libvirttest.NetworkEvent.DEFINED: + return assert isinstance(path, dbus.ObjectPath) self.loop.quit() =20 - self.connect.connect_to_signal('NetworkEvent', network_defined, ar= g1=3D'Defined') + self.connect.connect_to_signal('NetworkEvent', network_defined) =20 path =3D self.connect.NetworkDefineXML(self.minimal_network_xml) assert isinstance(path, dbus.ObjectPath) diff --git a/tests/test_network.py b/tests/test_network.py index 1340d95..f34c081 100755 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -34,11 +34,13 @@ class TestNetwork(libvirttest.BaseTestClass): assert autostart_current =3D=3D dbus.Boolean(autostart_expected) =20 def test_network_create(self): - def domain_started(path, _event): + def domain_started(path, event): + if event !=3D libvirttest.NetworkEvent.STARTED: + return assert isinstance(path, dbus.ObjectPath) self.loop.quit() =20 - self.connect.connect_to_signal('NetworkEvent', domain_started, arg= 1=3D'Started') + self.connect.connect_to_signal('NetworkEvent', domain_started) =20 _,test_network =3D self.test_network() interface_obj =3D dbus.Interface(test_network, 'org.libvirt.Networ= k') @@ -48,11 +50,13 @@ class TestNetwork(libvirttest.BaseTestClass): self.main_loop() =20 def test_network_destroy(self): - def network_stopped(path, _event): + def network_stopped(path, event): + if event !=3D libvirttest.NetworkEvent.STOPPED: + return assert isinstance(path, dbus.ObjectPath) self.loop.quit() =20 - self.connect.connect_to_signal('NetworkEvent', network_stopped, ar= g1=3D'Stopped') + self.connect.connect_to_signal('NetworkEvent', network_stopped) =20 _, test_network =3D self.test_network() interface_obj =3D dbus.Interface(test_network, 'org.libvirt.Networ= k') @@ -66,11 +70,13 @@ class TestNetwork(libvirttest.BaseTestClass): assert isinstance(interface_obj.GetXMLDesc(0), dbus.String) =20 def test_network_undefine(self): - def domain_undefined(path, _event): + def domain_undefined(path, event): + if event !=3D libvirttest.NetworkEvent.UNDEFINED: + return assert isinstance(path, dbus.ObjectPath) self.loop.quit() =20 - self.connect.connect_to_signal('NetworkEvent', domain_undefined, a= rg1=3D'Undefined') + self.connect.connect_to_signal('NetworkEvent', domain_undefined) =20 _,test_network =3D self.test_network() interface_obj =3D dbus.Interface(test_network, 'org.libvirt.Networ= k') --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat May 4 21:32:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1525337559449322.00907921485214; Thu, 3 May 2018 01:52:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA5043B720; Thu, 3 May 2018 08:52:37 +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 7973430012B5; Thu, 3 May 2018 08:52:37 +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 1C4354CAA9; Thu, 3 May 2018 08:52:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w438jQnd032408 for ; Thu, 3 May 2018 04:45:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 80E962022AAC; Thu, 3 May 2018 08:45:26 +0000 (UTC) Received: from katerina.brq.redhat.com (unknown [10.34.245.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0190B2022AA9; Thu, 3 May 2018 08:45:25 +0000 (UTC) From: Katerina Koukiou To: libvir-list@redhat.com Date: Thu, 3 May 2018 10:45:19 +0200 Message-Id: <20180503084519.7421-7-kkoukiou@redhat.com> In-Reply-To: <20180503084519.7421-1-kkoukiou@redhat.com> References: <20180503084519.7421-1-kkoukiou@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [dbus RFC PATCH 6/6] Remove virtDBusUtilEnum{From, From}String functions 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 03 May 2018 08:52:38 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Katerina Koukiou --- src/util.c | 27 --------------------------- src/util.h | 28 ---------------------------- 2 files changed, 55 deletions(-) diff --git a/src/util.c b/src/util.c index a9d130e..4efa3ec 100644 --- a/src/util.c +++ b/src/util.c @@ -214,33 +214,6 @@ virtDBusUtilVirDomainListFree(virDomainPtr *domains) g_free(domains); } =20 -const gchar * -virtDBusUtilEnumToString(const gchar *const *types, - guint ntypes, - gint type) -{ - if (type < 0 || (guint)type >=3D ntypes) - return NULL; - - return types[type]; -} - -gint -virtDBusUtilEnumFromString(const gchar *const *types, - guint ntypes, - const gchar *type) -{ - guint i; - if (!type) - return -1; - - for (i =3D 0; i < ntypes; i++) - if (g_str_equal(types[i], type)) - return i; - - return -1; -} - virNetworkPtr virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection, const gchar *path, diff --git a/src/util.h b/src/util.h index 4a2138a..3309803 100644 --- a/src/util.h +++ b/src/util.h @@ -57,34 +57,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainPtr, virtDBusUtil= VirDomainListFree); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainStatsRecordPtr, virDomainStatsRecor= dListFree); =20 -gint -virtDBusUtilEnumFromString(const gchar *const *types, - guint ntypes, - const gchar *type) G_GNUC_PURE; - -const gchar * -virtDBusUtilEnumToString(const gchar *const *types, - guint ntypes, - gint type) G_GNUC_PURE; - -#define VIRT_DBUS_ENUM_IMPL(name, lastVal, ...) \ - static const gchar *const name ##TypeList[] =3D { __VA_ARGS__ }; \ - G_STATIC_ASSERT(G_N_ELEMENTS(name ##TypeList) =3D=3D lastVal); \ - const gchar *name ##TypeToString(gint type) { \ - return virtDBusUtilEnumToString(name ##TypeList, \ - G_N_ELEMENTS(name ##TypeList), \ - type); \ - } \ - gint name ##TypeFromString(const gchar *type) { \ - return virtDBusUtilEnumFromString(name ##TypeList, \ - G_N_ELEMENTS(name ##TypeList), \ - type); \ - } - -#define VIRT_DBUS_ENUM_DECL(name) \ - const gchar *name ##TypeToString(gint type) G_GNUC_PURE; \ - gint name ##TypeFromString(const gchar *type) G_GNUC_PURE; - virNetworkPtr virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection, const gchar *path, --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list