From nobody Thu Jul 3 22:21:39 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1529082264174768.5138405198609; Fri, 15 Jun 2018 10:04:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B47CC0587F1; Fri, 15 Jun 2018 17:04:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 50F0210A33C3; Fri, 15 Jun 2018 17:04:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id EB77C1800536; Fri, 15 Jun 2018 17:04:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5FH3t3e029812 for ; Fri, 15 Jun 2018 13:03:55 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9DCE2202660C; Fri, 15 Jun 2018 17:03:55 +0000 (UTC) Received: from katerina.brq.redhat.com (unknown [10.43.2.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 424782026609 for ; Fri, 15 Jun 2018 17:03:55 +0000 (UTC) From: Katerina Koukiou To: libvirt-list@redhat.com Date: Fri, 15 Jun 2018 19:03:41 +0200 Message-Id: <20180615170350.20851-6-kkoukiou@redhat.com> In-Reply-To: <20180615170350.20851-1-kkoukiou@redhat.com> References: <20180615170350.20851-1-kkoukiou@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [dbus PATCH 05/14] Implement Destroy method for NodeDevice Interface X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 15 Jun 2018 17:04:23 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Katerina Koukiou Reviewed-by: Pavel Hrdina --- Some note about the test: 1: The previous test should not use the node_device_create fixture introduc= ed here=20 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 @@ =20 + + + 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 @@ =20 #include =20 +static virNodeDevicePtr +virtDBusNodeDeviceGetVirNodeDevice(virtDBusConnect *connect, + const gchar *objectPath, + GError **error) +{ + virNodeDevicePtr dev; + + if (virtDBusConnectOpen(connect, error) < 0) + return NULL; + + dev =3D 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 =3D userData; + g_autoptr(virNodeDevice) dev =3D NULL; + + dev =3D virtDBusNodeDeviceGetVirNodeDevice(connect, objectPath, error); + if (!dev) + return; + + if (virNodeDeviceDestroy(dev) < 0) + virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusNodeDevicePropertyTable[] =3D { { 0 } }; =20 static virtDBusGDBusMethodTable virtDBusNodeDeviceMethodTable[] =3D { + { "Destroy", virtDBusNodeDeviceDestroy }, { 0 } }; =20 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 =3D \ test_connect.py \ test_domain.py \ test_network.py \ + test_nodedev.py \ test_storage.py =20 check_PROGRAMS =3D \ 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() =20 + @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 =3D self.connect.NodeDeviceCreateXML(xmldata.minimal_node_dev= ice_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 + + +@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 !=3D libvirttest.NodeDeviceEvent.DELETED: + return + assert isinstance(path, dbus.ObjectPath) + self.loop.quit() + + self.connect.connect_to_signal('NodeDeviceEvent', node_device_dele= ted) + + test_node_device_path =3D self.node_device_create() + obj =3D self.bus.get_object('org.libvirt', test_node_device_path) + interface_obj =3D dbus.Interface(obj, 'org.libvirt.NodeDevice') + interface_obj.Destroy() + + self.main_loop() + + +if __name__ =3D=3D '__main__': + libvirttest.run() --=20 2.15.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list