Commit 4c15fbce authored by Katerina Koukiou's avatar Katerina Koukiou

Implement StorageVolCreateXML method for StoragePool Interface

Signed-off-by: default avatarKaterina Koukiou <kkoukiou@redhat.com>
Reviewed-by: Pavel Hrdina's avatarPavel Hrdina <phrdina@redhat.com>
parent e2006d27
......@@ -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"/>
......
......@@ -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 }
};
......
......@@ -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
......
......@@ -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()
......@@ -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>
'''
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment