[libvirt] [dbus PATCH 0/4] Fix 'make check' with libvirt 3.0.0

Andrea Bolognani (4): tests: Drop pytest.mark.usefixtures from test_nodedev tests: Move some test cases to test_nodedev tests: Don't open-code node_device_create() tests: Make node_device_create() work with libvirt 3.0.0 tests/libvirttest.py | 17 ++++++++++++++++- tests/test_connect.py | 27 --------------------------- tests/test_nodedev.py | 26 +++++++++++++++++++++++++- tests/xmldata.py | 2 +- 4 files changed, 42 insertions(+), 30 deletions(-) -- 2.17.1

We're already using node_device_create explicitly for all test cases in order to retrieve the result of the fixture, so using pytest.mark.usefixtures as well is pointless. Additionally, we're soon going to add some test cases where we need the fixture *not* to run automatically. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- tests/test_nodedev.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_nodedev.py b/tests/test_nodedev.py index 22c8d60..082cf0b 100755 --- a/tests/test_nodedev.py +++ b/tests/test_nodedev.py @@ -5,7 +5,6 @@ import libvirttest import pytest -@pytest.mark.usefixtures("node_device_create") class TestNodeDevice(libvirttest.BaseTestClass): """ Tests for methods and properties of the NodeDevice interface """ -- 2.17.1

On Fri, Jul 27, 2018 at 02:37:38PM +0200, Andrea Bolognani wrote:
We're already using node_device_create explicitly for all test cases in order to retrieve the result of the fixture, so using pytest.mark.usefixtures as well is pointless.
Additionally, we're soon going to add some test cases where we need the fixture *not* to run automatically.
Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- tests/test_nodedev.py | 1 - 1 file changed, 1 deletion(-)
diff --git a/tests/test_nodedev.py b/tests/test_nodedev.py index 22c8d60..082cf0b 100755 --- a/tests/test_nodedev.py +++ b/tests/test_nodedev.py @@ -5,7 +5,6 @@ import libvirttest import pytest
-@pytest.mark.usefixtures("node_device_create") class TestNodeDevice(libvirttest.BaseTestClass): """ Tests for methods and properties of the NodeDevice interface """
This patch broke syntax-check: ./tests/test_nodedev.py:5:1: F401 'pytest' imported but unused import pytest ^ Jano

On Mon, 2018-08-13 at 14:11 +0200, Ján Tomko wrote:
On Fri, Jul 27, 2018 at 02:37:38PM +0200, Andrea Bolognani wrote:
-@pytest.mark.usefixtures("node_device_create") class TestNodeDevice(libvirttest.BaseTestClass): """ Tests for methods and properties of the NodeDevice interface """
This patch broke syntax-check: ./tests/test_nodedev.py:5:1: F401 'pytest' imported but unused import pytest ^
I hadn't even realized we have syntax-check O:-) https://www.redhat.com/archives/libvir-list/2018-August/msg00852.html -- Andrea Bolognani / Red Hat / Virtualization

