diff options
Diffstat (limited to 'nova/compute/pci_placement_translator.py')
-rw-r--r-- | nova/compute/pci_placement_translator.py | 74 |
1 files changed, 50 insertions, 24 deletions
diff --git a/nova/compute/pci_placement_translator.py b/nova/compute/pci_placement_translator.py index d6d7fdd6f1..016efd9122 100644 --- a/nova/compute/pci_placement_translator.py +++ b/nova/compute/pci_placement_translator.py @@ -65,20 +65,50 @@ def _normalize_traits(traits: ty.List[str]) -> ty.List[str]: return list(standard_traits) + custom_traits -def _get_traits_for_dev( - dev_spec_tags: ty.Dict[str, str], -) -> ty.Set[str]: +def get_traits(traits_str: str) -> ty.Set[str]: + """Return a normalized set of placement standard and custom traits from + a string of comma separated trait names. + """ # traits is a comma separated list of placement trait names - traits_str = dev_spec_tags.get("traits") if not traits_str: - return {os_traits.COMPUTE_MANAGED_PCI_DEVICE} + return set() + return set(_normalize_traits(traits_str.split(','))) - traits = traits_str.split(',') - return set(_normalize_traits(traits)) | { + +def _get_traits_for_dev( + dev_spec_tags: ty.Dict[str, str], +) -> ty.Set[str]: + return get_traits(dev_spec_tags.get("traits", "")) | { os_traits.COMPUTE_MANAGED_PCI_DEVICE } +def _normalize_resource_class(rc: str) -> str: + rc = rc.upper() + if ( + rc not in os_resource_classes.STANDARDS and + not os_resource_classes.is_custom(rc) + ): + rc = os_resource_classes.normalize_name(rc) + # mypy: normalize_name will return non None for non None input + assert rc + + return rc + + +def get_resource_class( + requested_name: ty.Optional[str], vendor_id: str, product_id: str +) -> str: + """Return the normalized resource class name based on what is requested + or if nothing is requested then generated from the vendor_id and product_id + """ + if requested_name: + rc = _normalize_resource_class(requested_name) + else: + rc = f"CUSTOM_PCI_{vendor_id}_{product_id}".upper() + return rc + + def _get_rc_for_dev( dev: pci_device.PciDevice, dev_spec_tags: ty.Dict[str, str], @@ -91,23 +121,8 @@ def _get_rc_for_dev( The user specified resource class is normalized if it is not already an acceptable standard or custom resource class. """ - # Either use the resource class from the config or the vendor_id and - # product_id of the device to generate the RC rc = dev_spec_tags.get("resource_class") - if rc: - rc = rc.upper() - if ( - rc not in os_resource_classes.STANDARDS and - not os_resource_classes.is_custom(rc) - ): - rc = os_resource_classes.normalize_name(rc) - # mypy: normalize_name will return non None for non None input - assert rc - - else: - rc = f"CUSTOM_PCI_{dev.vendor_id}_{dev.product_id}".upper() - - return rc + return get_resource_class(rc, dev.vendor_id, dev.product_id) class PciResourceProvider: @@ -246,6 +261,12 @@ class PciResourceProvider: ) provider_tree.update_traits(self.name, self.traits) + # Here we are sure the RP exists in the provider_tree. So, we can + # record the RP UUID in each PciDevice this RP represents + rp_uuid = provider_tree.data(self.name).uuid + for dev in self.devs: + dev.extra_info['rp_uuid'] = rp_uuid + def update_allocations( self, allocations: dict, @@ -583,12 +604,17 @@ def update_provider_tree_for_pci( pv.update_provider_tree(provider_tree) old_alloc = copy.deepcopy(allocations) + # update_provider_tree correlated the PciDevice objects with RPs in + # placement and recorded the RP UUID in the PciDevice object. We need to + # trigger an update on the device pools in the tracker to get the device + # RP UUID mapped to the device pools + pci_tracker.stats.populate_pools_metadata_from_assigned_devices() updated = pv.update_allocations(allocations, provider_tree) if updated: LOG.debug( "Placement PCI view needs allocation healing. This should only " - "happen if [scheduler]pci_in_placement is still disabled. " + "happen if [filter_scheduler]pci_in_placement is still disabled. " "Original allocations: %s New allocations: %s", old_alloc, allocations, |