Skip to content

Commit 41096f8

Browse files
committed
[pwmgmt]ignore missin governor when cpu_state used
When cpu_state power management strategy is requested nova-compute should not fail to start if there is no cpufreq governor is supported by the host. Closes-Bug: #2045966 Change-Id: Ice2fa47bdab320a7e472fbb4767761448d176bad (cherry picked from commit ed2ac71) (cherry picked from commit 3c054dc)
1 parent 2d05ee3 commit 41096f8

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,42 @@ def test_validate_all_dedicated_cpus_no_cpu(self):
237237
api.validate_all_dedicated_cpus()
238238
# no assert we want to make sure the validation won't raise if
239239
# no dedicated cpus are configured
240+
241+
@mock.patch.object(core, 'get_governor')
242+
@mock.patch.object(core, 'get_online')
243+
def test_validate_all_dedicated_cpus_for_cpu_state_no_governor_ignored(
244+
self, mock_get_online, mock_get_governor
245+
):
246+
self.flags(cpu_power_management=True, group='libvirt')
247+
self.flags(cpu_dedicated_set='0-2', group='compute')
248+
self.flags(cpu_power_management_strategy='cpu_state', group='libvirt')
249+
250+
mock_get_online.return_value = True
251+
mock_get_governor.side_effect = FileNotFoundError(
252+
"File /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor "
253+
"could not be found.")
254+
255+
api.validate_all_dedicated_cpus()
256+
257+
self.assertEqual(2, len(mock_get_governor.mock_calls))
258+
259+
@mock.patch.object(core, 'get_governor')
260+
@mock.patch.object(core, 'get_online')
261+
def test_validate_all_dedicated_cpus_for_governor_error(
262+
self, mock_get_online, mock_get_governor
263+
):
264+
self.flags(cpu_power_management=True, group='libvirt')
265+
self.flags(cpu_dedicated_set='0-2', group='compute')
266+
self.flags(cpu_power_management_strategy='governor', group='libvirt')
267+
268+
mock_get_online.return_value = True
269+
mock_get_governor.side_effect = FileNotFoundError(
270+
"File /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor "
271+
"could not be found.")
272+
273+
ex = self.assertRaises(
274+
exception.InvalidConfiguration, api.validate_all_dedicated_cpus)
275+
self.assertIn(
276+
"[libvirt]cpu_power_management_strategy is 'governor', "
277+
"but the host OS does not support governors for CPU0",
278+
str(ex))

nova/virt/libvirt/cpu/api.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,24 @@ def validate_all_dedicated_cpus() -> None:
137137
continue
138138
pcpu = Core(pcpu)
139139
# we need to collect the governors strategy and the CPU states
140-
governors.add(pcpu.governor)
140+
try:
141+
governors.add(pcpu.governor)
142+
except FileNotFoundError as e:
143+
# NOTE(gibi): When
144+
# /sys/devices/system/cpu/cpuX/cpufreq/scaling_governor does
145+
# not exist it means the host OS does not support any governors.
146+
# If cpu_state strategy is requested we can ignore this as
147+
# governors will not be used but if governor strategy is requested
148+
# we need to report an error and stop as the host is not properly
149+
# configured
150+
if CONF.libvirt.cpu_power_management_strategy == 'governor':
151+
msg = _(
152+
"[libvirt]cpu_power_management_strategy is 'governor', "
153+
"but the host OS does not support governors for CPU%d"
154+
% pcpu.ident
155+
)
156+
raise exception.InvalidConfiguration(msg) from e
157+
141158
cpu_states.add(pcpu.online)
142159
if CONF.libvirt.cpu_power_management_strategy == 'cpu_state':
143160
# all the cores need to have the same governor strategy

0 commit comments

Comments
 (0)