Address nits in I46d483f9de6776db1b025f925890624e5e682ada
Change-Id: Idcf3a72f5dd5d31c3aa1c514f3fdb28a69a900a4
This commit is contained in:
@@ -232,7 +232,8 @@ class PciDeviceStats(object):
|
||||
:param requested_count: The number of PCI devices requested.
|
||||
:returns: A list of pools that can, together, provide at least
|
||||
``requested_count`` PCI devices with the level of NUMA affinity
|
||||
required by ``numa_policy``.
|
||||
required by ``numa_policy``, else all pools that can satisfy this
|
||||
policy even if it's not enough.
|
||||
"""
|
||||
# NOTE(stephenfin): We may wish to change the default policy at a later
|
||||
# date
|
||||
@@ -265,7 +266,7 @@ class PciDeviceStats(object):
|
||||
|
||||
# once again, we can't apply a less strict policy than the one
|
||||
# requested, so we need to return if we've demanded a NUMA affinity of
|
||||
# LEGACY. Similarly, we will also reurn if we have enough devices to
|
||||
# LEGACY. Similarly, we will also return if we have enough devices to
|
||||
# satisfy this somewhat strict policy.
|
||||
if requested_policy == fields.PCINUMAAffinityPolicy.LEGACY or sum(
|
||||
pool['count'] for pool in filtered_pools) >= requested_count:
|
||||
@@ -274,7 +275,8 @@ class PciDeviceStats(object):
|
||||
# if we've got here, we're using the PREFERRED policy and weren't able
|
||||
# to provide anything with stricter affinity. Use whatever devices you
|
||||
# can, folks.
|
||||
return pools
|
||||
return sorted(
|
||||
pools, key=lambda pool: pool.get('numa_node') not in numa_cell_ids)
|
||||
|
||||
@classmethod
|
||||
def _filter_non_requested_pfs(cls, pools, request):
|
||||
@@ -305,6 +307,8 @@ class PciDeviceStats(object):
|
||||
quantity and required NUMA affinity of device(s) we want..
|
||||
:param numa_cells: A list of InstanceNUMACell objects whose ``id``
|
||||
corresponds to the ``id`` of host NUMACells.
|
||||
:returns: True if the request was applied against the provided pools
|
||||
successfully, else False.
|
||||
"""
|
||||
# NOTE(vladikr): This code maybe open to race conditions.
|
||||
# Two concurrent requests may succeed when called support_requests
|
||||
@@ -376,8 +380,6 @@ class PciDeviceStats(object):
|
||||
:type requests: nova.objects.InstancePCIRequests
|
||||
:param numa_cells: A list of InstanceNUMACell objects whose ``id``
|
||||
corresponds to the ``id`` of host NUMACells, or None.
|
||||
:param numa_policy: The PCI NUMA affinity policy to apply when
|
||||
filtering devices from ``numa_cells``, or None.
|
||||
:raises: exception.PciDeviceRequestFailed if this compute node cannot
|
||||
satisfy the given request.
|
||||
"""
|
||||
|
||||
@@ -67,13 +67,13 @@ pci_requests_multiple = [objects.InstancePCIRequest(count=1,
|
||||
class PciDeviceStatsTestCase(test.NoDBTestCase):
|
||||
|
||||
@staticmethod
|
||||
def _get_fake_requests(vendor_ids=None, numa_policy=None):
|
||||
def _get_fake_requests(vendor_ids=None, numa_policy=None, count=1):
|
||||
if not vendor_ids:
|
||||
vendor_ids = ['v1', 'v2']
|
||||
|
||||
specs = [{'vendor_id': vendor_id} for vendor_id in vendor_ids]
|
||||
|
||||
return [objects.InstancePCIRequest(count=1, spec=[spec],
|
||||
return [objects.InstancePCIRequest(count=count, spec=[spec],
|
||||
numa_policy=numa_policy) for spec in specs]
|
||||
|
||||
def _create_fake_devs(self):
|
||||
@@ -248,7 +248,7 @@ class PciDeviceStatsTestCase(test.NoDBTestCase):
|
||||
set([dev.vendor_id for dev in devs]))
|
||||
|
||||
def _test_consume_requests_numa_policy(self, cell_ids, policy,
|
||||
expected, vendor_id='v4'):
|
||||
expected, vendor_id='v4', count=1):
|
||||
"""Base test for 'consume_requests' function.
|
||||
|
||||
Create three devices with vendor_id of 'v4': 'pr0' in NUMA node 0,
|
||||
@@ -262,7 +262,7 @@ class PciDeviceStatsTestCase(test.NoDBTestCase):
|
||||
for id in cell_ids]
|
||||
|
||||
pci_requests = self._get_fake_requests(vendor_ids=[vendor_id],
|
||||
numa_policy=policy)
|
||||
numa_policy=policy, count=count)
|
||||
devs = self.pci_stats.consume_requests(pci_requests, cells)
|
||||
|
||||
if expected is None:
|
||||
@@ -296,7 +296,7 @@ class PciDeviceStatsTestCase(test.NoDBTestCase):
|
||||
|
||||
Policy is 'legacy' which means we must use a device with strict NUMA
|
||||
affinity or no provided NUMA affinity. Request a device from NUMA node
|
||||
0, which contains contains such a device, and ensure it's used.
|
||||
0, which contains such a device, and ensure it's used.
|
||||
"""
|
||||
self._test_consume_requests_numa_policy(
|
||||
[0], fields.PCINUMAAffinityPolicy.LEGACY, ['pr0'])
|
||||
@@ -312,6 +312,18 @@ class PciDeviceStatsTestCase(test.NoDBTestCase):
|
||||
self._test_consume_requests_numa_policy(
|
||||
[999], fields.PCINUMAAffinityPolicy.LEGACY, ['pr_none'])
|
||||
|
||||
def test_consume_requests_numa_policy_legacy_multiple(self):
|
||||
"""Ensure LEGACY policy will use best policy for multiple devices.
|
||||
|
||||
Policy is 'legacy' which means we must use a device with strict NUMA
|
||||
affinity or no provided NUMA affinity. Request two devices from NUMA
|
||||
node 0, which contains only one such device, and ensure we use that
|
||||
device and the next best thing for the second device.
|
||||
"""
|
||||
self._test_consume_requests_numa_policy(
|
||||
[0], fields.PCINUMAAffinityPolicy.PREFERRED, ['pr0', 'pr_none'],
|
||||
count=2)
|
||||
|
||||
def test_consume_requests_numa_policy_legacy_fail(self):
|
||||
"""Ensure REQUIRED policy will *not* provide NUMA non-affinity.
|
||||
|
||||
@@ -323,12 +335,12 @@ class PciDeviceStatsTestCase(test.NoDBTestCase):
|
||||
self._test_consume_requests_numa_policy(
|
||||
[0], fields.PCINUMAAffinityPolicy.LEGACY, None, vendor_id='v2')
|
||||
|
||||
def test_consume_requests_numa_pci_numa_policy_preferred(self):
|
||||
def test_consume_requests_numa_policy_preferred(self):
|
||||
"""Ensure PREFERRED policy will ensure NUMA affinity if possible.
|
||||
|
||||
Policy is 'preferred' which means we must use a device with any level
|
||||
of NUMA affinity. Request a device from NUMA node 0, which contains
|
||||
contains an affined device, and ensure it's used.
|
||||
an affined device, and ensure it's used.
|
||||
"""
|
||||
self._test_consume_requests_numa_policy(
|
||||
[0], fields.PCINUMAAffinityPolicy.PREFERRED, ['pr0'])
|
||||
@@ -344,7 +356,7 @@ class PciDeviceStatsTestCase(test.NoDBTestCase):
|
||||
self._test_consume_requests_numa_policy(
|
||||
[999], fields.PCINUMAAffinityPolicy.PREFERRED, ['pr_none'])
|
||||
|
||||
def test_consume_requests_numa_pci_numa_policy_fallback_b(self):
|
||||
def test_consume_requests_numa_policy_preferred_fallback_b(self):
|
||||
"""Ensure PREFERRED policy will fallback to different NUMA affinity.
|
||||
|
||||
Policy is 'preferred' which means we must use a device with any level
|
||||
@@ -356,6 +368,30 @@ class PciDeviceStatsTestCase(test.NoDBTestCase):
|
||||
[0], fields.PCINUMAAffinityPolicy.PREFERRED, ['p2'],
|
||||
vendor_id='v2')
|
||||
|
||||
def test_consume_requests_numa_policy_preferred_multiple_a(self):
|
||||
"""Ensure PREFERRED policy will use best policy for multiple devices.
|
||||
|
||||
Policy is 'preferred' which means we must use a device with any level
|
||||
of NUMA affinity. Request two devices from NUMA node 0, which contains
|
||||
only one such device, and ensure we use that device and gracefully
|
||||
degrade for the other device.
|
||||
"""
|
||||
self._test_consume_requests_numa_policy(
|
||||
[0], fields.PCINUMAAffinityPolicy.PREFERRED, ['pr0', 'pr_none'],
|
||||
count=2)
|
||||
|
||||
def test_consume_requests_numa_policy_preferred_multiple_b(self):
|
||||
"""Ensure PREFERRED policy will use best policy for multiple devices.
|
||||
|
||||
Policy is 'preferred' which means we must use a device with any level
|
||||
of NUMA affinity. Request three devices from NUMA node 0, which
|
||||
contains only one such device, and ensure we use that device and
|
||||
gracefully degrade for the other devices.
|
||||
"""
|
||||
self._test_consume_requests_numa_policy(
|
||||
[0], fields.PCINUMAAffinityPolicy.PREFERRED,
|
||||
['pr0', 'pr_none', 'pr1'], count=3)
|
||||
|
||||
@mock.patch(
|
||||
'nova.pci.whitelist.Whitelist._parse_white_list_from_config')
|
||||
def test_white_list_parsing(self, mock_whitelist_parse):
|
||||
|
||||
Reference in New Issue
Block a user