From 433796779e4f31320e6c57527f421d4e9aaacedc Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Tue, 9 Feb 2021 11:53:12 +0000 Subject: [PATCH] Fix error when setting cpu-dedicated-set Change-Id: Ic89d48f81af46682dc251cfdd6d88152c7039b0f Closes-Bug: #1897275 --- hooks/nova_compute_context.py | 12 +++------- unit_tests/test_nova_compute_contexts.py | 30 +++++++++++++++++++++++- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/hooks/nova_compute_context.py b/hooks/nova_compute_context.py index c1d4c0b4..c79f4a0c 100644 --- a/hooks/nova_compute_context.py +++ b/hooks/nova_compute_context.py @@ -38,7 +38,6 @@ from charmhelpers.core.hookenv import ( service_name, ERROR, INFO, - WARNING, ) from charmhelpers.contrib.openstack.utils import ( get_os_version_package, @@ -278,18 +277,13 @@ class NovaComputeLibvirtContext(context.OSContextGenerator): if config('pci-alias'): ctxt['pci_alias'] = config('pci-alias') - if config('vcpu-pin-set'): + if config('cpu-dedicated-set'): + ctxt['cpu_dedicated_set'] = config('cpu-dedicated-set') + elif config('vcpu-pin-set'): ctxt['vcpu_pin_set'] = config('vcpu-pin-set') if config('cpu-shared-set'): ctxt['cpu_shared_set'] = config('cpu-shared-set') - if config('cpu-dedicated-set'): - ctxt['cpu_dedicated_set'] = config('cpu-dedicated-set') - if ctxt['vcpu_pin_set']: - w = ("Ignoring vcpu-pin-set config since that option can't be " - "used with cpu-dedicated-set.") - log(w, level=WARNING) - ctxt['vcpu_pin_set'] = None if config('virtio-net-tx-queue-size'): ctxt['virtio_net_tx_queue_size'] = ( diff --git a/unit_tests/test_nova_compute_contexts.py b/unit_tests/test_nova_compute_contexts.py index 506782bb..ac4c8cc1 100644 --- a/unit_tests/test_nova_compute_contexts.py +++ b/unit_tests/test_nova_compute_contexts.py @@ -691,7 +691,6 @@ class NovaComputeContextTests(CharmTestCase): 'listen_tls': 0, 'host_uuid': self.host_uuid, 'reserved_host_memory': 1024, - 'vcpu_pin_set': None, 'force_raw_images': True, 'inject_password': False, 'inject_partition': -2, @@ -723,6 +722,35 @@ class NovaComputeContextTests(CharmTestCase): 'inject_partition': -2, 'default_ephemeral_format': 'ext4'}, libvirt()) + def test_cpu_dedicated_set(self): + self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) + self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'} + self.test_config.set('cpu-shared-set', '4-15') + self.test_config.set('cpu-dedicated-set', '16-31') + libvirt = context.NovaComputeLibvirtContext() + + expected = {'libvirtd_opts': '-d', + 'libvirt_user': 'libvirtd', + 'arch': platform.machine(), + 'ksm': 'AUTO', + 'kvm_hugepages': 0, + 'listen_tls': 0, + 'host_uuid': self.host_uuid, + 'reserved_host_memory': 512, + 'cpu_shared_set': '4-15', + 'cpu_dedicated_set': '16-31', + 'force_raw_images': True, + 'inject_password': False, + 'inject_partition': -2, + 'default_ephemeral_format': 'ext4'} + + self.assertEqual(expected, libvirt()) + + # should be ignored + self.test_config.set('vcpu-pin-set', '16-31') + libvirt = context.NovaComputeLibvirtContext() + self.assertEqual(expected, libvirt()) + def test_ksm_configs(self): self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'}