Skip to content

Commit b1a0aee

Browse files
committed
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
1 parent e5e5e00 commit b1a0aee

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

nova/tests/functional/libvirt/test_power_manage.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,13 @@ def setUp(self):
108108
cpu_dedicated_set = hardware.get_cpu_dedicated_set()
109109
self._assert_cpu_set_state(cpu_dedicated_set, expected='offline')
110110

111-
def test_hardstop_compute_service_if_wrong_opt(self):
111+
def test_compute_service_starts_with_power_management_and_zero_pcpu(self):
112112
self.flags(cpu_dedicated_set=None, cpu_shared_set=None,
113113
group='compute')
114114
self.flags(vcpu_pin_set=None)
115115
self.flags(cpu_power_management=True, group='libvirt')
116-
self.assertRaises(exception.InvalidConfiguration,
117-
self.start_compute, host_info=self.host_info,
118-
hostname='compute2')
116+
self.start_compute(host_info=self.host_info, hostname='compute2')
117+
# NOTE(gibi): we test that no exception is raised by start_compute
119118

120119
def test_create_server(self):
121120
server = self._create_server(

nova/tests/unit/virt/libvirt/cpu/test_api.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,14 @@ def test_power_down_all_dedicated_cpus_skipped(self, mock_offline):
182182
api.power_down_all_dedicated_cpus()
183183
mock_offline.assert_not_called()
184184

185-
def test_power_down_all_dedicated_cpus_wrong_config(self):
185+
@mock.patch.object(core, 'set_offline')
186+
def test_power_down_all_dedicated_cpus_no_dedicated_cpus_configured(
187+
self, mock_offline
188+
):
186189
self.flags(cpu_power_management=True, group='libvirt')
187190
self.flags(cpu_dedicated_set=None, group='compute')
188-
self.assertRaises(exception.InvalidConfiguration,
189-
api.power_down_all_dedicated_cpus)
191+
api.power_down_all_dedicated_cpus()
192+
mock_offline.assert_not_called()
190193

191194
@mock.patch.object(core, 'get_governor')
192195
@mock.patch.object(core, 'get_online')
@@ -233,3 +236,10 @@ def test_validate_all_dedicated_cpus_for_cpu_state_warning(
233236
mock_warning.assert_called_once_with(
234237
'CPU0 is in cpu_dedicated_set, but it is not eligible for '
235238
'state management and will be ignored')
239+
240+
def test_validate_all_dedicated_cpus_no_cpu(self):
241+
self.flags(cpu_power_management=True, group='libvirt')
242+
self.flags(cpu_dedicated_set=None, group='compute')
243+
api.validate_all_dedicated_cpus()
244+
# no assert we want to make sure the validation won't raise if
245+
# no dedicated cpus are configured

nova/virt/hardware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def get_cpu_dedicated_set():
7878

7979
def get_cpu_dedicated_set_nozero():
8080
"""Return cpu_dedicated_set without CPU0, if present"""
81-
return get_cpu_dedicated_set() - {0}
81+
return (get_cpu_dedicated_set() or set()) - {0}
8282

8383

8484
def get_cpu_shared_set():

nova/virt/libvirt/cpu/api.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,6 @@ def power_down(instance: objects.Instance) -> None:
118118
def power_down_all_dedicated_cpus() -> None:
119119
if not CONF.libvirt.cpu_power_management:
120120
return
121-
if (CONF.libvirt.cpu_power_management and
122-
not CONF.compute.cpu_dedicated_set
123-
):
124-
msg = _("'[compute]/cpu_dedicated_set' is mandatory to be set if "
125-
"'[libvirt]/cpu_power_management' is set."
126-
"Please provide the CPUs that can be pinned or don't use the "
127-
"power management if you only use shared CPUs.")
128-
raise exception.InvalidConfiguration(msg)
129121

130122
cpu_dedicated_set = hardware.get_cpu_dedicated_set_nozero() or set()
131123
for pcpu in cpu_dedicated_set:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
fixes:
3+
- |
4+
Relaxed the config option checking of the cpu_power_management feature of
5+
the libvirt driver. The nova-compute service will start with
6+
[libvirt]cpu_power_management=True and an empty [compute]cpu_dedicated_set
7+
configuration. The power management is still only applied to dedicated CPUs.
8+
So the above configuration only allowed to ensure that cpu_power_management
9+
can be enabled independently for configuring cpu_dedicated_set during
10+
deployment.
11+

0 commit comments

Comments
 (0)