Skip to content

Commit 06389f8

Browse files
committed
Allow enabling PCI tracking in Placement
This patch introduces the [pci]report_in_placement config option that is False by default but if set to True will enable reporting of the PCI passthrough inventories to Placement. blueprint: pci-device-tracking-in-placement Change-Id: I49a3dbf4c5708d2d92dedd29a9dc3ef25b6cd66c
1 parent 9268bc3 commit 06389f8

File tree

6 files changed

+49
-35
lines changed

6 files changed

+49
-35
lines changed

doc/source/admin/pci-passthrough.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,14 @@ information, refer to :oslo.config:option:`the documentation <pci.alias>`.
351351

352352
PCI tracking in Placement
353353
-------------------------
354+
.. note::
355+
The feature described below are optional and disabled by default in nova
356+
26.0.0. (Zed). The legacy PCI tracker code path is still supported and
357+
enabled. The Placement PCI tracking can be enabled via the
358+
:oslo.config:option:`pci.report_in_placement` configuration. But please note
359+
that once it is enabled on a given compute host it cannot be disabled there
360+
any more.
361+
354362
Since nova 26.0.0 (Zed) PCI passthrough device inventories are tracked in
355363
Placement. If a PCI device exists on the hypervisor and
356364
matches one of the device specifications configured via

nova/compute/pci_placement_translator.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from oslo_utils import uuidutils
2222

2323
from nova.compute import provider_tree
24+
import nova.conf
2425
from nova import exception
2526
from nova.i18n import _
2627
from nova.objects import fields
@@ -29,6 +30,7 @@
2930
from nova.pci import manager as pci_manager
3031

3132

33+
CONF = nova.conf.CONF
3234
LOG = logging.getLogger(__name__)
3335

3436

@@ -42,14 +44,7 @@
4244

4345

4446
def _is_placement_tracking_enabled() -> bool:
45-
# This is false to act as a feature flag while we develop the feature
46-
# step by step. It will be replaced with a config check when the feature is
47-
# ready for production.
48-
#
49-
# return CONF.pci.report_in_placement
50-
51-
# Test code will mock this function to enable the feature in the test env
52-
return False
47+
return CONF.pci.report_in_placement
5348

5449

5550
def _normalize_traits(traits: ty.List[str]) -> ty.List[str]:

nova/conf/pci.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,21 @@
225225
226226
device_spec = [{"product_id":"0001", "vendor_id":"8086"},
227227
{"product_id":"0002", "vendor_id":"8086"}]
228-
""")
228+
"""),
229+
cfg.BoolOpt('report_in_placement',
230+
default=False,
231+
help="""
232+
Enable PCI resource inventory reporting to Placement. If it is enabled then the
233+
nova-compute service will report PCI resource inventories to Placement
234+
according to the [pci]device_spec configuration and the PCI devices reported
235+
by the hypervisor. Once it is enabled it cannot be disabled any more. In a
236+
future release the default of this config will be change to True.
237+
238+
Related options:
239+
240+
* [pci]device_spec: to define which PCI devices nova are allowed to track and
241+
assign to guests.
242+
"""),
229243
]
230244

231245

nova/tests/functional/libvirt/test_pci_in_placement.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,7 @@ class PlacementPCIReportingTests(test_pci_sriov_servers._PCIServersTestBase):
6161

6262
def setUp(self):
6363
super().setUp()
64-
patcher = mock.patch(
65-
"nova.compute.pci_placement_translator."
66-
"_is_placement_tracking_enabled",
67-
return_value=True
68-
)
69-
self.addCleanup(patcher.stop)
70-
self.mock_pci_report_in_placement = patcher.start()
64+
self.flags(group="pci", report_in_placement=True)
7165

7266
# These tests should not depend on the host's sysfs
7367
self.useFixture(
@@ -718,7 +712,7 @@ def _create_one_compute_with_a_pf_consumed_by_an_instance(self):
718712
]
719713
)
720714
self.flags(group='pci', device_spec=device_spec)
721-
self.mock_pci_report_in_placement.return_value = True
715+
self.flags(group="pci", report_in_placement=True)
722716
self.start_compute(hostname="compute1", pci_info=pci_info)
723717

724718
self.assertPCIDeviceCounts("compute1", total=1, free=1)
@@ -893,7 +887,7 @@ def test_reporting_disabled_nothing_is_reported(self):
893887
# Disable placement reporting so even if there are PCI devices on the
894888
# hypervisor matching the [pci]device_spec config they are not reported
895889
# to Placement
896-
self.mock_pci_report_in_placement.return_value = False
890+
self.flags(group="pci", report_in_placement=False)
897891
self.start_compute(hostname="compute1", pci_info=pci_info)
898892

