[libvirt] [dbus PATCH 15/19] Implement StoragePoolLookupByName method for Connect Interface

Katerina Koukiou kkoukiou at redhat.com
Mon May 7 14:40:56 UTC 2018


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

diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index 6b156d1..55c0883 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -217,6 +217,12 @@
       <arg name="params" type="a{sv}" direction="in"/>
       <arg name="flags" type="u" direction="in"/>
     </method>
+    <method name="StoragePoolLookupByName">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolLookupByName"/>
+      <arg name="name" type="s" direction="in"/>
+      <arg name="storagePool" type="o" direction="out"/>
+    </method>
     <signal name="DomainEvent">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventCallback"/>
diff --git a/src/connect.c b/src/connect.c
index 97c4857..fa4078f 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -1104,6 +1104,35 @@ virtDBusConnectNodeSetMemoryParameters(GVariant *inArgs,
     }
 }
 
+static void
+virtDBusConnectStoragePoolLookupByName(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(virStoragePool) storagePool = NULL;
+    g_autofree gchar *path = NULL;
+    const gchar *name;
+
+    g_variant_get(inArgs, "(s)", &name);
+
+    if (!virtDBusConnectOpen(connect, error))
+        return;
+
+    storagePool = virStoragePoolLookupByName(connect->connection, name);
+    if (!storagePool)
+        return virtDBusUtilSetLastVirtError(error);
+
+    path = virtDBusUtilBusPathForVirStoragePool(storagePool,
+                                                connect->storagePoolPath);
+
+    *outArgs = g_variant_new("(o)", path);
+}
+
 static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = {
     { "Encrypted", virtDBusConnectGetEncrypted, NULL },
     { "Hostname", virtDBusConnectGetHostname, NULL },
@@ -1143,6 +1172,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
     { "NodeGetMemoryStats", virtDBusConnectNodeGetMemoryStats },
     { "NodeGetSecurityModel", virtDBusConnectNodeGetSecurityModel },
     { "NodeSetMemoryParameters", virtDBusConnectNodeSetMemoryParameters },
+    { "StoragePoolLookupByName", virtDBusConnectStoragePoolLookupByName },
     { 0 }
 };
 
diff --git a/tests/test_connect.py b/tests/test_connect.py
index d8f05e8..2e0cd7f 100755
--- a/tests/test_connect.py
+++ b/tests/test_connect.py
@@ -190,6 +190,21 @@ class TestConnect(libvirttest.BaseTestClass):
         info = self.connect.NodeGetCPUMap(0)
         assert isinstance(info, dbus.Array)
 
+    @pytest.mark.parametrize("lookup_method_name,lookup_item", [
+        ("StoragePoolLookupByName", 'Name'),
+    ])
+    def test_connect_network_lookup_by_property(
+            self,
+            lookup_method_name,
+            lookup_item):
+        """Parameterized test for all StoragePoolLookupBy* API calls of Connect interface
+        """
+        original_path, obj = self.test_storage_pool()
+        prop = obj.Get('org.libvirt.StoragePool', lookup_item,
+                       dbus_interface=dbus.PROPERTIES_IFACE)
+        path = getattr(self.connect, lookup_method_name)(prop)
+        assert original_path == path
+
 
 if __name__ == '__main__':
     libvirttest.run()
-- 
2.15.0




More information about the libvir-list mailing list