Skip to content

Commit

Permalink
Merge "libvirt: make mdev types name attribute be optional"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed Sep 25, 2020
2 parents 2931516 + 416cd1a commit 162c6b6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
45 changes: 45 additions & 0 deletions nova/tests/unit/virt/libvirt/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,29 @@
</type>
</capability>
</capability>
</device>""",
"pci_0000_06_00_1": """
<device>
<name>pci_0000_06_00_1</name>
<path>/sys/devices/pci0000:00/0000:00:06.1</path>
<parent></parent>
<driver>
<name>i915</name>
</driver>
<capability type="pci">
<domain>0</domain>
<bus>6</bus>
<slot>0</slot>
<function>1</function>
<product id="0x591d">HD Graphics P630</product>
<vendor id="0x8086">Intel Corporation</vendor>
<capability type='mdev_types'>
<type id='i915-GVTg_V5_8'>
<deviceAPI>vfio-pci</deviceAPI>
<availableInstances>2</availableInstances>
</type>
</capability>
</capability>
</device>""",
"mdev_4b20d080_1b54_4048_85b3_a6a62d165c01": """
<device>
Expand Down Expand Up @@ -24999,6 +25022,28 @@ def fake_nodeDeviceLookupByName(name):
self.assertEqual([],
drvr._get_mdev_capable_devices(types=['nvidia-12']))

@mock.patch.object(host.Host, 'device_lookup_by_name')
def test_get_mdev_capabilities_for_dev_name_optional(
self, device_lookup_by_name):
# We use another PCI device that doesn't provide a name attribute for
# each mdev type.
def fake_nodeDeviceLookupByName(name):
return FakeNodeDevice(_fake_NodeDevXml[name])
device_lookup_by_name.side_effect = fake_nodeDeviceLookupByName

drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)

expected = {"dev_id": "pci_0000_06_00_1",
"vendor_id": 0x8086,
"types": {'i915-GVTg_V5_8': {'availableInstances': 2,
'name': None,
'deviceAPI': 'vfio-pci'},
}
}
self.assertEqual(
expected,
drvr._get_mdev_capabilities_for_dev("pci_0000_06_00_1"))

@mock.patch.object(host.Host, 'device_lookup_by_name')
@mock.patch.object(host.Host, 'list_mediated_devices')
def test_get_mediated_devices(self, list_mediated_devices,
Expand Down
3 changes: 2 additions & 1 deletion nova/virt/libvirt/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -7246,7 +7246,8 @@ def _get_mdev_capabilities_for_dev(self, devname, types=None):
if not types or cap['type'] in types:
device["types"].update({cap['type']: {
'availableInstances': cap['availableInstances'],
'name': cap['name'],
# This attribute is optional
'name': cap.get('name'),
'deviceAPI': cap['deviceAPI']}})
return device

Expand Down

0 comments on commit 162c6b6

Please sign in to comment.