cpu: Only check governor type on online cores
Kernels don't accept to access the governor strategy on an offline core, so we need to only validate strategies for online cores. Change-Id: I14c9b268d0b97221216bd1a9ab9e48b48d6dcc2c Closes-Bug: #2073528
This commit is contained in:
parent
e82854dc8c
commit
757c333c0e
@ -244,3 +244,21 @@ class TestAPI(test.NoDBTestCase):
|
|||||||
self.api.validate_all_dedicated_cpus()
|
self.api.validate_all_dedicated_cpus()
|
||||||
# no assert we want to make sure the validation won't raise if
|
# no assert we want to make sure the validation won't raise if
|
||||||
# no dedicated cpus are configured
|
# no dedicated cpus are configured
|
||||||
|
|
||||||
|
@mock.patch.object(core, 'get_governor')
|
||||||
|
@mock.patch.object(core, 'get_online')
|
||||||
|
def test_validate_all_dedicated_cpus_for_cpu_state_with_off_cores(
|
||||||
|
self, mock_get_online, mock_get_governor):
|
||||||
|
self.flags(cpu_power_management=True, group='libvirt')
|
||||||
|
self.flags(cpu_dedicated_set='1-3', group='compute')
|
||||||
|
self.flags(cpu_power_management_strategy='cpu_state', group='libvirt')
|
||||||
|
# CPU1 and CPU3 are online while CPU2 is offline
|
||||||
|
mock_get_online.side_effect = (True, False, True)
|
||||||
|
mock_get_governor.return_value = 'performance'
|
||||||
|
self.api.validate_all_dedicated_cpus()
|
||||||
|
|
||||||
|
mock_get_online.assert_has_calls([mock.call(1), mock.call(2),
|
||||||
|
mock.call(3)])
|
||||||
|
# we only have two calls as CPU2 was skipped
|
||||||
|
mock_get_governor.assert_has_calls([mock.call(1),
|
||||||
|
mock.call(3)])
|
||||||
|
@ -172,8 +172,7 @@ class API(object):
|
|||||||
if not CONF.libvirt.cpu_power_management:
|
if not CONF.libvirt.cpu_power_management:
|
||||||
return
|
return
|
||||||
cpu_dedicated_set = hardware.get_cpu_dedicated_set() or set()
|
cpu_dedicated_set = hardware.get_cpu_dedicated_set() or set()
|
||||||
governors = set()
|
pcpus = []
|
||||||
cpu_states = set()
|
|
||||||
for pcpu in cpu_dedicated_set:
|
for pcpu in cpu_dedicated_set:
|
||||||
if (pcpu == 0 and
|
if (pcpu == 0 and
|
||||||
CONF.libvirt.cpu_power_management_strategy == 'cpu_state'):
|
CONF.libvirt.cpu_power_management_strategy == 'cpu_state'):
|
||||||
@ -181,11 +180,13 @@ class API(object):
|
|||||||
'but it is not eligible for state management '
|
'but it is not eligible for state management '
|
||||||
'and will be ignored')
|
'and will be ignored')
|
||||||
continue
|
continue
|
||||||
pcpu = self.core(pcpu)
|
|
||||||
# we need to collect the governors strategy and the CPU states
|
# we need to collect the governors strategy and the CPU states
|
||||||
governors.add(pcpu.governor)
|
pcpus.append(self.core(pcpu))
|
||||||
cpu_states.add(pcpu.online)
|
|
||||||
if CONF.libvirt.cpu_power_management_strategy == 'cpu_state':
|
if CONF.libvirt.cpu_power_management_strategy == 'cpu_state':
|
||||||
|
# NOTE(sbauza): offline cores can't have a governor, it returns a
|
||||||
|
# DeviceBusy exception.
|
||||||
|
governors = set([pcpu.governor for pcpu in pcpus
|
||||||
|
if pcpu.online])
|
||||||
# all the cores need to have the same governor strategy
|
# all the cores need to have the same governor strategy
|
||||||
if len(governors) > 1:
|
if len(governors) > 1:
|
||||||
msg = _("All the cores need to have the same governor strategy"
|
msg = _("All the cores need to have the same governor strategy"
|
||||||
@ -193,6 +194,7 @@ class API(object):
|
|||||||
"compute node if you prefer.")
|
"compute node if you prefer.")
|
||||||
raise exception.InvalidConfiguration(msg)
|
raise exception.InvalidConfiguration(msg)
|
||||||
elif CONF.libvirt.cpu_power_management_strategy == 'governor':
|
elif CONF.libvirt.cpu_power_management_strategy == 'governor':
|
||||||
|
cpu_states = set([pcpu.online for pcpu in pcpus])
|
||||||
# all the cores need to be online
|
# all the cores need to be online
|
||||||
if False in cpu_states:
|
if False in cpu_states:
|
||||||
msg = _("All the cores need to be online before modifying the "
|
msg = _("All the cores need to be online before modifying the "
|
||||||
|
Loading…
Reference in New Issue
Block a user