From a931b0bf82362e8f5540b2118c4e8b6d403f45aa Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Tue, 16 Jan 2024 11:09:26 +0100 Subject: [PATCH] Revert "[pwmgmt]ignore missin governor when cpu_state used" This reverts commit 41096f83426bc21bd35b8a1dce0e103ba48c3140 as it has a bug in it expecting a wrong exception type (FileNotFoundError vs nova.exception.FileNotFound). Also there is a proper fix on master 2c4421568ea62e66257b55c08092de3e0303fb0a that can be backported instead. Change-Id: Id2c253a6e223bd5ba22512d9e5a40a9d12680da2 (cherry picked from commit 03ef4d6f53843bae9860e5f207453a5e741f3edc) (cherry picked from commit 25d0db782ecf3a032cae639563604ea6ffd80241) --- nova/tests/unit/virt/libvirt/cpu/test_api.py | 39 -------------------- nova/virt/libvirt/cpu/api.py | 19 +--------- 2 files changed, 1 insertion(+), 57 deletions(-) diff --git a/nova/tests/unit/virt/libvirt/cpu/test_api.py b/nova/tests/unit/virt/libvirt/cpu/test_api.py index 18b927302fd1..5e9af44e8ed9 100644 --- a/nova/tests/unit/virt/libvirt/cpu/test_api.py +++ b/nova/tests/unit/virt/libvirt/cpu/test_api.py @@ -237,42 +237,3 @@ class TestAPI(test.NoDBTestCase): api.validate_all_dedicated_cpus() # no assert we want to make sure the validation won't raise if # 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_no_governor_ignored( - self, mock_get_online, mock_get_governor - ): - self.flags(cpu_power_management=True, group='libvirt') - self.flags(cpu_dedicated_set='0-2', group='compute') - self.flags(cpu_power_management_strategy='cpu_state', group='libvirt') - - mock_get_online.return_value = True - mock_get_governor.side_effect = FileNotFoundError( - "File /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor " - "could not be found.") - - api.validate_all_dedicated_cpus() - - self.assertEqual(2, len(mock_get_governor.mock_calls)) - - @mock.patch.object(core, 'get_governor') - @mock.patch.object(core, 'get_online') - def test_validate_all_dedicated_cpus_for_governor_error( - self, mock_get_online, mock_get_governor - ): - self.flags(cpu_power_management=True, group='libvirt') - self.flags(cpu_dedicated_set='0-2', group='compute') - self.flags(cpu_power_management_strategy='governor', group='libvirt') - - mock_get_online.return_value = True - mock_get_governor.side_effect = FileNotFoundError( - "File /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor " - "could not be found.") - - ex = self.assertRaises( - exception.InvalidConfiguration, api.validate_all_dedicated_cpus) - self.assertIn( - "[libvirt]cpu_power_management_strategy is 'governor', " - "but the host OS does not support governors for CPU0", - str(ex)) diff --git a/nova/virt/libvirt/cpu/api.py b/nova/virt/libvirt/cpu/api.py index 0673b9e26f2d..060041c0f486 100644 --- a/nova/virt/libvirt/cpu/api.py +++ b/nova/virt/libvirt/cpu/api.py @@ -137,24 +137,7 @@ def validate_all_dedicated_cpus() -> None: continue pcpu = Core(pcpu) # we need to collect the governors strategy and the CPU states - try: - governors.add(pcpu.governor) - except FileNotFoundError as e: - # NOTE(gibi): When - # /sys/devices/system/cpu/cpuX/cpufreq/scaling_governor does - # not exist it means the host OS does not support any governors. - # If cpu_state strategy is requested we can ignore this as - # governors will not be used but if governor strategy is requested - # we need to report an error and stop as the host is not properly - # configured - if CONF.libvirt.cpu_power_management_strategy == 'governor': - msg = _( - "[libvirt]cpu_power_management_strategy is 'governor', " - "but the host OS does not support governors for CPU%d" - % pcpu.ident - ) - raise exception.InvalidConfiguration(msg) from e - + governors.add(pcpu.governor) cpu_states.add(pcpu.online) if CONF.libvirt.cpu_power_management_strategy == 'cpu_state': # all the cores need to have the same governor strategy