Modify PciPassthroughFilter to accept lists

PciPassthroughFilter can accept lists as input parameters.
All values contained in the spec list parameter must be
contained in the PCI device namesake parameter.

blueprint enable-sriov-nic-features

Change-Id: Icca0488a6e37133fd1de3709ae97b97b45b80d93
This commit is contained in:
Rodolfo Alonso Hernandez 2017-03-13 15:11:10 +00:00 committed by Jay Pipes
parent e6829f872a
commit b122429b2a
2 changed files with 30 additions and 3 deletions

View File

@ -45,11 +45,19 @@ def pci_device_prop_match(pci_dev, specs):
b) Device with vendor_id as 0x10de and product_id as 0x10d8:
[{"vendor_id":"8086", "product_id":"8259"},
{"vendor_id":"10de", "product_id":"10d8"}]
{"vendor_id":"10de", "product_id":"10d8",
"capabilities_network": ["rx", "tx", "tso", "gso"]}]
"""
def _matching_devices(spec):
return all(pci_dev.get(k) == v for k, v in spec.items())
for k, v in spec.items():
pci_dev_v = pci_dev.get(k)
if isinstance(v, list) and isinstance(pci_dev_v, list):
if not all(x in pci_dev.get(k) for x in v):
return False
elif pci_dev_v != v:
return False
return True
return any(_matching_devices(spec) for spec in specs)

View File

@ -30,7 +30,8 @@ class PciDeviceMatchTestCase(test.NoDBTestCase):
def setUp(self):
super(PciDeviceMatchTestCase, self).setUp()
self.fake_pci_1 = {'vendor_id': 'v1',
'device_id': 'd1'}
'device_id': 'd1',
'capabilities_network': ['cap1', 'cap2', 'cap3']}
def test_single_spec_match(self):
self.assertTrue(utils.pci_device_prop_match(
@ -53,6 +54,24 @@ class PciDeviceMatchTestCase(test.NoDBTestCase):
self.fake_pci_1,
[{'vendor_id': 'v1', 'device_id': 'd1', 'wrong_key': 'k1'}]))
def test_spec_list(self):
self.assertTrue(utils.pci_device_prop_match(
self.fake_pci_1, [{'vendor_id': 'v1', 'device_id': 'd1',
'capabilities_network': ['cap1', 'cap2',
'cap3']}]))
self.assertTrue(utils.pci_device_prop_match(
self.fake_pci_1, [{'vendor_id': 'v1', 'device_id': 'd1',
'capabilities_network': ['cap3', 'cap1']}]))
def test_spec_list_no_matching(self):
self.assertFalse(utils.pci_device_prop_match(
self.fake_pci_1, [{'vendor_id': 'v1', 'device_id': 'd1',
'capabilities_network': ['cap1', 'cap33']}]))
def test_spec_list_wrong_type(self):
self.assertFalse(utils.pci_device_prop_match(
self.fake_pci_1, [{'vendor_id': 'v1', 'device_id': ['d1']}]))
class PciDeviceAddressParserTestCase(test.NoDBTestCase):
def test_parse_address(self):