[libvirt] [dbus PATCH 11/14] Implement NodeDeviceLookupByName method for Connect Interface

Katerina Koukiou kkoukiou at redhat.com
Fri Jun 15 17:03:47 UTC 2018


Signed-off-by: Katerina Koukiou <kkoukiou at redhat.com>
---
 data/org.libvirt.Connect.xml |  6 ++++++
 src/connect.c                | 29 +++++++++++++++++++++++++++++
 tests/test_connect.py        | 13 +++++++++++++
 3 files changed, 48 insertions(+)

diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index d8b0d9e..a030d57 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -215,6 +215,12 @@
       <arg name="flags" type="u" direction="in"/>
       <arg name="dev" type="o" direction="out"/>
     </method>
+    <method name="NodeDeviceLookupByName">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceLookupByName"/>
+      <arg name="name" type="s" direction="in"/>
+      <arg name="dev" type="o" direction="out"/>
+    </method>
     <method name="NWFilterDefineXML">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterDefineXML"/>
diff --git a/src/connect.c b/src/connect.c
index 5e146a6..6192f47 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -1098,6 +1098,34 @@ virtDBusConnectNodeDeviceCreateXML(GVariant *inArgs,
     *outArgs = g_variant_new("(o)", path);
 }
 
+static void
+virtDBusConnectNodeDeviceLookupByName(GVariant *inArgs,
+                                      GUnixFDList *inFDs G_GNUC_UNUSED,
+                                      const gchar *objectPath G_GNUC_UNUSED,
+                                      gpointer userData,
+                                      GVariant **outArgs,
+                                      GUnixFDList **outFDs G_GNUC_UNUSED,
+                                      GError **error)
+{
+    virtDBusConnect *connect = userData;
+    g_autoptr(virNodeDevice) dev = NULL;
+    g_autofree gchar *path = NULL;
+    const gchar *name;
+
+    g_variant_get(inArgs, "(s)", &name);
+
+    if (!virtDBusConnectOpen(connect, error))
+        return;
+
+    dev = virNodeDeviceLookupByName(connect->connection, name);
+    if (!dev)
+        return virtDBusUtilSetLastVirtError(error);
+
+    path = virtDBusUtilBusPathForVirNodeDevice(dev, connect->devPath);
+
+    *outArgs = g_variant_new("(o)", path);
+}
+
 static void
 virtDBusConnectNWFilterDefineXML(GVariant *inArgs,
                                  GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -1717,6 +1745,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
     { "NetworkLookupByName", virtDBusConnectNetworkLookupByName },
     { "NetworkLookupByUUID", virtDBusConnectNetworkLookupByUUID },
     { "NodeDeviceCreateXML", virtDBusConnectNodeDeviceCreateXML },
+    { "NodeDeviceLookupByName", virtDBusConnectNodeDeviceLookupByName },
     { "NWFilterDefineXML", virtDBusConnectNWFilterDefineXML },
     { "NWFilterLookupByName", virtDBusConnectNWFilterLookupByName },
     { "NWFilterLookupByUUID", virtDBusConnectNWFilterLookupByUUID },
diff --git a/tests/test_connect.py b/tests/test_connect.py
index e532016..7084397 100755
--- a/tests/test_connect.py
+++ b/tests/test_connect.py
@@ -143,6 +143,19 @@ class TestConnect(libvirttest.BaseTestClass):
 
         self.main_loop()
 
+    @pytest.mark.usefixtures("node_device_create")
+    @pytest.mark.parametrize("lookup_method_name,lookup_item", [
+        ("NodeDeviceLookupByName", 'Name'),
+    ])
+    def test_connect_node_device_lookup_by_property(self, lookup_method_name, lookup_item):
+        """Parameterized test for all NodeDeviceLookupBy* API calls of Connect interface
+        """
+        original_path = self.node_device_create()
+        obj = self.bus.get_object('org.libvirt', original_path)
+        prop = obj.Get('org.libvirt.NodeDevice', lookup_item, dbus_interface=dbus.PROPERTIES_IFACE)
+        path = getattr(self.connect, lookup_method_name)(prop)
+        assert original_path == path
+
     @pytest.mark.parametrize("lookup_method_name,lookup_item", [
         ("NetworkLookupByName", 'Name'),
         ("NetworkLookupByUUID", 'UUID'),
-- 
2.15.0




More information about the libvir-list mailing list