Allow enabling cpu_power_management with 0 dedicated CPUs

The CPU power management feature of the libvirt driver, enabled with
[libvirt]cpu_power_management, only manages dedicated CPUs and does not
touch share CPUs. Today nova-compute refuses to start if configured
with [libvirt]cpu_power_management=true [compute]cpu_dedicated_set=None.
While this is functionally not limiting it does limit the possibility to
independently enable the power management and define the
cpu_dedicated_set. E.g. there might be a need to enable the former in
the whole cloud in a single step, while not all nodes of the cloud will
have dedicated CPUs configured.

This patch removes the strict config check. The implementation already
handles each PCPU individually, so if there are an empty list of PCPUs
then it does nothing.

Closes-Bug: #2043707
Change-Id: Ib070e1042c0526f5875e34fa4f0d569590ec2514
This commit is contained in:
Balazs Gibizer 2023-11-16 18:01:29 +01:00
parent e5e5e00579
commit b1a0aee1ab
5 changed files with 28 additions and 16 deletions

View File

@ -108,14 +108,13 @@ class PowerManagementTests(PowerManagementTestsBase):
cpu_dedicated_set = hardware.get_cpu_dedicated_set()
self._assert_cpu_set_state(cpu_dedicated_set, expected='offline')
def test_hardstop_compute_service_if_wrong_opt(self):
def test_compute_service_starts_with_power_management_and_zero_pcpu(self):
self.flags(cpu_dedicated_set=None, cpu_shared_set=None,
group='compute')
self.flags(vcpu_pin_set=None)
self.flags(cpu_power_management=True, group='libvirt')
self.assertRaises(exception.InvalidConfiguration,
self.start_compute, host_info=self.host_info,
hostname='compute2')
self.start_compute(host_info=self.host_info, hostname='compute2')
# NOTE(gibi): we test that no exception is raised by start_compute
def test_create_server(self):
server = self._create_server(

View File

@ -182,11 +182,14 @@ class TestAPI(test.NoDBTestCase):
api.power_down_all_dedicated_cpus()
mock_offline.assert_not_called()
def test_power_down_all_dedicated_cpus_wrong_config(self):
@mock.patch.object(core, 'set_offline')
def test_power_down_all_dedicated_cpus_no_dedicated_cpus_configured(
self, mock_offline
):
self.flags(cpu_power_management=True, group='libvirt')
self.flags(cpu_dedicated_set=None, group='compute')
self.assertRaises(exception.InvalidConfiguration,
api.power_down_all_dedicated_cpus)
api.power_down_all_dedicated_cpus()
mock_offline.assert_not_called()
@mock.patch.object(core, 'get_governor')
@mock.patch.object(core, 'get_online')
@ -233,3 +236,10 @@ class TestAPI(test.NoDBTestCase):
mock_warning.assert_called_once_with(
'CPU0 is in cpu_dedicated_set, but it is not eligible for '
'state management and will be ignored')
def test_validate_all_dedicated_cpus_no_cpu(self):
self.flags(cpu_power_management=True, group='libvirt')
self.flags(cpu_dedicated_set=None, group='compute')
api.validate_all_dedicated_cpus()
# no assert we want to make sure the validation won't raise if
# no dedicated cpus are configured

View File

@ -78,7 +78,7 @@ def get_cpu_dedicated_set():
def get_cpu_dedicated_set_nozero():
"""Return cpu_dedicated_set without CPU0, if present"""
return get_cpu_dedicated_set() - {0}
return (get_cpu_dedicated_set() or set()) - {0}
def get_cpu_shared_set():

View File

@ -118,14 +118,6 @@ def power_down(instance: objects.Instance) -> None:
def power_down_all_dedicated_cpus() -> None:
if not CONF.libvirt.cpu_power_management:
return
if (CONF.libvirt.cpu_power_management and
not CONF.compute.cpu_dedicated_set
):
msg = _("'[compute]/cpu_dedicated_set' is mandatory to be set if "
"'[libvirt]/cpu_power_management' is set."
"Please provide the CPUs that can be pinned or don't use the "
"power management if you only use shared CPUs.")
raise exception.InvalidConfiguration(msg)
cpu_dedicated_set = hardware.get_cpu_dedicated_set_nozero() or set()
for pcpu in cpu_dedicated_set:

View File

@ -0,0 +1,11 @@
---
fixes:
- |
Relaxed the config option checking of the cpu_power_management feature of
the libvirt driver. The nova-compute service will start with
[libvirt]cpu_power_management=True and an empty [compute]cpu_dedicated_set
configuration. The power management is still only applied to dedicated CPUs.
So the above configuration only allowed to ensure that cpu_power_management
can be enabled independently for configuring cpu_dedicated_set during
deployment.