From e388ff8ff52b909c10eb894223843a3a5e0787ea Mon Sep 17 00:00:00 2001 From: Sahid Orentino Ferdjaoui Date: Wed, 23 Sep 2015 05:47:37 -0400 Subject: [PATCH] virt: add constraint to handle realtime policy This commit makes pinning constraints to take into account of new introduced option cpu_realtime. It verifiy if the configuration is good or raise an error to user. Change-Id: Iefbb60fcc4f8d1a4b6f8ca8bac9c9a0d8bec3a62 Blueprint: libvirt-real-time --- nova/exception.py | 5 +++++ nova/tests/unit/virt/test_hardware.py | 12 ++++++++++++ nova/virt/hardware.py | 10 ++++++++++ 3 files changed, 27 insertions(+) diff --git a/nova/exception.py b/nova/exception.py index bf0e771c40f1..4652b189c494 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -1952,3 +1952,8 @@ class UnsupportedImageModel(Invalid): class HostMappingNotFound(Invalid): msg_fmt = _("Host '%(name)s' is not mapped to any cell") + + +class RealtimeConfigurationInvalid(Invalid): + msg_fmt = _("Cannot set realtime policy in a non dedicated " + "cpu pinning policy") diff --git a/nova/tests/unit/virt/test_hardware.py b/nova/tests/unit/virt/test_hardware.py index f2aa6525bfe7..9255f4d851f5 100644 --- a/nova/tests/unit/virt/test_hardware.py +++ b/nova/tests/unit/virt/test_hardware.py @@ -1090,6 +1090,18 @@ class NUMATopologyTest(test.NoDBTestCase): }, "expect": exception.ImageCPUPinningForbidden, }, + { + # Invalid CPU pinning policy with realtime + "flavor": objects.Flavor(vcpus=4, memory_mb=2048, + extra_specs={ + "hw:cpu_policy": "shared", + "hw:cpu_realtime": "yes", + }), + "image": { + "properties": {} + }, + "expect": exception.RealtimeConfigurationInvalid, + }, ] for testitem in testdata: diff --git a/nova/virt/hardware.py b/nova/virt/hardware.py index 2622b59e7771..0bb8c62eb683 100644 --- a/nova/virt/hardware.py +++ b/nova/virt/hardware.py @@ -959,6 +959,11 @@ def _numa_get_constraints_manual(nodes, flavor, cpu_list, mem_list): return objects.InstanceNUMATopology(cells=cells) +def is_realtime_enabled(flavor): + flavor_rt = flavor.get('extra_specs', {}).get("hw:cpu_realtime") + return strutils.bool_from_string(flavor_rt) + + def _numa_get_constraints_auto(nodes, flavor): if ((flavor.vcpus % nodes) > 0 or (flavor.memory_mb % nodes) > 0): @@ -989,6 +994,11 @@ def _add_cpu_pinning_constraint(flavor, image_meta, numa_topology): else: requested = image_pinning == "dedicated" + rt = is_realtime_enabled(flavor) + pi = image_pinning or flavor_pinning + if rt and pi != "dedicated": + raise exception.RealtimeConfigurationInvalid() + if not requested: return numa_topology