[libvirt] [dbus PATCH 05/14] Implement Destroy method for NodeDevice Interface

Katerina Koukiou kkoukiou at redhat.com
Fri Jun 15 17:03:41 UTC 2018


Signed-off-by: Katerina Koukiou <kkoukiou at redhat.com>
---

Some note about the test:

1: The previous test should not use the node_device_create fixture introduced here 
for the following reason:
The fixture is creating the device in the setup of the test since the
device creation is not supposed to be tested in other tests apart from
the CreateXML test. Only that test should not have the creation in the
setup, but in the actual test `call` part.

2: I didn't create the get_test_node_device function as other entities have
because ListNodeDevices method is not supported by the test driver

 data/org.libvirt.NodeDevice.xml |  4 ++++
 src/nodedev.c                   | 42 +++++++++++++++++++++++++++++++++++++++++
 tests/Makefile.am               |  1 +
 tests/libvirttest.py            | 10 ++++++++++
 tests/test_nodedev.py           | 31 ++++++++++++++++++++++++++++++
 5 files changed, 88 insertions(+)
 create mode 100755 tests/test_nodedev.py

diff --git a/data/org.libvirt.NodeDevice.xml b/data/org.libvirt.NodeDevice.xml
index 7ca26d0..4ca2e11 100644
--- a/data/org.libvirt.NodeDevice.xml
+++ b/data/org.libvirt.NodeDevice.xml
@@ -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>
diff --git a/src/nodedev.c b/src/nodedev.c
index 188df74..ec87bd8 100644
--- a/src/nodedev.c
+++ b/src/nodedev.c
@@ -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->devPath);
+    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 }
 };
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4cae303..e841627 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -7,6 +7,7 @@ test_programs = \
 	test_connect.py \
 	test_domain.py \
 	test_network.py \
+	test_nodedev.py \
 	test_storage.py
 
 check_PROGRAMS = \
diff --git a/tests/libvirttest.py b/tests/libvirttest.py
index 6b6cb4c..06e52c0 100644
--- a/tests/libvirttest.py
+++ b/tests/libvirttest.py
@@ -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
diff --git a/tests/test_nodedev.py b/tests/test_nodedev.py
new file mode 100755
index 0000000..8ef8e32
--- /dev/null
+++ b/tests/test_nodedev.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+
+import dbus
+import libvirttest
+import pytest
+
+
+ at 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()
-- 
2.15.0




More information about the libvir-list mailing list