From nobody Thu May 15 16:03:22 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522924830265335.6546039746928; Thu, 5 Apr 2018 03:40:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E1B432FA; Thu, 5 Apr 2018 10:40:28 +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 A2D5A174B1; Thu, 5 Apr 2018 10:40:28 +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 590B91800CA0; Thu, 5 Apr 2018 10:40:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w35AeQiW003472 for ; Thu, 5 Apr 2018 06:40:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 51CD5AB3E2; Thu, 5 Apr 2018 10:40:26 +0000 (UTC) Received: from katerina.brq.redhat.com (ovpn-204-29.brq.redhat.com [10.40.204.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id EBF56AB3E7 for ; Thu, 5 Apr 2018 10:40:25 +0000 (UTC) From: Katerina Koukiou To: libvir-list@redhat.com Date: Thu, 5 Apr 2018 12:40:19 +0200 Message-Id: <20180405104020.18545-4-kkoukiou@redhat.com> In-Reply-To: <20180405104020.18545-1-kkoukiou@redhat.com> References: <20180405104020.18545-1-kkoukiou@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [dbus PATCH v3 3/4] Implement Name property for Network interface 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.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 05 Apr 2018 10:40:29 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Katerina Koukiou --- data/org.libvirt.Network.xml | 4 ++++ src/network.c | 43 ++++++++++++++++++++++++++++++++++++++++= +++ test/Makefile.am | 3 ++- test/libvirttest.py | 12 ++++++++++++ test/test_network.py | 19 +++++++++++++++++++ 5 files changed, 80 insertions(+), 1 deletion(-) create mode 100755 test/test_network.py diff --git a/data/org.libvirt.Network.xml b/data/org.libvirt.Network.xml index 2b7c4f7..1215ac3 100644 --- a/data/org.libvirt.Network.xml +++ b/data/org.libvirt.Network.xml @@ -3,5 +3,9 @@ =20 + + + diff --git a/src/network.c b/src/network.c index 0d0e992..fdfaaa7 100644 --- a/src/network.c +++ b/src/network.c @@ -3,7 +3,50 @@ =20 #include =20 +static virNetworkPtr +virtDBusNetworkGetVirNetwork(virtDBusConnect *connect, + const gchar *objectPath, + GError **error) +{ + virNetworkPtr network; + + if (virtDBusConnectOpen(connect, error) < 0) + return NULL; + + network =3D virtDBusUtilVirNetworkFromBusPath(connect->connection, + objectPath, + connect->networkPath); + if (!network) { + virtDBusUtilSetLastVirtError(error); + return NULL; + } + + return network; +} + +static void +virtDBusNetworkGetName(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect =3D userData; + g_autoptr(virNetwork) network =3D NULL; + const gchar *name; + + network =3D virtDBusNetworkGetVirNetwork(connect, objectPath, error); + if (!network) + return; + + name =3D virNetworkGetName(network); + if (!name) + return virtDBusUtilSetLastVirtError(error); + + *value =3D g_variant_new("s", name); +} + static virtDBusGDBusPropertyTable virtDBusNetworkPropertyTable[] =3D { + { "Name", virtDBusNetworkGetName, NULL }, { 0 } }; =20 diff --git a/test/Makefile.am b/test/Makefile.am index acb2d33..089ade5 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -4,7 +4,8 @@ test_helpers =3D \ =20 test_programs =3D \ test_connect.py \ - test_domain.py + test_domain.py \ + test_network.py =20 EXTRA_DIST =3D \ $(test_helpers) \ diff --git a/test/libvirttest.py b/test/libvirttest.py index c4dc96f..ecd8aef 100644 --- a/test/libvirttest.py +++ b/test/libvirttest.py @@ -70,3 +70,15 @@ class BaseTestClass(): path =3D self.connect.ListDomains(0)[0] obj =3D self.bus.get_object('org.libvirt', path) return obj, dbus.Interface(obj, 'org.libvirt.Domain') + + def test_network(self): + """Fetch information for the test network from test driver + + Returns: + (dbus.proxies.ProxyObject, dbus.proxies.ProxyObject): + Test Network Object, Local proxy for the test Network Object. + + """ + path =3D self.connect.ListNetworks(0)[0] + obj =3D self.bus.get_object('org.libvirt', path) + return path, obj diff --git a/test/test_network.py b/test/test_network.py new file mode 100755 index 0000000..97ab0aa --- /dev/null +++ b/test/test_network.py @@ -0,0 +1,19 @@ +#!/usr/bin/python3 + +import dbus +import libvirttest + + +class TestNetwork(libvirttest.BaseTestClass): + """ Tests for methods and properties of the Network interface + """ + def test_network_properties_type(self): + """ Ensure correct return type for Network properties + """ + _, obj =3D self.test_network() + props =3D obj.GetAll('org.libvirt.Network', dbus_interface=3Ddbus.= PROPERTIES_IFACE) + assert isinstance(props['Name'], dbus.String) + + +if __name__ =3D=3D '__main__': + libvirttest.run() --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list