For whatever reason, a few nodedev-related test cases have ended up in test_connect instead of the more appropriate test_nodedev. Move them. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- tests/test_connect.py | 27 --------------------------- tests/test_nodedev.py | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/tests/test_connect.py b/tests/test_connect.py index f481356..9cc51db 100755 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -161,19 +161,6 @@ class TestConnect(libvirttest.BaseTestClass): self.main_loop() - @pytest.mark.usefixtures("node_device_create") - @pytest.mark.parametrize("lookup_method_name,lookup_item", [ - ("NodeDeviceLookupByName", 'Name'), - ]) - def test_connect_node_device_lookup_by_property(self, lookup_method_name, lookup_item, node_device_create): - """Parameterized test for all NodeDeviceLookupBy* API calls of Connect interface - """ - original_path = node_device_create - obj = self.bus.get_object('org.libvirt', original_path) - prop = obj.Get('org.libvirt.NodeDevice', lookup_item, dbus_interface=dbus.PROPERTIES_IFACE) - path = getattr(self.connect, lookup_method_name)(prop) - assert original_path == path - @pytest.mark.parametrize("lookup_method_name,lookup_item", [ ("NetworkLookupByName", 'Name'), ("NetworkLookupByUUID", 'UUID'), @@ -186,20 +173,6 @@ class TestConnect(libvirttest.BaseTestClass): path = getattr(self.connect, lookup_method_name)(prop) assert original_path == path - def test_connect_node_device_create_xml(self): - def node_device_created(path, event, _detail): - if event != libvirttest.NodeDeviceEvent.CREATED: - return - assert isinstance(path, dbus.ObjectPath) - self.loop.quit() - - self.connect.connect_to_signal('NodeDeviceEvent', node_device_created) - - path = self.connect.NodeDeviceCreateXML(xmldata.minimal_node_device_xml, 0) - assert isinstance(path, dbus.ObjectPath) - - self.main_loop() - def test_connect_node_get_cpu_stats(self): stats = self.connect.NodeGetCPUStats(0, 0) assert isinstance(stats, dbus.Dictionary) diff --git a/tests/test_nodedev.py b/tests/test_nodedev.py index 082cf0b..c68cb66 100755 --- a/tests/test_nodedev.py +++ b/tests/test_nodedev.py @@ -3,11 +3,37 @@ import dbus import libvirttest import pytest +import xmldata class TestNodeDevice(libvirttest.BaseTestClass): """ Tests for methods and properties of the NodeDevice interface """ + @pytest.mark.parametrize("lookup_method_name,lookup_item", [ + ("NodeDeviceLookupByName", 'Name'), + ]) + def test_connect_node_device_lookup_by_property(self, lookup_method_name, lookup_item, node_device_create): + """Parameterized test for all NodeDeviceLookupBy* API calls of Connect interface + """ + original_path = node_device_create + obj = self.bus.get_object('org.libvirt', original_path) + prop = obj.Get('org.libvirt.NodeDevice', lookup_item, dbus_interface=dbus.PROPERTIES_IFACE) + path = getattr(self.connect, lookup_method_name)(prop) + assert original_path == path + + def test_connect_node_device_create(self): + def node_device_created(path, event, _detail): + if event != libvirttest.NodeDeviceEvent.CREATED: + return + assert isinstance(path, dbus.ObjectPath) + self.loop.quit() + + self.connect.connect_to_signal('NodeDeviceEvent', node_device_created) + + path = self.connect.NodeDeviceCreateXML(xmldata.minimal_node_device_xml, 0) + assert isinstance(path, dbus.ObjectPath) + + self.main_loop() def test_node_device_destroy(self, node_device_create): def node_device_deleted(path, event, _detail): -- 2.17.1

On Fri, Jul 27, 2018 at 02:37:39PM +0200, Andrea Bolognani wrote:
For whatever reason, a few nodedev-related test cases have ended up in test_connect instead of the more appropriate test_nodedev. Move them.
Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- https://www.redhat.com/mailman/listinfo/libvir-list
Currently a test for some method is placed in the test file refering to the interface the tested method is exposed on. So NodeDeviceCreateXML method is exposed on the Connect Interface, this test_connect.py is the place for the test for this method. Katerina

The fixture is pretty trivial right now, so open-coding it is not a big deal; however, we're going to add more logic to it soon and we definitely don't want to end up having to worry about duplicated code. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- tests/test_nodedev.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_nodedev.py b/tests/test_nodedev.py index c68cb66..ce70dfc 100755 --- a/tests/test_nodedev.py +++ b/tests/test_nodedev.py @@ -3,7 +3,6 @@ import dbus import libvirttest import pytest -import xmldata class TestNodeDevice(libvirttest.BaseTestClass): @@ -30,7 +29,7 @@ class TestNodeDevice(libvirttest.BaseTestClass): self.connect.connect_to_signal('NodeDeviceEvent', node_device_created) - path = self.connect.NodeDeviceCreateXML(xmldata.minimal_node_device_xml, 0) + path = self.node_device_create() assert isinstance(path, dbus.ObjectPath) self.main_loop() -- 2.17.1

The scsi_host2 nodedev, which our test nodedev uses as its parent, was added to the test driver with commit 5c2ff641e10c, which is included in libvirt 3.1.0; before that, there was a similar device called test-scsi-host-vport, which is no longer present after libvirt 3.0.0. Since there's no nodedev that we can use as parent both with libvirt 3.0.0 and with later versions, our only option is to perform a lookup at runtime and use whatever's available. Signed-off-by: Andrea Bolognani <abologna@redhat.com> --- tests/libvirttest.py | 17 ++++++++++++++++- tests/xmldata.py | 2 +- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/libvirttest.py b/tests/libvirttest.py index 776b12d..14baf5b 100644 --- a/tests/libvirttest.py +++ b/tests/libvirttest.py @@ -91,7 +91,22 @@ class BaseTestClass(): 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) + # We need a usable parent nodedev: possible candidates are + # scsi_host2 (available since libvirt 3.1.0) and + # test-scsi-host-vport (available until libvirt 3.0.0). + # + # Looking up a non-existing nodedev raises an exception, so + # we need to ignore them here: that's okay, because if we + # can't find any then NodeDeviceCreateXML() itself will fail + xml = xmldata.minimal_node_device_xml + for parent in ['scsi_host2', 'test-scsi-host-vport']: + try: + if self.connect.NodeDeviceLookupByName(parent): + xml = xml.replace('@parent@', parent) + break + except dbus.exceptions.DBusException: + pass + path = self.connect.NodeDeviceCreateXML(xml, 0) return path @pytest.fixture diff --git a/tests/xmldata.py b/tests/xmldata.py index a70bac1..8075052 100644 --- a/tests/xmldata.py +++ b/tests/xmldata.py @@ -41,7 +41,7 @@ minimal_network_xml = ''' minimal_node_device_xml = ''' <device> <name>scsi_host22</name> - <parent>scsi_host2</parent> + <parent>@parent@</parent> <capability type='scsi_host'> <host>22</host> <unique_id>22</unique_id> -- 2.17.1

On Fri, Jul 27, 2018 at 02:37:37PM +0200, Andrea Bolognani wrote:
Andrea Bolognani (4): tests: Drop pytest.mark.usefixtures from test_nodedev tests: Move some test cases to test_nodedev tests: Don't open-code node_device_create() tests: Make node_device_create() work with libvirt 3.0.0
tests/libvirttest.py | 17 ++++++++++++++++- tests/test_connect.py | 27 --------------------------- tests/test_nodedev.py | 26 +++++++++++++++++++++++++- tests/xmldata.py | 2 +- 4 files changed, 42 insertions(+), 30 deletions(-)
-- 2.17.1
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Please remove the second patch moving the test file - see reasoning there. So the third patch should be adjusted but in the original file, test_connect.py With these fixed: Reviewed-by: Katerina Koukiou <kkoukiou@redhat.com>
participants (3)
-
Andrea Bolognani
-
Ján Tomko
-
Katerina Koukiou