[libvirt] [dbus PATCH 00/19] StoragePool APIs till libvirt 3.0

Katerina Koukiou (19): Introduce StoragePool Interface Implement ListStoragePools method for Connect Interface Register StoragePool Lifecycle Events Implement Destroy method for StoragePool Interface Implement Build method for StoragePool Interface Implement Create method for StoragePool Interface Implement Delete method for StoragePool Interface Implement getter for Autostart property for StoragePool Interface Implement GetInfo method for StoragePool Interface Implement Name property for StoragePool Interface Implement UUID property for StoragePool Interface Implement GetXMLDesc method for StoragePool Interface Implement Active property for StoragePool Interface Implement Persistent property for StoragePool Interface Implement StoragePoolLookupByName method for Connect Interface Implement StoragePoolLookupByUUID method for Connect Interface Implement Refresh method for StoragePool Interface Implement setter for Autostart property for StoragePool Interface Implement Undefine method for StoragePool Interface data/Makefile.am | 3 +- data/org.libvirt.Connect.xml | 24 +++ data/org.libvirt.StoragePool.xml | 69 +++++++ src/Makefile.am | 3 +- src/connect.c | 120 +++++++++++ src/connect.h | 2 + src/events.c | 43 ++++ src/storagepool.c | 422 +++++++++++++++++++++++++++++++++++++++ src/storagepool.h | 9 + src/util.c | 33 +++ src/util.h | 15 ++ tests/libvirttest.py | 29 +++ tests/test_connect.py | 28 +++ tests/test_storage.py | 112 +++++++++++ 14 files changed, 910 insertions(+), 2 deletions(-) create mode 100644 data/org.libvirt.StoragePool.xml create mode 100644 src/storagepool.c create mode 100644 src/storagepool.h create mode 100755 tests/test_storage.py -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/Makefile.am | 3 +- data/org.libvirt.StoragePool.xml | 7 +++++ src/Makefile.am | 3 +- src/connect.c | 6 ++++ src/connect.h | 1 + src/storagepool.c | 65 ++++++++++++++++++++++++++++++++++++++++ src/storagepool.h | 9 ++++++ src/util.c | 33 ++++++++++++++++++++ src/util.h | 16 ++++++++++ 9 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 data/org.libvirt.StoragePool.xml create mode 100644 src/storagepool.c create mode 100644 src/storagepool.h diff --git a/data/Makefile.am b/data/Makefile.am index 61702df..4d2af45 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -21,7 +21,8 @@ polkit_DATA = $(polkit_files:.rules.in=.rules) interfaces_files = \ org.libvirt.Connect.xml \ org.libvirt.Domain.xml \ - org.libvirt.Network.xml + org.libvirt.Network.xml \ + org.libvirt.StoragePool.xml interfacesdir = $(DBUS_INTERFACES_DIR) interfaces_DATA = $(interfaces_files) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml new file mode 100644 index 0000000..504a166 --- /dev/null +++ b/data/org.libvirt.StoragePool.xml @@ -0,0 +1,7 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" +"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> + +<node name="/org/libvirt/storagepool"> + <interface name="org.libvirt.StoragePool"> + </interface> +</node> diff --git a/src/Makefile.am b/src/Makefile.am index 158398a..5e082da 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,7 +9,8 @@ DAEMON_SOURCES = \ domain.c domain.h \ events.c events.h \ gdbus.c gdbus.h \ - network.c network.h + network.c network.h \ + storagepool.c storagepool.h EXTRA_DIST = \ $(DAEMON_SOURCES) diff --git a/src/connect.c b/src/connect.c index fd335e3..e838e98 100644 --- a/src/connect.c +++ b/src/connect.c @@ -2,6 +2,7 @@ #include "domain.h" #include "events.h" #include "network.h" +#include "storagepool.h" #include "util.h" #include <glib/gprintf.h> @@ -1105,6 +1106,7 @@ virtDBusConnectFree(virtDBusConnect *connect) g_free(connect->domainPath); g_free(connect->networkPath); + g_free(connect->storagePoolPath); g_free(connect); } G_DEFINE_AUTOPTR_CLEANUP_FUNC(virtDBusConnect, virtDBusConnectFree); @@ -1154,6 +1156,10 @@ virtDBusConnectNew(virtDBusConnect **connectp, if (error && *error) return; + virtDBusStoragePoolRegister(connect, error); + if (error && *error) + return; + *connectp = connect; connect = NULL; } diff --git a/src/connect.h b/src/connect.h index f89bc9d..d6c3830 100644 --- a/src/connect.h +++ b/src/connect.h @@ -14,6 +14,7 @@ struct virtDBusConnect { const gchar *connectPath; gchar *domainPath; gchar *networkPath; + gchar *storagePoolPath; virConnectPtr connection; GMutex lock; diff --git a/src/storagepool.c b/src/storagepool.c new file mode 100644 index 0000000..f1421ef --- /dev/null +++ b/src/storagepool.c @@ -0,0 +1,65 @@ +#include "storagepool.h" +#include "util.h" + +#include <libvirt/libvirt.h> + +static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = { + { 0 } +}; + +static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { + { 0 } +}; + +static gchar ** +virtDBusStoragePoolEnumerate(gpointer userData) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePoolPtr) storagePools = NULL; + gint num = 0; + gchar **ret = NULL; + + if (!virtDBusConnectOpen(connect, NULL)) + return NULL; + + num = virConnectListAllStoragePools(connect->connection, &storagePools, 0); + if (num < 0) + return NULL; + + if (num == 0) + return NULL; + + ret = g_new0(gchar *, num + 1); + + for (gint i = 0; i < num; i++) { + ret[i] = virtDBusUtilBusPathForVirStoragePool(storagePools[i], + connect->storagePoolPath); + } + + return ret; +} + +static GDBusInterfaceInfo *interfaceInfo; + +void +virtDBusStoragePoolRegister(virtDBusConnect *connect, + GError **error) +{ + connect->storagePoolPath = g_strdup_printf("%s/storagepool", + connect->connectPath); + + if (!interfaceInfo) { + interfaceInfo = virtDBusGDBusLoadIntrospectData(VIRT_DBUS_STORAGEPOOL_INTERFACE, + error); + if (!interfaceInfo) + return; + } + + virtDBusGDBusRegisterSubtree(connect->bus, + connect->storagePoolPath, + interfaceInfo, + virtDBusStoragePoolEnumerate, + virtDBusStoragePoolMethodTable, + virtDBusStoragePoolPropertyTable, + connect); +} diff --git a/src/storagepool.h b/src/storagepool.h new file mode 100644 index 0000000..fb2bffb --- /dev/null +++ b/src/storagepool.h @@ -0,0 +1,9 @@ +#pragma once + +#include "connect.h" + +#define VIRT_DBUS_STORAGEPOOL_INTERFACE "org.libvirt.StoragePool" + +void +virtDBusStoragePoolRegister(virtDBusConnect *connect, + GError **error); diff --git a/src/util.c b/src/util.c index 548fac8..e90be3b 100644 --- a/src/util.c +++ b/src/util.c @@ -255,3 +255,36 @@ virtDBusUtilStringListFree(virtDBusCharArray *item) g_free(item); } + +virStoragePoolPtr +virtDBusUtilVirStoragePoolFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *storagePoolPath) +{ + g_autofree gchar *name = NULL; + gsize prefixLen = strlen(storagePoolPath) + 1; + + name = virtDBusUtilDecodeUUID(path + prefixLen); + + return virStoragePoolLookupByUUIDString(connection, name); +} + +gchar * +virtDBusUtilBusPathForVirStoragePool(virStoragePoolPtr storagePool, + const gchar *storagePoolPath) +{ + gchar uuid[VIR_UUID_STRING_BUFLEN] = ""; + g_autofree gchar *newUuid = NULL; + virStoragePoolGetUUIDString(storagePool, uuid); + newUuid = virtDBusUtilEncodeUUID(uuid); + return g_strdup_printf("%s/%s", storagePoolPath, newUuid); +} + +void +virtDBusUtilVirStoragePoolListFree(virStoragePoolPtr *storagePools) +{ + for (gint i = 0; storagePools[i] != NULL; i++) + virStoragePoolFree(storagePools[i]); + + g_free(storagePools); +} diff --git a/src/util.h b/src/util.h index 3309803..d932b66 100644 --- a/src/util.h +++ b/src/util.h @@ -78,3 +78,19 @@ void virtDBusUtilStringListFree(virtDBusCharArray *item); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virtDBusCharArray, virtDBusUtilStringListFree); + +virStoragePoolPtr +virtDBusUtilVirStoragePoolFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *storagePoolPath); + +gchar * +virtDBusUtilBusPathForVirStoragePool(virStoragePoolPtr storagePool, + const gchar *storagePoolPath); + +void +virtDBusUtilVirStoragePoolListFree(virStoragePoolPtr *storagePools); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePool, virStoragePoolFree); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePoolPtr, + virtDBusUtilVirStoragePoolListFree); -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 40 ++++++++++++++++++++++++++++++++++++++++ tests/test_connect.py | 12 ++++++++++++ 3 files changed, 58 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index a235872..9207295 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -145,6 +145,12 @@ <arg name="flags" type="u" direction="in"/> <arg name="networks" type="ao" direction="out"/> </method> + <method name="ListStoragePools"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectListAllStoragePools"/> + <arg name="flags" type="u" direction="in"/> + <arg name="storagePools" type="ao" direction="out"/> + </method> <method name="NetworkCreateXML"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkCreateXML"/> diff --git a/src/connect.c b/src/connect.c index e838e98..858db43 100644 --- a/src/connect.c +++ b/src/connect.c @@ -709,6 +709,45 @@ virtDBusConnectListNetworks(GVariant *inArgs, *outArgs = g_variant_new_tuple(&gnetworks, 1); } +static void +virtDBusConnectListStoragePools(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(virStoragePoolPtr) storagePools = NULL; + guint flags; + GVariantBuilder builder; + GVariant *gstoragePools; + + g_variant_get(inArgs, "(u)", &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + if (virConnectListAllStoragePools(connect->connection, &storagePools, + flags) < 0) { + return virtDBusUtilSetLastVirtError(error); + } + + g_variant_builder_init(&builder, G_VARIANT_TYPE("ao")); + + for (gint i = 0; storagePools[i]; i++) { + g_autofree gchar *path = NULL; + path = virtDBusUtilBusPathForVirStoragePool(storagePools[i], + connect->storagePoolPath); + + g_variant_builder_add(&builder, "o", path); + } + + gstoragePools = g_variant_builder_end(&builder); + *outArgs = g_variant_new_tuple(&gstoragePools, 1); +} + static void virtDBusConnectNetworkCreateXML(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1082,6 +1121,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "GetSysinfo", virtDBusConnectGetSysinfo }, { "ListDomains", virtDBusConnectListDomains }, { "ListNetworks", virtDBusConnectListNetworks }, + { "ListStoragePools", virtDBusConnectListStoragePools }, { "NetworkCreateXML", virtDBusConnectNetworkCreateXML }, { "NetworkDefineXML", virtDBusConnectNetworkDefineXML }, { "NetworkLookupByName", virtDBusConnectNetworkLookupByName }, diff --git a/tests/test_connect.py b/tests/test_connect.py index 3eeecb9..d8f05e8 100755 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -126,6 +126,18 @@ class TestConnect(libvirttest.BaseTestClass): arch = "x86_64" assert isinstance(self.connect.GetCPUModelNames(arch, 0), dbus.Array) + def test_connect_list_storage_pools(self): + storage_pools = self.connect.ListStoragePools(0) + assert isinstance(storage_pools, dbus.Array) + assert len(storage_pools) == 1 + + for path in storage_pools: + assert isinstance(path, dbus.ObjectPath) + storage_pool = self.bus.get_object('org.libvirt', path) + + # ensure the path exists by calling Introspect on it + storage_pool.Introspect(dbus_interface=dbus.INTROSPECTABLE_IFACE) + def test_connect_network_create_xml(self): def network_started(path, event): if event != libvirttest.NetworkEvent.STARTED: -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 7 +++++++ src/connect.c | 13 +++++++++++++ src/connect.h | 1 + src/events.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 9207295..6b156d1 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -230,5 +230,12 @@ <arg name="network" type="o"/> <arg name="event" type="u"/> </signal> + <signal name="StoragePoolEvent"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectStoragePoolEventLifecycleCallback"/> + <arg name="storagePool" type="o"/> + <arg name="event" type="u"/> + <arg name="detail" type="u"/> + </signal> </interface> </node> diff --git a/src/connect.c b/src/connect.c index 858db43..97c4857 100644 --- a/src/connect.c +++ b/src/connect.c @@ -60,6 +60,16 @@ virtDBusConnectClose(virtDBusConnect *connect, } } + for (gint i = 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++) { + if (connect->storagePoolCallbackIds[i] >= 0) { + if (deregisterEvents) { + virConnectStoragePoolEventDeregisterAny(connect->connection, + connect->storagePoolCallbackIds[i]); + } + connect->storagePoolCallbackIds[i] = -1; + } + } + virConnectClose(connect->connection); connect->connection = NULL; } @@ -1177,6 +1187,9 @@ virtDBusConnectNew(virtDBusConnect **connectp, for (gint i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) connect->networkCallbackIds[i] = -1; + for (gint i = 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++) + connect->storagePoolCallbackIds[i] = -1; + connect->bus = bus; connect->uri = uri; connect->connectPath = connectPath; diff --git a/src/connect.h b/src/connect.h index d6c3830..b4df048 100644 --- a/src/connect.h +++ b/src/connect.h @@ -20,6 +20,7 @@ struct virtDBusConnect { gint domainCallbackIds[VIR_DOMAIN_EVENT_ID_LAST]; gint networkCallbackIds[VIR_NETWORK_EVENT_ID_LAST]; + gint storagePoolCallbackIds[VIR_STORAGE_POOL_EVENT_ID_LAST]; }; typedef struct virtDBusConnect virtDBusConnect; diff --git a/src/events.c b/src/events.c index ea55180..04967c2 100644 --- a/src/events.c +++ b/src/events.c @@ -143,6 +143,30 @@ virtDBusEventsNetworkLifecycle(virConnectPtr connection G_GNUC_UNUSED, return 0; } +static gint +virtDBusEventsStoragePoolLifecycle(virConnectPtr connection G_GNUC_UNUSED, + virStoragePoolPtr storagePool, + gint event, + gint detail, + gpointer opaque) +{ + virtDBusConnect *connect = opaque; + g_autofree gchar *path = NULL; + + path = virtDBusUtilBusPathForVirStoragePool(storagePool, + connect->storagePoolPath); + + g_dbus_connection_emit_signal(connect->bus, + NULL, + connect->connectPath, + VIRT_DBUS_CONNECT_INTERFACE, + "StoragePoolEvent", + g_variant_new("(ouu)", path, event, detail), + NULL); + + return 0; +} + static void virtDBusEventsRegisterDomainEvent(virtDBusConnect *connect, gint id, @@ -173,6 +197,21 @@ virtDBusEventsRegisterNetworkEvent(virtDBusConnect *connect, NULL); } +static void +virtDBusEventsRegisterStoragePoolEvent(virtDBusConnect *connect, + gint id, + virConnectStoragePoolEventGenericCallback callback) +{ + g_assert(connect->storagePoolCallbackIds[id] == -1); + + connect->storagePoolCallbackIds[id] = virConnectStoragePoolEventRegisterAny(connect->connection, + NULL, + id, + VIR_STORAGE_POOL_EVENT_CALLBACK(callback), + connect, + NULL); +} + void virtDBusEventsRegister(virtDBusConnect *connect) { @@ -199,4 +238,8 @@ virtDBusEventsRegister(virtDBusConnect *connect) virtDBusEventsRegisterNetworkEvent(connect, VIR_NETWORK_EVENT_ID_LIFECYCLE, VIR_NETWORK_EVENT_CALLBACK(virtDBusEventsNetworkLifecycle)); + + virtDBusEventsRegisterStoragePoolEvent(connect, + VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE, + VIR_STORAGE_POOL_EVENT_CALLBACK(virtDBusEventsStoragePoolLifecycle)); } -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@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#virStoragePoolDestroy"/> + </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

