pci: don't consider case when match tags specs

This makes matching pci device spec tags case
insensitive. This is useful to improve the user
experience for simple cases where boolean values
are being compared. For example, with the trusted
VF series, the port binding profile might have:

  trusted=True

And the PCI whitelist might have:

  trusted=true

And this should be considered a match.

Part of blueprint sriov-trusted-vfs

Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@redhat.com>
Change-Id: Ica532fa7dcd5fe11bd60db4cfe005a2bef0a1b7a
This commit is contained in:
Sahid Orentino Ferdjaoui 2018-05-02 16:17:45 +02:00
parent 13fc241af6
commit 7c725eeb34
2 changed files with 14 additions and 3 deletions

View File

@ -20,7 +20,7 @@ import os
import re
from oslo_log import log as logging
import six
from nova import exception
@ -54,7 +54,16 @@ def pci_device_prop_match(pci_dev, specs):
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:
else:
# We don't need to check case for tags in order to avoid any
# mismatch with the tags provided by users for port
# binding profile and the ones configured by operators
# with pci whitelist option.
if isinstance(v, six.string_types):
v = v.lower()
if isinstance(pci_dev_v, six.string_types):
pci_dev_v = pci_dev_v.lower()
if pci_dev_v != v:
return False
return True

View File

@ -36,6 +36,8 @@ class PciDeviceMatchTestCase(test.NoDBTestCase):
def test_single_spec_match(self):
self.assertTrue(utils.pci_device_prop_match(
self.fake_pci_1, [{'vendor_id': 'v1', 'device_id': 'd1'}]))
self.assertTrue(utils.pci_device_prop_match(
self.fake_pci_1, [{'vendor_id': 'V1', 'device_id': 'D1'}]))
def test_multiple_spec_match(self):
self.assertTrue(utils.pci_device_prop_match(