Resolve PCI devices on the host during Guest boot-up.

When devname is used in Whitelist configuration,
resolve the address of devname when trying to
match a device in the whiltelist.

Change-Id: I7a65857454cc132d97df9abb8297d350514cf2df
Closes-Bug: #1605549
Co-Authored-By: Raghuveer Shenoy <rshenoy@hp.com>
Co-Authored-By: Sonu <sonu.sudhakaran@gmail.com>
This commit is contained in:
Manjunath Patil 2016-07-22 14:31:11 +05:30
parent f5b43ce0d1
commit 433fe514e8
2 changed files with 16 additions and 19 deletions

View File

@ -142,28 +142,26 @@ class PciDeviceSpec(object):
get_pci_dev_info(self, 'vendor_id', MAX_VENDOR_ID, '%04x')
get_pci_dev_info(self, 'product_id', MAX_PRODUCT_ID, '%04x')
pf = False
if self.address and self.dev_name:
raise exception.PciDeviceInvalidDeviceName()
if not self.address:
if self.dev_name:
self.address, pf = utils.get_function_by_ifname(
self.dev_name)
if not self.address:
raise exception.PciDeviceNotFoundById(id=self.dev_name)
else:
self.address = "*:*:*.*"
self.address = PciAddress(self.address, pf)
if not self.dev_name:
address_str = self.address or "*:*:*.*"
self.address = PciAddress(address_str, False)
def match(self, dev_dict):
conditions = [
if self.dev_name:
address_str, pf = utils.get_function_by_ifname(
self.dev_name)
if not address_str:
return False
address_obj = PciAddress(address_str, pf)
elif self.address:
address_obj = self.address
return all([
self.vendor_id in (ANY, dev_dict['vendor_id']),
self.product_id in (ANY, dev_dict['product_id']),
self.address.match(dev_dict['address'],
dev_dict.get('parent_addr'))
]
return all(conditions)
address_obj.match(dev_dict['address'],
dev_dict.get('parent_addr'))])
def match_pci_obj(self, pci_obj):
return self.match({'vendor_id': pci_obj.vendor_id,

View File

@ -154,9 +154,8 @@ class PciDevSpecTestCase(test.NoDBTestCase):
return_value = (None, False))
def test_invalid_name(self, mock_get_function_by_ifname):
pci_info = {"devname": "lo", "physical_network": "hr_net"}
exc = self.assertRaises(exception.PciDeviceNotFoundById,
devspec.PciDeviceSpec, pci_info)
self.assertEqual('PCI device lo not found', six.text_type(exc))
pci = devspec.PciDeviceSpec(pci_info)
self.assertFalse(pci.match(dev))
def test_pci_obj(self):
pci_info = {"vendor_id": "8086", "address": "*:*:*.5",