VIR_STORAGE_POOL_EVENT_CREATED event was added in 3.1. Test should be fixed later on to use signal handler. Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 5 +++++ src/storagepool.c | 25 +++++++++++++++++++++++++ tests/libvirttest.py | 8 ++++++++ tests/test_storage.py | 8 +++++++- 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index ac628d9..f96e676 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -3,6 +3,11 @@ <node name="/org/libvirt/storagepool"> <interface name="org.libvirt.StoragePool"> + <method name="Build"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolBuild"/> + <arg name="flags" type="u" direction="in"/> + </method> <method name="Destroy"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolDestroy"/> diff --git a/src/storagepool.c b/src/storagepool.c index 5202f9e..d23c847 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -24,6 +24,30 @@ virtDBusStoragePoolGetVirStoragePool(virtDBusConnect *connect, return storagePool; } +static void +virtDBusStoragePoolBuild(GVariant *inArgs, + 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; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + if (virStoragePoolBuild(storagePool, flags) < 0) + virtDBusUtilSetLastVirtError(error); +} + static void virtDBusStoragePoolDestroy(GVariant *inArgs G_GNUC_UNUSED, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -50,6 +74,7 @@ static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = { }; static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { + { "Build", virtDBusStoragePoolBuild }, { "Destroy", virtDBusStoragePoolDestroy }, { 0 } }; diff --git a/tests/libvirttest.py b/tests/libvirttest.py index e88484f..3cd02ef 100644 --- a/tests/libvirttest.py +++ b/tests/libvirttest.py @@ -187,6 +187,14 @@ class NetworkEvent(IntEnum): STOPPED = 3 +class StoragePoolBuildFlags(IntEnum): + NEW = 0 + REPAIR = 1 + RESIZE = 2 + NO_OVERWRITE = 4 + OVERWRITE = 8 + + class StoragePoolEvent(IntEnum): DEFINED = 0 UNDEFINED = 1 diff --git a/tests/test_storage.py b/tests/test_storage.py index 8c5d75f..cf13024 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -4,6 +4,13 @@ import dbus import libvirttest class TestStoragePool(libvirttest.BaseTestClass): + def test_storage_pool_build(self): + _, test_storage_pool = self.test_storage_pool() + interface_obj = dbus.Interface(test_storage_pool, + 'org.libvirt.StoragePool') + interface_obj.Destroy() + interface_obj.Build(libvirttest.StoragePoolBuildFlags.NEW) + def test_storage_pool_destroy(self): def storage_pool_destroyed(path, event, _detail): if event != libvirttest.StoragePoolEvent.STOPPED: @@ -13,7 +20,6 @@ class TestStoragePool(libvirttest.BaseTestClass): 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') -- 2.15.0

On Mon, May 07, 2018 at 04:40:46PM +0200, Katerina Koukiou wrote:
VIR_STORAGE_POOL_EVENT_CREATED event was added in 3.1. Test should be fixed later on to use signal handler.
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 5 +++++ src/storagepool.c | 25 +++++++++++++++++++++++++ tests/libvirttest.py | 8 ++++++++ tests/test_storage.py | 8 +++++++- 4 files changed, 45 insertions(+), 1 deletion(-)
[...]
diff --git a/tests/test_storage.py b/tests/test_storage.py index 8c5d75f..cf13024 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -4,6 +4,13 @@ import dbus import libvirttest
class TestStoragePool(libvirttest.BaseTestClass): + def test_storage_pool_build(self): + _, test_storage_pool = self.test_storage_pool() + interface_obj = dbus.Interface(test_storage_pool, + 'org.libvirt.StoragePool') + interface_obj.Destroy() + interface_obj.Build(libvirttest.StoragePoolBuildFlags.NEW) + def test_storage_pool_destroy(self): def storage_pool_destroyed(path, event, _detail): if event != libvirttest.StoragePoolEvent.STOPPED: @@ -13,7 +20,6 @@ class TestStoragePool(libvirttest.BaseTestClass):
self.connect.connect_to_signal('StoragePoolEvent', storage_pool_destroyed) -
Unrelated line removal. Pavel

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 5 +++++ src/storagepool.c | 25 +++++++++++++++++++++++++ tests/test_storage.py | 17 +++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index f96e676..7e837c0 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -8,6 +8,11 @@ value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolBuild"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="Create"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolCreate"/> + <arg name="flags" type="u" direction="in"/> + </method> <method name="Destroy"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolDestroy"/> diff --git a/src/storagepool.c b/src/storagepool.c index d23c847..d4cd7a7 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -48,6 +48,30 @@ virtDBusStoragePoolBuild(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusStoragePoolCreate(GVariant *inArgs, + 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; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + if (virStoragePoolCreate(storagePool, flags) < 0) + virtDBusUtilSetLastVirtError(error); +} + static void virtDBusStoragePoolDestroy(GVariant *inArgs G_GNUC_UNUSED, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -75,6 +99,7 @@ static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = { static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { { "Build", virtDBusStoragePoolBuild }, + { "Create", virtDBusStoragePoolCreate }, { "Destroy", virtDBusStoragePoolDestroy }, { 0 } }; diff --git a/tests/test_storage.py b/tests/test_storage.py index cf13024..b1927cb 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -11,6 +11,23 @@ class TestStoragePool(libvirttest.BaseTestClass): interface_obj.Destroy() interface_obj.Build(libvirttest.StoragePoolBuildFlags.NEW) + def test_storage_pool_create(self): + def storage_pool_started(path, event, _detail): + if event != libvirttest.StoragePoolEvent.STARTED: + return + assert isinstance(path, dbus.ObjectPath) + self.loop.quit() + + self.connect.connect_to_signal('StoragePoolEvent', storage_pool_started) + + _, test_storage_pool = self.test_storage_pool() + interface_obj = dbus.Interface(test_storage_pool, + 'org.libvirt.StoragePool') + interface_obj.Destroy() + interface_obj.Create(0) + + self.main_loop() + def test_storage_pool_destroy(self): def storage_pool_destroyed(path, event, _detail): if event != libvirttest.StoragePoolEvent.STOPPED: -- 2.15.0

VIR_STORAGE_POOL_EVENT_DELETED event was added in 3.1. Test should be fixed later on to use signal handler. Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 5 +++++ src/storagepool.c | 25 +++++++++++++++++++++++++ tests/test_storage.py | 7 +++++++ 3 files changed, 37 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index 7e837c0..fb21e59 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -13,6 +13,11 @@ value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolCreate"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="Delete"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolDelete"/> + <arg name="flags" type="u" direction="in"/> + </method> <method name="Destroy"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolDestroy"/> diff --git a/src/storagepool.c b/src/storagepool.c index d4cd7a7..bf1fd3f 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -72,6 +72,30 @@ virtDBusStoragePoolCreate(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusStoragePoolDelete(GVariant *inArgs, + 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; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + if (virStoragePoolDelete(storagePool, flags) < 0) + virtDBusUtilSetLastVirtError(error); +} + static void virtDBusStoragePoolDestroy(GVariant *inArgs G_GNUC_UNUSED, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -100,6 +124,7 @@ static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = { static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { { "Build", virtDBusStoragePoolBuild }, { "Create", virtDBusStoragePoolCreate }, + { "Delete", virtDBusStoragePoolDelete }, { "Destroy", virtDBusStoragePoolDestroy }, { 0 } }; diff --git a/tests/test_storage.py b/tests/test_storage.py index b1927cb..c4c7cf1 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -28,6 +28,13 @@ class TestStoragePool(libvirttest.BaseTestClass): self.main_loop() + def test_storage_pool_delete(self): + _, test_storage_pool = self.test_storage_pool() + interface_obj = dbus.Interface(test_storage_pool, + 'org.libvirt.StoragePool') + interface_obj.Destroy() + interface_obj.Delete(0) + def test_storage_pool_destroy(self): def storage_pool_destroyed(path, event, _detail): if event != libvirttest.StoragePoolEvent.STOPPED: -- 2.15.0

Most of the properties will not emit signals when changed, thus making the annotation EmitsChangedSignal->false global for this Interface. Properties with different behavior will overwrite it. Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 5 +++++ src/storagepool.c | 22 ++++++++++++++++++++++ tests/test_storage.py | 7 +++++++ 3 files changed, 34 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index fb21e59..ed03474 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -3,6 +3,11 @@ <node name="/org/libvirt/storagepool"> <interface name="org.libvirt.StoragePool"> + <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="false"/> + <property name="Autostart" type="b" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetAutostart"/> + </property> <method name="Build"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolBuild"/> diff --git a/src/storagepool.c b/src/storagepool.c index bf1fd3f..515b38c 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -24,6 +24,27 @@ virtDBusStoragePoolGetVirStoragePool(virtDBusConnect *connect, return storagePool; } +static void +virtDBusStoragePoolGetAutostart(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePool) storagePool = NULL; + gint autostart = 0; + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + if (virStoragePoolGetAutostart(storagePool, &autostart) < 0) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("b", !!autostart); +} + static void virtDBusStoragePoolBuild(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -118,6 +139,7 @@ virtDBusStoragePoolDestroy(GVariant *inArgs G_GNUC_UNUSED, } static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = { + { "Autostart", virtDBusStoragePoolGetAutostart, NULL }, { 0 } }; diff --git a/tests/test_storage.py b/tests/test_storage.py index c4c7cf1..0aa75e3 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -51,6 +51,13 @@ class TestStoragePool(libvirttest.BaseTestClass): self.main_loop() + def test_storage_pool_properties_type(self): + _, obj = self.test_storage_pool() + + props = obj.GetAll('org.libvirt.StoragePool', + dbus_interface=dbus.PROPERTIES_IFACE) + assert isinstance(props['Autostart'], dbus.Boolean) + if __name__ == '__main__': libvirttest.run() -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 5 +++++ src/storagepool.c | 28 ++++++++++++++++++++++++++++ tests/test_storage.py | 7 +++++++ 3 files changed, 40 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index ed03474..29d501b 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -27,5 +27,10 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolDestroy"/> </method> + <method name="GetInfo"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetInfo"/> + <arg name="info" type="(uttt)" direction="out"/> + </method> </interface> </node> diff --git a/src/storagepool.c b/src/storagepool.c index 515b38c..a7bcc94 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -138,6 +138,33 @@ virtDBusStoragePoolDestroy(GVariant *inArgs G_GNUC_UNUSED, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusStoragePoolGetInfo(GVariant *inArgs G_GNUC_UNUSED, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePool) storagePool = NULL; + g_autofree virStoragePoolInfoPtr info = NULL; + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + info = g_new0(virStoragePoolInfo, 1); + if (virStoragePoolGetInfo(storagePool, info) < 0) + return virtDBusUtilSetLastVirtError(error); + + *outArgs = g_variant_new("((uttt))", info->state, + info->capacity, info->allocation, + info->available); +} + static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = { { "Autostart", virtDBusStoragePoolGetAutostart, NULL }, { 0 } @@ -148,6 +175,7 @@ static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { { "Create", virtDBusStoragePoolCreate }, { "Delete", virtDBusStoragePoolDelete }, { "Destroy", virtDBusStoragePoolDestroy }, + { "GetInfo", virtDBusStoragePoolGetInfo }, { 0 } }; diff --git a/tests/test_storage.py b/tests/test_storage.py index 0aa75e3..116385b 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -51,6 +51,13 @@ class TestStoragePool(libvirttest.BaseTestClass): self.main_loop() + def test_storage_pool_get_info(self): + _, test_storage_pool = self.test_storage_pool() + interface_obj = dbus.Interface(test_storage_pool, + 'org.libvirt.StoragePool') + info = interface_obj.GetInfo() + assert isinstance(info, dbus.Struct) + def test_storage_pool_properties_type(self): _, obj = self.test_storage_pool() -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 4 ++++ src/storagepool.c | 23 +++++++++++++++++++++++ tests/test_storage.py | 1 + 3 files changed, 28 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index 29d501b..8bc90b7 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -8,6 +8,10 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetAutostart"/> </property> + <property name="Name" type="s" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetName"/> + </property> <method name="Build"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolBuild"/> diff --git a/src/storagepool.c b/src/storagepool.c index a7bcc94..f81a670 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -45,6 +45,28 @@ virtDBusStoragePoolGetAutostart(const gchar *objectPath, *value = g_variant_new("b", !!autostart); } +static void +virtDBusStoragePoolGetName(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePool) storagePool = NULL; + const gchar *name; + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + name = virStoragePoolGetName(storagePool); + if (!name) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("s", name); +} + static void virtDBusStoragePoolBuild(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -167,6 +189,7 @@ virtDBusStoragePoolGetInfo(GVariant *inArgs G_GNUC_UNUSED, static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = { { "Autostart", virtDBusStoragePoolGetAutostart, NULL }, + { "Name", virtDBusStoragePoolGetName, NULL }, { 0 } }; diff --git a/tests/test_storage.py b/tests/test_storage.py index 116385b..8e73228 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -64,6 +64,7 @@ class TestStoragePool(libvirttest.BaseTestClass): props = obj.GetAll('org.libvirt.StoragePool', dbus_interface=dbus.PROPERTIES_IFACE) assert isinstance(props['Autostart'], dbus.Boolean) + assert isinstance(props['Name'], dbus.String) if __name__ == '__main__': -- 2.15.0

On Mon, May 07, 2018 at 04:40:51PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 4 ++++ src/storagepool.c | 23 +++++++++++++++++++++++ tests/test_storage.py | 1 + 3 files changed, 28 insertions(+)
diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index 29d501b..8bc90b7 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -8,6 +8,10 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetAutostart"/> </property> + <property name="Name" type="s" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetName"/> + </property>
This should be annotated as 'const' because there is no API to change the name. The only way is to undefine it and define it again. Pavel

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 5 +++++ src/storagepool.c | 22 ++++++++++++++++++++++ tests/test_storage.py | 1 + 3 files changed, 28 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index 8bc90b7..a60ef84 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -12,6 +12,11 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetName"/> </property> + <property name="UUID" type="s" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetUUIDString"/> + <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> + </property> <method name="Build"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolBuild"/> diff --git a/src/storagepool.c b/src/storagepool.c index f81a670..43e8040 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -67,6 +67,27 @@ virtDBusStoragePoolGetName(const gchar *objectPath, *value = g_variant_new("s", name); } +static void +virtDBusStoragePoolGetUUID(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePool) storagePool = NULL; + gchar uuid[VIR_UUID_STRING_BUFLEN] = ""; + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + if (virStoragePoolGetUUIDString(storagePool, uuid) < 0) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("s", uuid); +} + static void virtDBusStoragePoolBuild(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -190,6 +211,7 @@ virtDBusStoragePoolGetInfo(GVariant *inArgs G_GNUC_UNUSED, static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = { { "Autostart", virtDBusStoragePoolGetAutostart, NULL }, { "Name", virtDBusStoragePoolGetName, NULL }, + { "UUID", virtDBusStoragePoolGetUUID, NULL }, { 0 } }; diff --git a/tests/test_storage.py b/tests/test_storage.py index 8e73228..3e67633 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -65,6 +65,7 @@ class TestStoragePool(libvirttest.BaseTestClass): dbus_interface=dbus.PROPERTIES_IFACE) assert isinstance(props['Autostart'], dbus.Boolean) assert isinstance(props['Name'], dbus.String) + assert isinstance(props['UUID'], dbus.String) if __name__ == '__main__': -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 6 ++++++ src/storagepool.c | 29 +++++++++++++++++++++++++++++ tests/test_storage.py | 7 +++++++ 3 files changed, 42 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index a60ef84..50550ee 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -41,5 +41,11 @@ value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetInfo"/> <arg name="info" type="(uttt)" direction="out"/> </method> + <method name="GetXMLDesc"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetXMLDesc"/> + <arg name="flags" type="u" direction="in"/> + <arg name="xml" type="s" direction="out"/> + </method> </interface> </node> diff --git a/src/storagepool.c b/src/storagepool.c index 43e8040..628ad17 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -208,6 +208,34 @@ virtDBusStoragePoolGetInfo(GVariant *inArgs G_GNUC_UNUSED, info->available); } +static void +virtDBusStoragePoolGetXMLDesc(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePool) storagePool = NULL; + g_autofree gchar *xml = NULL; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + xml = virStoragePoolGetXMLDesc(storagePool, flags); + if (!xml) + return virtDBusUtilSetLastVirtError(error); + + *outArgs = g_variant_new("(s)", xml); +} + static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = { { "Autostart", virtDBusStoragePoolGetAutostart, NULL }, { "Name", virtDBusStoragePoolGetName, NULL }, @@ -221,6 +249,7 @@ static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { { "Delete", virtDBusStoragePoolDelete }, { "Destroy", virtDBusStoragePoolDestroy }, { "GetInfo", virtDBusStoragePoolGetInfo }, + { "GetXMLDesc", virtDBusStoragePoolGetXMLDesc }, { 0 } }; diff --git a/tests/test_storage.py b/tests/test_storage.py index 3e67633..1afae2a 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -58,6 +58,13 @@ class TestStoragePool(libvirttest.BaseTestClass): info = interface_obj.GetInfo() assert isinstance(info, dbus.Struct) + def test_storage_pool_get_xml_description(self): + _, test_storage_pool = self.test_storage_pool() + interface_obj = dbus.Interface(test_storage_pool, + 'org.libvirt.StoragePool') + info = interface_obj.GetXMLDesc(0) + assert isinstance(info, dbus.String) + def test_storage_pool_properties_type(self): _, obj = self.test_storage_pool() -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 4 ++++ src/storagepool.c | 23 +++++++++++++++++++++++ tests/test_storage.py | 1 + 3 files changed, 28 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index 50550ee..b739841 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -4,6 +4,10 @@ <node name="/org/libvirt/storagepool"> <interface name="org.libvirt.StoragePool"> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="false"/> + <property name="Active" type="b" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolIsActive"/> + </property> <property name="Autostart" type="b" access="read"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetAutostart"/> diff --git a/src/storagepool.c b/src/storagepool.c index 628ad17..834e1c5 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -24,6 +24,28 @@ virtDBusStoragePoolGetVirStoragePool(virtDBusConnect *connect, return storagePool; } +static void +virtDBusStoragePoolGetActive(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePool) storagePool = NULL; + gint active; + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + active = virStoragePoolIsActive(storagePool); + if (active < 0) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("b", !!active); +} + static void virtDBusStoragePoolGetAutostart(const gchar *objectPath, gpointer userData, @@ -237,6 +259,7 @@ virtDBusStoragePoolGetXMLDesc(GVariant *inArgs, } static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = { + { "Active", virtDBusStoragePoolGetActive, NULL }, { "Autostart", virtDBusStoragePoolGetAutostart, NULL }, { "Name", virtDBusStoragePoolGetName, NULL }, { "UUID", virtDBusStoragePoolGetUUID, NULL }, diff --git a/tests/test_storage.py b/tests/test_storage.py index 1afae2a..34838fc 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -70,6 +70,7 @@ class TestStoragePool(libvirttest.BaseTestClass): props = obj.GetAll('org.libvirt.StoragePool', dbus_interface=dbus.PROPERTIES_IFACE) + assert isinstance(props['Active'], dbus.Boolean) assert isinstance(props['Autostart'], dbus.Boolean) assert isinstance(props['Name'], dbus.String) assert isinstance(props['UUID'], dbus.String) -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 4 ++++ src/storagepool.c | 23 +++++++++++++++++++++++ tests/test_storage.py | 1 + 3 files changed, 28 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index b739841..31abd34 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -16,6 +16,10 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetName"/> </property> + <property name="Persistent" type="b" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolIsPersistent"/> + </property> <property name="UUID" type="s" access="read"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetUUIDString"/> diff --git a/src/storagepool.c b/src/storagepool.c index 834e1c5..c38e029 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -89,6 +89,28 @@ virtDBusStoragePoolGetName(const gchar *objectPath, *value = g_variant_new("s", name); } +static void +virtDBusStoragePoolGetPersistent(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePool) storagePool = NULL; + gint persistent; + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + persistent = virStoragePoolIsPersistent(storagePool); + if (persistent < 0) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("b", !!persistent); +} + static void virtDBusStoragePoolGetUUID(const gchar *objectPath, gpointer userData, @@ -262,6 +284,7 @@ static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = { { "Active", virtDBusStoragePoolGetActive, NULL }, { "Autostart", virtDBusStoragePoolGetAutostart, NULL }, { "Name", virtDBusStoragePoolGetName, NULL }, + { "Persistent", virtDBusStoragePoolGetPersistent, NULL }, { "UUID", virtDBusStoragePoolGetUUID, NULL }, { 0 } }; diff --git a/tests/test_storage.py b/tests/test_storage.py index 34838fc..b872c3d 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -73,6 +73,7 @@ class TestStoragePool(libvirttest.BaseTestClass): assert isinstance(props['Active'], dbus.Boolean) assert isinstance(props['Autostart'], dbus.Boolean) assert isinstance(props['Name'], dbus.String) + assert isinstance(props['Persistent'], dbus.Boolean) assert isinstance(props['UUID'], dbus.String) -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@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

On Mon, May 07, 2018 at 04:40:56PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@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):
The function name is not correct, it should say 'storage_pool'. I don't like this style :) how about: def test_connect_storage_pool_lookup_by_property(self, lookup_method_name, lookup_item): Pavel

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 31 +++++++++++++++++++++++++++++++ tests/test_connect.py | 1 + 3 files changed, 38 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 55c0883..0c009cd 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -223,6 +223,12 @@ <arg name="name" type="s" direction="in"/> <arg name="storagePool" type="o" direction="out"/> </method> + <method name="StoragePoolLookupByUUID"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolLookupByUUIDString"/> + <arg name="uuid" 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 fa4078f..43013a2 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1133,6 +1133,36 @@ virtDBusConnectStoragePoolLookupByName(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); } +static void +virtDBusConnectStoragePoolLookupByUUID(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 *uuidstr; + + g_variant_get(inArgs, "(s)", &uuidstr); + + if (!virtDBusConnectOpen(connect, error)) + return; + + storagePool = virStoragePoolLookupByUUIDString(connect->connection, + uuidstr); + 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 }, @@ -1173,6 +1203,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NodeGetSecurityModel", virtDBusConnectNodeGetSecurityModel }, { "NodeSetMemoryParameters", virtDBusConnectNodeSetMemoryParameters }, { "StoragePoolLookupByName", virtDBusConnectStoragePoolLookupByName }, + { "StoragePoolLookupByUUID", virtDBusConnectStoragePoolLookupByUUID }, { 0 } }; diff --git a/tests/test_connect.py b/tests/test_connect.py index 2e0cd7f..c0365ae 100755 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -192,6 +192,7 @@ class TestConnect(libvirttest.BaseTestClass): @pytest.mark.parametrize("lookup_method_name,lookup_item", [ ("StoragePoolLookupByName", 'Name'), + ("StoragePoolLookupByUUID", 'UUID'), ]) def test_connect_network_lookup_by_property( self, -- 2.15.0

Test will should be added when VIR_STORAGE_POOL_EVENT_ID_REFRESH signal will be implemented. Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 5 +++++ src/storagepool.c | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index 31abd34..8ebab33 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -55,5 +55,10 @@ <arg name="flags" type="u" direction="in"/> <arg name="xml" type="s" direction="out"/> </method> + <method name="Refresh"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolRefresh"/> + <arg name="flags" type="u" direction="in"/> + </method> </interface> </node> diff --git a/src/storagepool.c b/src/storagepool.c index c38e029..aa0e280 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -280,6 +280,30 @@ virtDBusStoragePoolGetXMLDesc(GVariant *inArgs, *outArgs = g_variant_new("(s)", xml); } +static void +virtDBusStoragePoolRefresh(GVariant *inArgs, + 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; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + if (virStoragePoolRefresh(storagePool, flags) < 0) + virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = { { "Active", virtDBusStoragePoolGetActive, NULL }, { "Autostart", virtDBusStoragePoolGetAutostart, NULL }, @@ -296,6 +320,7 @@ static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { { "Destroy", virtDBusStoragePoolDestroy }, { "GetInfo", virtDBusStoragePoolGetInfo }, { "GetXMLDesc", virtDBusStoragePoolGetXMLDesc }, + { "Refresh", virtDBusStoragePoolRefresh }, { 0 } }; -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 5 +++-- src/storagepool.c | 24 +++++++++++++++++++++++- tests/test_storage.py | 13 +++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index 8ebab33..9d59818 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -8,9 +8,10 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolIsActive"/> </property> - <property name="Autostart" type="b" access="read"> + <property name="Autostart" type="b" access="readwrite"> <annotation name="org.gtk.GDBus.DocString" - value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetAutostart"/> + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetAutos... + https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolSetAutostart"/> </property> <property name="Name" type="s" access="read"> <annotation name="org.gtk.GDBus.DocString" diff --git a/src/storagepool.c b/src/storagepool.c index aa0e280..a40db14 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -132,6 +132,27 @@ virtDBusStoragePoolGetUUID(const gchar *objectPath, *value = g_variant_new("s", uuid); } +static void +virtDBusStoragePoolSetAutostart(GVariant *value, + const gchar *objectPath, + gpointer userData, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePool) storagePool = NULL; + gboolean autostart; + + g_variant_get(value, "b", &autostart); + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + if (virStoragePoolSetAutostart(storagePool, autostart) < 0) + virtDBusUtilSetLastVirtError(error); +} + static void virtDBusStoragePoolBuild(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -306,7 +327,8 @@ virtDBusStoragePoolRefresh(GVariant *inArgs, static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = { { "Active", virtDBusStoragePoolGetActive, NULL }, - { "Autostart", virtDBusStoragePoolGetAutostart, NULL }, + { "Autostart", virtDBusStoragePoolGetAutostart, + virtDBusStoragePoolSetAutostart }, { "Name", virtDBusStoragePoolGetName, NULL }, { "Persistent", virtDBusStoragePoolGetPersistent, NULL }, { "UUID", virtDBusStoragePoolGetUUID, NULL }, diff --git a/tests/test_storage.py b/tests/test_storage.py index b872c3d..2d87e08 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -4,6 +4,19 @@ import dbus import libvirttest class TestStoragePool(libvirttest.BaseTestClass): + def test_storage_pool_autostart(self): + _, test_storage_pool = self.test_storage_pool() + interface_obj = dbus.Interface(test_storage_pool, + 'org.libvirt.StoragePool') + autostart_expected = True + interface_obj.Set('org.libvirt.StoragePool', 'Autostart', + autostart_expected, + dbus_interface=dbus.PROPERTIES_IFACE) + autostart_current = interface_obj.Get('org.libvirt.StoragePool', + 'Autostart', + dbus_interface=dbus.PROPERTIES_IFACE) + assert autostart_current == dbus.Boolean(autostart_expected) + def test_storage_pool_build(self): _, test_storage_pool = self.test_storage_pool() interface_obj = dbus.Interface(test_storage_pool, -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 4 ++++ src/storagepool.c | 22 ++++++++++++++++++++++ tests/test_storage.py | 18 ++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index 9d59818..d7e19d0 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -61,5 +61,9 @@ value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolRefresh"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="Undefine"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolUndefine"/> + </method> </interface> </node> diff --git a/src/storagepool.c b/src/storagepool.c index a40db14..c8b6467 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -325,6 +325,27 @@ virtDBusStoragePoolRefresh(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusStoragePoolUndefine(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 (virStoragePoolUndefine(storagePool) < 0) + virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = { { "Active", virtDBusStoragePoolGetActive, NULL }, { "Autostart", virtDBusStoragePoolGetAutostart, @@ -343,6 +364,7 @@ static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { { "GetInfo", virtDBusStoragePoolGetInfo }, { "GetXMLDesc", virtDBusStoragePoolGetXMLDesc }, { "Refresh", virtDBusStoragePoolRefresh }, + { "Undefine", virtDBusStoragePoolUndefine }, { 0 } }; diff --git a/tests/test_storage.py b/tests/test_storage.py index 2d87e08..d2cbbb5 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -89,6 +89,24 @@ class TestStoragePool(libvirttest.BaseTestClass): assert isinstance(props['Persistent'], dbus.Boolean) assert isinstance(props['UUID'], dbus.String) + def test_storage_pool_undefine(self): + def storage_pool_undefined(path, event, _detail): + if event != libvirttest.StoragePoolEvent.UNDEFINED: + return + assert isinstance(path, dbus.ObjectPath) + self.loop.quit() + + self.connect.connect_to_signal('StoragePoolEvent', + storage_pool_undefined) + + _, test_storage_pool = self.test_storage_pool() + interface_obj = dbus.Interface(test_storage_pool, + 'org.libvirt.StoragePool') + interface_obj.Destroy() + interface_obj.Undefine() + + self.main_loop() + if __name__ == '__main__': libvirttest.run() -- 2.15.0

On Mon, May 07, 2018 at 04:40:41PM +0200, Katerina Koukiou wrote:
Katerina Koukiou (19): Introduce StoragePool Interface Implement ListStoragePools method for Connect Interface Register StoragePool Lifecycle Events Implement Destroy method for StoragePool Interface Implement Build method for StoragePool Interface Implement Create method for StoragePool Interface Implement Delete method for StoragePool Interface Implement getter for Autostart property for StoragePool Interface Implement GetInfo method for StoragePool Interface Implement Name property for StoragePool Interface Implement UUID property for StoragePool Interface Implement GetXMLDesc method for StoragePool Interface Implement Active property for StoragePool Interface Implement Persistent property for StoragePool Interface Implement StoragePoolLookupByName method for Connect Interface Implement StoragePoolLookupByUUID method for Connect Interface Implement Refresh method for StoragePool Interface Implement setter for Autostart property for StoragePool Interface Implement Undefine method for StoragePool Interface
See the notes for some patches, with the issues fixed Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
participants (2)
-
Katerina Koukiou
-
Pavel Hrdina