From 7c725eeb3470394d064894991419793394fc34cd Mon Sep 17 00:00:00 2001 From: Sahid Orentino Ferdjaoui Date: Wed, 2 May 2018 16:17:45 +0200 Subject: [PATCH] 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 Change-Id: Ica532fa7dcd5fe11bd60db4cfe005a2bef0a1b7a --- nova/pci/utils.py | 15 ++++++++++++--- nova/tests/unit/pci/test_utils.py | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/nova/pci/utils.py b/nova/pci/utils.py index 2ea64b14911c..221508574aa3 100644 --- a/nova/pci/utils.py +++ b/nova/pci/utils.py @@ -20,7 +20,7 @@ import os import re from oslo_log import log as logging - +import six from nova import exception @@ -54,8 +54,17 @@ 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: - return False + 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 return any(_matching_devices(spec) for spec in specs) diff --git a/nova/tests/unit/pci/test_utils.py b/nova/tests/unit/pci/test_utils.py index b86f0fab7a8d..6675be5c2471 100644 --- a/nova/tests/unit/pci/test_utils.py +++ b/nova/tests/unit/pci/test_utils.py @@ -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(