def test_remote_managed_vf_by_pf(self): """Remote-managed PF test case with PF-based VF matching This is to test the supported matching of a VF by using its product and vendor ID and a specific PF PCI address. """ # Full match: 5058 is the expected VF product ID which # matches the one specified in the whitelist. This is to # simulate the supported matching of a VF by using its # product and vendor ID and a specific PF PCI address. pci_info = { "vendor_id": "8086", "address": "0000:0a:00.0", "product_id": "5058", "physical_network": "hr_net", PCI_REMOTE_MANAGED_TAG: "true" } devspec.PciDeviceSpec(pci_info) # This spec would match both PFs and VFs. Since we care that # remote-managed PFs are not allowed, we have to prohibit the # this altogether. pci_info = { "vendor_id": "*", "address": "0000:0a:00.0", "product_id": "*", "physical_network": "hr_net", PCI_REMOTE_MANAGED_TAG: "true" } self.assertRaises(exception.PciDeviceInvalidPFRemoteManaged, devspec.PciDeviceSpec, pci_info) # Don't care about a VF product ID. Like above, this would # match both PFs and VFs (since VFs have the same vendor ID). # Therefore, this case is prohibited to avoid remote-managed PFs. pci_info = { "vendor_id": "8086", "address": "0000:0a:00.0", "product_id": "*", "physical_network": "hr_net", PCI_REMOTE_MANAGED_TAG: "true" } self.assertRaises(exception.PciDeviceInvalidPFRemoteManaged, devspec.PciDeviceSpec, pci_info) # Don't care about a VF vendor ID. pci_info = { "vendor_id": "*", "address": "0000:0a:00.0", "product_id": "5058", "physical_network": "hr_net", PCI_REMOTE_MANAGED_TAG: "true" } devspec.PciDeviceSpec(pci_info)
def _parse_white_list_from_config(self, whitelists): """Parse and validate the pci whitelist from the nova config.""" specs = [] for jsonspec in whitelists: try: dev_spec = jsonutils.loads(jsonspec) except ValueError: raise exception.PciConfigInvalidWhitelist( reason=_("Invalid entry: '%s'") % jsonspec) if isinstance(dev_spec, dict): dev_spec = [dev_spec] elif not isinstance(dev_spec, list): raise exception.PciConfigInvalidWhitelist( reason=_("Invalid entry: '%s'; " "Expecting list or dict") % jsonspec) for ds in dev_spec: if not isinstance(ds, dict): raise exception.PciConfigInvalidWhitelist( reason=_("Invalid entry: '%s'; " "Expecting dict") % ds) spec = devspec.PciDeviceSpec(ds) specs.append(spec) return specs
def test_remote_managed_vf_match_by_pci_obj(self): pci_info = { "vendor_id": "8086", "address": "0000:0a:00.2", "product_id": "5057", "physical_network": "hr_net", PCI_REMOTE_MANAGED_TAG: "true" } pci = devspec.PciDeviceSpec(pci_info) pci_dev = { "compute_node_id": 1, "address": "0000:0a:00.2", "vendor_id": "8086", "product_id": "5057", "capabilities": { "vpd": { "card_serial_number": "MT2113X00000" } }, "status": "available", "parent_addr": "0000:0a:00.1", } pci_obj = objects.PciDevice.create(None, pci_dev) self.assertTrue(pci.match_pci_obj(pci_obj))
def test_spec_partial_address_regex(self): pci_info = {"address": {"domain": ".*", "bus": ".*", "slot": "00", }, "physical_network": "hr_net"} pci = devspec.PciDeviceSpec(pci_info) self.assertTrue(pci.match(dev))
def test_partial_address_func(self): pci_info = {"address": ".5", "physical_network": "hr_net"} pci = devspec.PciDeviceSpec(pci_info) dev = {"vendor_id": "1137", "product_id": "0071", "address": "0000:0a:00.5", "phys_function": "0000:0a:00.0"} self.assertTrue(pci.match(dev))
def _parse_white_list_from_config(self, whitelists): """Parse and validate the pci whitelist from the nova config.""" specs = [] for jsonspec in whitelists: spec = devspec.PciDeviceSpec(jsonspec) specs.append(spec) return specs
def test_spec_regex_no_match(self): pci_info = {"address": {"domain": ".*", "bus": ".*", "slot": "00", "function": "[6-7]" }, "physical_network": "hr_net"} pci = devspec.PciDeviceSpec(pci_info) self.assertFalse(pci.match(dev))
def test_wrong_address(self): pci_info = { "vendor_id": "8086", "address": "*: *: *.6", "product_id": "5057", "physical_network": "hr_net" } pci = devspec.PciDeviceSpec(pci_info) self.assertFalse(pci.match(dev))
def test_address_is_pf_regex(self, mock_is_physical_function): pci_info = {"address": {"domain": "0000", "bus": "0a", "slot": "00", "function": "0" }, "physical_network": "hr_net"} pci = devspec.PciDeviceSpec(pci_info) self.assertTrue(pci.match(dev))
def test_no_remote_managed_specified_vf_match(self): pci_info = { "vendor_id": "8086", "address": "0000:0a:00.0", "product_id": "5057", "physical_network": "hr_net" } pci = devspec.PciDeviceSpec(pci_info) self.assertTrue(pci.match(self.test_dev))
def test_not_remote_managed_vf_match(self): pci_info = { "vendor_id": "8086", "address": "0000:0a:00.0", "product_id": "5057", "physical_network": "hr_net", PCI_REMOTE_MANAGED_TAG: "false" } pci = devspec.PciDeviceSpec(pci_info) self.assertTrue(pci.match(self.test_dev))
def test_remote_managed_specified_no_serial_vf_no_match(self): # No card serial number available - must not get a match. test_dev = { "vendor_id": "8086", "product_id": "5057", "address": "0000:0a:00.0", } pci_info = { "vendor_id": "8086", "address": "0000:0a:00.0", "product_id": "5057", "physical_network": "hr_net", PCI_REMOTE_MANAGED_TAG: "true" } pci = devspec.PciDeviceSpec(pci_info) self.assertFalse(pci.match(test_dev))
def test_pci_obj(self): pci_info = ('{"vendor_id": "8086","address": "*:*:*.5", ' + '"product_id": "5057", "physical_network": "hr_net"}') pci = devspec.PciDeviceSpec(pci_info) pci_dev = { 'compute_node_id': 1, 'address': '0000:00:00.5', 'product_id': '5057', 'vendor_id': '8086', 'status': 'available', 'extra_k1': 'v1', } pci_obj = objects.PciDevice.create(pci_dev) self.assertTrue(pci.match_pci_obj(pci_obj))
def test_remote_managed_specified_empty_serial_vf_no_match(self): # Card serial is an empty string. test_dev = { "vendor_id": "8086", "product_id": "5057", "address": "0000:0a:00.0", "capabilities": { "vpd": { "card_serial_number": "" } }, } pci_info = { "vendor_id": "8086", "address": "0000:0a:00.0", "product_id": "5057", "physical_network": "hr_net", PCI_REMOTE_MANAGED_TAG: "true" } pci = devspec.PciDeviceSpec(pci_info) self.assertFalse(pci.match(test_dev))
def test_address_pf_no_parent_addr(self, mock_is_physical_function): _dev = dev.copy() _dev.pop('parent_addr') pci_info = {"address": "0000:0a:00.5", "physical_network": "hr_net"} pci = devspec.PciDeviceSpec(pci_info) self.assertTrue(pci.match(_dev))
def test_address_is_pf(self, mock_is_physical_function): pci_info = {"address": "0000:0a:00.0", "physical_network": "hr_net"} pci = devspec.PciDeviceSpec(pci_info) self.assertTrue(pci.match(dev))
def test_address_is_undefined(self): pci_info = {"vendor_id": "8086", "product_id": "5057"} pci = devspec.PciDeviceSpec(pci_info) self.assertTrue(pci.match(dev))
def test_by_name(self, mock_get_function_by_ifname): pci_info = '{"devname": "eth0", "physical_network": "hr_net"}' pci = devspec.PciDeviceSpec(pci_info) self.assertTrue(pci.match(dev))
def test_invalid_product_id(self): pci_info = ('{"vendor_id": "8086","address": "*: *: *.5", ' + '"product_id": "5056", "physical_network": "hr_net"}') pci = devspec.PciDeviceSpec(pci_info) self.assertFalse(pci.match(dev))
def test_invalid_name(self, mock_get_function_by_ifname): pci_info = {"devname": "lo", "physical_network": "hr_net"} pci = devspec.PciDeviceSpec(pci_info) self.assertFalse(pci.match(dev))
def test_blank_devname(self): pci_info = {"devname": "", "physical_network": "hr_net"} pci = devspec.PciDeviceSpec(pci_info) for field in ['domain', 'bus', 'slot', 'func']: self.assertEqual('*', getattr(pci.address.pci_address_spec, field))