Commit 6f626690 authored by Andrea Bolognani's avatar Andrea Bolognani

tests: Make node_device_create() work with libvirt 3.0.0

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: 's avatarAndrea Bolognani <abologna@redhat.com>
Reviewed-by: 's avatarKaterina Koukiou <kkoukiou@redhat.com>
parent 9ba6080e
......@@ -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
......
......@@ -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>
......
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