Commit a83e2407 authored by Katerina Koukiou's avatar Katerina Koukiou

Implement Destroy method for NodeDevice Interface

Signed-off-by: 's avatarKaterina Koukiou <kkoukiou@redhat.com>
Reviewed-by: Pavel Hrdina's avatarPavel Hrdina <phrdina@redhat.com>
parent fe0d864b
......@@ -3,5 +3,9 @@
<node name="/org/libvirt/nodedev">
<interface name="org.libvirt.NodeDevice">
<method name="Destroy">
<annotation name="org.gtk.GDBus.DocString"
value="See https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDestroy"/>
</method>
</interface>
</node>
......@@ -3,11 +3,53 @@
#include <libvirt/libvirt.h>
static virNodeDevicePtr
virtDBusNodeDeviceGetVirNodeDevice(virtDBusConnect *connect,
const gchar *objectPath,
GError **error)
{
virNodeDevicePtr dev;
if (virtDBusConnectOpen(connect, error) < 0)
return NULL;
dev = virtDBusUtilVirNodeDeviceFromBusPath(connect->connection,
objectPath,
connect->nodeDevPath);
if (!dev) {
virtDBusUtilSetLastVirtError(error);
return NULL;
}
return dev;
}
static void
virtDBusNodeDeviceDestroy(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(virNodeDevice) dev = NULL;
dev = virtDBusNodeDeviceGetVirNodeDevice(connect, objectPath, error);
if (!dev)
return;
if (virNodeDeviceDestroy(dev) < 0)
virtDBusUtilSetLastVirtError(error);
}
static virtDBusGDBusPropertyTable virtDBusNodeDevicePropertyTable[] = {
{ 0 }
};
static virtDBusGDBusMethodTable virtDBusNodeDeviceMethodTable[] = {
{ "Destroy", virtDBusNodeDeviceDestroy },
{ 0 }
};
......
......@@ -7,6 +7,7 @@ test_programs = \
test_connect.py \
test_domain.py \
test_network.py \
test_nodedev.py \
test_storage.py
check_PROGRAMS = \
......
......@@ -71,6 +71,16 @@ class BaseTestClass():
if self.timeout:
raise TimeoutError()
@pytest.fixture
def node_device_create(self):
""" Fixture to create dummy node device on the test driver
This fixture should be used in the setup of every test manipulating
with node devices.
"""
path = self.connect.NodeDeviceCreateXML(xmldata.minimal_node_device_xml, 0)
return path
@pytest.fixture
def storage_volume_create(self):
""" Fixture to create dummy storage volume on the test driver
......
#!/usr/bin/env python3
import dbus
import libvirttest
import pytest
@pytest.mark.usefixtures("node_device_create")
class TestNodeDevice(libvirttest.BaseTestClass):
""" Tests for methods and properties of the NodeDevice interface
"""
def test_node_device_destroy(self):
def node_device_deleted(path, event, _detail):
if event != libvirttest.NodeDeviceEvent.DELETED:
return
assert isinstance(path, dbus.ObjectPath)
self.loop.quit()
self.connect.connect_to_signal('NodeDeviceEvent', node_device_deleted)
test_node_device_path = self.node_device_create()
obj = self.bus.get_object('org.libvirt', test_node_device_path)
interface_obj = dbus.Interface(obj, 'org.libvirt.NodeDevice')
interface_obj.Destroy()
self.main_loop()
if __name__ == '__main__':
libvirttest.run()
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