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(a)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