Merge "Allow enabling cpu_power_management with 0 dedicated CPUs"

This commit is contained in:
Zuul 2023-11-22 07:55:31 +00:00 committed by Gerrit Code Review
commit 670ba207bc
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.