899893
self.assert_placement_pci_view(
@@ -931,7 +925,7 @@ def test_reporting_cannot_be_disable_once_it_is_enabled(self):
931925

932926
# Try to disable placement reporting. The compute will refuse to start
933927
# as there are already PCI device RPs in placement.
934-
self.mock_pci_report_in_placement.return_value = False
928+
self.flags(group="pci", report_in_placement=False)
935929
ex = self.assertRaises(
936930
exception.PlacementPciException,
937931
self.restart_compute_service,
@@ -988,7 +982,7 @@ def test_heal_single_pci_allocation(self):
988982
self.flags(group='pci', device_spec=device_spec)
989983

990984
# Start a compute *without* PCI tracking in placement
991-
self.mock_pci_report_in_placement.return_value = False
985+
self.flags(group="pci", report_in_placement=False)
992986
self.start_compute(hostname="compute1", pci_info=pci_info)
993987
self.assertPCIDeviceCounts("compute1", total=1, free=1)
994988

@@ -999,7 +993,7 @@ def test_heal_single_pci_allocation(self):
999993
self.assertPCIDeviceCounts("compute1", total=1, free=0)
1000994

1001995
# Restart the compute but now with PCI tracking enabled
1002-
self.mock_pci_report_in_placement.return_value = True
996+
self.flags(group="pci", report_in_placement=True)
1003997
self.restart_compute_service("compute1")
1004998
# Assert that the PCI allocation is healed in placement
1005999
self.assertPCIDeviceCounts("compute1", total=1, free=0)
@@ -1057,7 +1051,7 @@ def test_heal_multiple_allocations(self):
10571051
self.flags(group='pci', device_spec=device_spec)
10581052

10591053
# Start a compute *without* PCI tracking in placement
1060-
self.mock_pci_report_in_placement.return_value = False
1054+
self.flags(group="pci", report_in_placement=False)
10611055
self.start_compute(hostname="compute1", pci_info=pci_info)
10621056
# 2 PCI + 1 PF + 4 VFs
10631057
self.assertPCIDeviceCounts("compute1", total=7, free=7)
@@ -1082,7 +1076,7 @@ def test_heal_multiple_allocations(self):
10821076
self.assertPCIDeviceCounts("compute1", total=7, free=1)
10831077

10841078
# Restart the compute but now with PCI tracking enabled
1085-
self.mock_pci_report_in_placement.return_value = True
1079+
self.flags(group="pci", report_in_placement=True)
10861080
self.restart_compute_service("compute1")
10871081
# Assert that the PCI allocation is healed in placement
10881082
self.assertPCIDeviceCounts("compute1", total=7, free=1)
@@ -1157,7 +1151,7 @@ def test_heal_partial_allocations(self):
11571151
self.flags(group='pci', device_spec=device_spec)
11581152

11591153
# Start a compute with PCI tracking in placement
1160-
self.mock_pci_report_in_placement.return_value = True
1154+
self.flags(group="pci", report_in_placement=True)
11611155
self.start_compute(hostname="compute1", pci_info=pci_info)
11621156
# 2 PCI + 1 PF + 4 VFs
11631157
self.assertPCIDeviceCounts("compute1", total=7, free=7)
@@ -1234,7 +1228,7 @@ def test_heal_partial_allocations_during_resize_downsize(self):
12341228
self.flags(group='pci', device_spec=compute1_device_spec)
12351229

12361230
# Start a compute with PCI tracking in placement
1237-
self.mock_pci_report_in_placement.return_value = True
1231+
self.flags(group="pci", report_in_placement=True)
12381232
self.start_compute(hostname="compute1", pci_info=compute1_pci_info)
12391233
self.assertPCIDeviceCounts("compute1", total=2, free=2)
12401234
compute1_expected_placement_view = {
@@ -1395,7 +1389,7 @@ def test_heal_partial_allocations_during_resize_change_dev_type(self):
13951389
self.flags(group='pci', device_spec=compute1_device_spec)
13961390

13971391
# Start a compute with PCI tracking in placement
1398-
self.mock_pci_report_in_placement.return_value = True
1392+
self.flags(group="pci", report_in_placement=True)
13991393
self.start_compute(hostname="compute1", pci_info=compute1_pci_info)
14001394
self.assertPCIDeviceCounts("compute1", total=1, free=1)
14011395
compute1_expected_placement_view = {
@@ -1458,7 +1452,7 @@ def test_heal_partial_allocations_during_resize_change_dev_type(self):
14581452
self.flags(group='pci', device_spec=compute2_device_spec)
14591453

14601454
# Start a compute with PCI tracking in placement
1461-
self.mock_pci_report_in_placement.return_value = True
1455+
self.flags(group="pci", report_in_placement=True)
14621456
self.start_compute(hostname="compute2", pci_info=compute2_pci_info)
14631457
self.assertPCIDeviceCounts("compute2", total=3, free=3)
14641458
compute2_expected_placement_view = {
@@ -1533,7 +1527,7 @@ def test_heal_allocation_during_same_host_resize(self):
15331527
)
15341528
self.flags(group='pci', device_spec=compute1_device_spec)
15351529
# Start a compute with PCI tracking in placement
1536-
self.mock_pci_report_in_placement.return_value = True
1530+
self.flags(group="pci", report_in_placement=True)
15371531
self.start_compute(hostname="compute1", pci_info=compute1_pci_info)
15381532
self.assertPCIDeviceCounts("compute1", total=3, free=3)
15391533
compute1_expected_placement_view = {

nova/tests/functional/libvirt/test_pci_sriov_servers.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,13 +1742,7 @@ class PCIServersTest(_PCIServersTestBase):
17421742

17431743
def setUp(self):
17441744
super().setUp()
1745-
patcher = mock.patch(
1746-
"nova.compute.pci_placement_translator."
1747-
"_is_placement_tracking_enabled",
1748-
return_value=True
1749-
)
1750-
self.addCleanup(patcher.stop)
1751-
patcher.start()
1745+
self.flags(group="pci", report_in_placement=True)
17521746

17531747
def test_create_server_with_pci_dev_and_numa(self):
17541748
"""Verifies that an instance can be booted with cpu pinning and with an
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
features:
3+
- |
4+
Nova started tracking PCI devices in Placement. This is an optional feature
5+
disable by default while we are implementing inventory tracking and
6+
scheduling support for both PCI passthrough devices and SR-IOV devices
7+
consumed via Neutron ports. Please read our
8+
`documentation <https://docs.openstack.org/nova/latest/admin/pci-passthrough.html#pci-tracking-in-placement>`_
9+
for more details on what is supported how this feature can be enabled.

0 commit comments

Comments
 (0)