Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx> --- data/org.libvirt.StoragePool.xml | 7 +++++++ src/storagepool.c | 34 ++++++++++++++++++++++++++++++++++ tests/libvirttest.py | 31 +++++++++++++++++++++++++++++++ tests/test_storage.py | 3 +++ tests/xmldata.py | 10 ++++++++++ 5 files changed, 85 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index 764c9c1..51d65ab 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -68,6 +68,13 @@ value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolRefresh"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="StorageVolCreateXML"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolCreateXML"/> + <arg name="xml" type="s" direction="in"/> + <arg name="flags" type="u" direction="in"/> + <arg name="storageVol" type="o" direction="out"/> + </method> <method name="Undefine"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolUndefine"/> diff --git a/src/storagepool.c b/src/storagepool.c index 4f83ee2..cde9ec3 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -367,6 +367,39 @@ virtDBusStoragePoolRefresh(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusStoragePoolStorageVolCreateXML(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_autoptr(virStorageVol) storageVol = NULL; + gchar *xml; + guint flags; + g_autofree gchar *path = NULL; + + g_variant_get(inArgs, "(&su)", &xml, &flags); + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + storageVol = virStorageVolCreateXML(storagePool, xml, flags); + if (!storageVol) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirStorageVol(storageVol, + connect->storageVolPath); + + *outArgs = g_variant_new("(o)", path); +} + static void virtDBusStoragePoolUndefine(GVariant *inArgs G_GNUC_UNUSED, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -407,6 +440,7 @@ static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { { "GetXMLDesc", virtDBusStoragePoolGetXMLDesc }, { "ListStorageVolumes", virtDBusStoragePoolListStorageVolumes }, { "Refresh", virtDBusStoragePoolRefresh }, + { "StorageVolCreateXML", virtDBusStoragePoolStorageVolCreateXML }, { "Undefine", virtDBusStoragePoolUndefine }, { 0 } }; diff --git a/tests/libvirttest.py b/tests/libvirttest.py index 23a597f..6d1a9d0 100644 --- a/tests/libvirttest.py +++ b/tests/libvirttest.py @@ -7,6 +7,7 @@ import pytest import subprocess import sys import time +import xmldata root = os.environ.get('abs_top_builddir', os.path.dirname(os.path.dirname(__file__))) @@ -70,6 +71,20 @@ class BaseTestClass(): if self.timeout: raise TimeoutError() + @pytest.fixture + def storage_volume_create(self): + """ Fixture to create dummy storage volume on the test driver + + This fixture should be used in the setup of every test manipulating + with test volume. + """ + _, test_storage_pool = self.get_test_storage_pool() + interface_obj = dbus.Interface(test_storage_pool, + 'org.libvirt.StoragePool') + path = interface_obj.StorageVolCreateXML(xmldata.minimal_storage_vol_xml, 0) + yield path + + def get_test_domain(self): path = self.connect.ListDomains(0)[0] obj = self.bus.get_object('org.libvirt', path) @@ -100,6 +115,22 @@ class BaseTestClass(): obj = self.bus.get_object('org.libvirt', path) return path, obj + def get_test_storage_volume(self): + """Fetch information for the test storage vol from test driver + + Returns: + (dbus.proxies.ProxyObject, dbus.proxies.ProxyObject): + Test StorageVol Object, Local proxy for the test StorageVol + Object. + + """ + _, test_storage_pool = self.get_test_storage_pool() + pool_iface = dbus.Interface(test_storage_pool, + 'org.libvirt.StoragePool') + path = pool_iface.ListStorageVolumes(0)[0] + obj = self.bus.get_object('org.libvirt', path) + return path, obj + class DomainEvent(IntEnum): DEFINED = 0 diff --git a/tests/test_storage.py b/tests/test_storage.py index 10bcea3..2aefd74 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -126,6 +126,9 @@ class TestStoragePool(libvirttest.BaseTestClass): self.main_loop() + def test_storage_pool_volume_create(self, storage_volume_create): + assert isinstance(storage_volume_create, dbus.ObjectPath) + if __name__ == '__main__': libvirttest.run() diff --git a/tests/xmldata.py b/tests/xmldata.py index e42b6aa..926bd2c 100644 --- a/tests/xmldata.py +++ b/tests/xmldata.py @@ -35,3 +35,13 @@ minimal_storage_pool_xml = ''' </target> </pool> ''' + +minimal_storage_vol_xml = ''' +<volume> + <name>sparse.img</name> + <capacity unit="G">2</capacity> + <target> + <path>/var/lib/virt/images/sparse.img</path> + </target> +</volume> +''' -- 2.15.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list