Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
data/org.libvirt.StoragePool.xml | 4 ++++
src/storagepool.c | 43 ++++++++++++++++++++++++++++++++++++++++
tests/libvirttest.py | 21 ++++++++++++++++++++
tests/test_storage.py | 26 ++++++++++++++++++++++++
4 files changed, 94 insertions(+)
create mode 100755 tests/test_storage.py
diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml
index 504a166..ac628d9 100644
--- a/data/org.libvirt.StoragePool.xml
+++ b/data/org.libvirt.StoragePool.xml
@@ -3,5 +3,9 @@
<node name="/org/libvirt/storagepool">
<interface name="org.libvirt.StoragePool">
+ <method name="Destroy">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See
https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolDestr...
+ </method>
</interface>
</node>
diff --git a/src/storagepool.c b/src/storagepool.c
index f1421ef..5202f9e 100644
--- a/src/storagepool.c
+++ b/src/storagepool.c
@@ -3,11 +3,54 @@
#include <libvirt/libvirt.h>
+static virStoragePoolPtr
+virtDBusStoragePoolGetVirStoragePool(virtDBusConnect *connect,
+ const gchar *objectPath,
+ GError **error)
+{
+ virStoragePoolPtr storagePool;
+
+ if (virtDBusConnectOpen(connect, error) < 0)
+ return NULL;
+
+ storagePool = virtDBusUtilVirStoragePoolFromBusPath(connect->connection,
+ objectPath,
+ connect->storagePoolPath);
+ if (!storagePool) {
+ virtDBusUtilSetLastVirtError(error);
+ return NULL;
+ }
+
+ return storagePool;
+}
+
+static void
+virtDBusStoragePoolDestroy(GVariant *inArgs G_GNUC_UNUSED,
+ GUnixFDList *inFDs G_GNUC_UNUSED,
+ const gchar *objectPath,
+ gpointer userData,
+ GVariant **outArgs G_GNUC_UNUSED,
+ GUnixFDList **outFDs G_GNUC_UNUSED,
+ GError **error)
+{
+ virtDBusConnect *connect = userData;
+ g_autoptr(virStoragePool) storagePool = NULL;
+
+ storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath,
+ error);
+ if (!storagePool)
+ return;
+
+ if (virStoragePoolDestroy(storagePool) < 0)
+ virtDBusUtilSetLastVirtError(error);
+}
+
static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = {
{ 0 }
};
static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = {
+ { "Destroy", virtDBusStoragePoolDestroy },
{ 0 }
};
diff --git a/tests/libvirttest.py b/tests/libvirttest.py
index eee67a0..e88484f 100644
--- a/tests/libvirttest.py
+++ b/tests/libvirttest.py
@@ -87,6 +87,19 @@ class BaseTestClass():
obj = self.bus.get_object('org.libvirt', path)
return path, obj
+ def test_storage_pool(self):
+ """Fetch information for the test storage pool from test driver
+
+ Returns:
+ (dbus.proxies.ProxyObject, dbus.proxies.ProxyObject):
+ Test StoragePool Object, Local proxy for the test StoragePool
+ Object.
+
+ """
+ path = self.connect.ListStoragePools(0)[0]
+ obj = self.bus.get_object('org.libvirt', path)
+ return path, obj
+
class DomainEvent(IntEnum):
DEFINED = 0
@@ -172,3 +185,11 @@ class NetworkEvent(IntEnum):
UNDEFINED = 1
STARTED = 2
STOPPED = 3
+
+
+class StoragePoolEvent(IntEnum):
+ DEFINED = 0
+ UNDEFINED = 1
+ STARTED = 2
+ STOPPED = 3
+ LAST = 4
diff --git a/tests/test_storage.py b/tests/test_storage.py
new file mode 100755
index 0000000..8c5d75f
--- /dev/null
+++ b/tests/test_storage.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+
+import dbus
+import libvirttest
+
+class TestStoragePool(libvirttest.BaseTestClass):
+ def test_storage_pool_destroy(self):
+ def storage_pool_destroyed(path, event, _detail):
+ if event != libvirttest.StoragePoolEvent.STOPPED:
+ return
+ assert isinstance(path, dbus.ObjectPath)
+ self.loop.quit()
+
+ self.connect.connect_to_signal('StoragePoolEvent',
+ storage_pool_destroyed)
+
+ _, test_storage_pool = self.test_storage_pool()
+ interface_obj = dbus.Interface(test_storage_pool,
+ 'org.libvirt.StoragePool')
+ interface_obj.Destroy()
+
+ self.main_loop()
+
+
+if __name__ == '__main__':
+ libvirttest.run()
--
2.15.0