Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx> --- 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 @@ <node name="/org/libvirt/network"> <interface name="org.libvirt.Network"> + <property name="Name" type="s" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetName"/> + </property> </interface> </node> 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 @@ #include <libvirt/libvirt.h> +static virNetworkPtr +virtDBusNetworkGetVirNetwork(virtDBusConnect *connect, + const gchar *objectPath, + GError **error) +{ + virNetworkPtr network; + + if (virtDBusConnectOpen(connect, error) < 0) + return NULL; + + network = 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 = userData; + g_autoptr(virNetwork) network = NULL; + const gchar *name; + + network = virtDBusNetworkGetVirNetwork(connect, objectPath, error); + if (!network) + return; + + name = virNetworkGetName(network); + if (!name) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("s", name); +} + static virtDBusGDBusPropertyTable virtDBusNetworkPropertyTable[] = { + { "Name", virtDBusNetworkGetName, NULL }, { 0 } }; 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 = \ test_programs = \ test_connect.py \ - test_domain.py + test_domain.py \ + test_network.py EXTRA_DIST = \ $(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 = self.connect.ListDomains(0)[0] obj = 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 = self.connect.ListNetworks(0)[0] + obj = 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 = self.test_network() + props = obj.GetAll('org.libvirt.Network', dbus_interface=dbus.PROPERTIES_IFACE) + assert isinstance(props['Name'], dbus.String) + + +if __name__ == '__main__': + libvirttest.run() -- 2.15.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list