diff --git a/nova/compute/cpumodel.py b/nova/compute/cpumodel.py deleted file mode 100644 index 5f531fbe636..00000000000 --- a/nova/compute/cpumodel.py +++ /dev/null @@ -1,45 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -POLICY_FORCE = 'force' -POLICY_REQUIRE = 'require' -POLICY_OPTIONAL = 'optional' -POLICY_DISABLE = 'disable' -POLICY_FORBID = 'forbid' - -ALL_POLICIES = [ - POLICY_FORCE, - POLICY_REQUIRE, - POLICY_OPTIONAL, - POLICY_DISABLE, - POLICY_FORBID, -] - -MODE_CUSTOM = 'custom' -MODE_HOST_MODEL = 'host-model' -MODE_HOST_PASSTHROUGH = 'host-passthrough' - -ALL_CPUMODES = [ - MODE_CUSTOM, - MODE_HOST_MODEL, - MODE_HOST_PASSTHROUGH, -] - -MATCH_MINIMUM = 'minimum' -MATCH_EXACT = 'exact' -MATCH_STRICT = 'strict' - -ALL_MATCHES = [ - MATCH_MINIMUM, - MATCH_EXACT, - MATCH_STRICT, -] diff --git a/nova/objects/fields.py b/nova/objects/fields.py index df77f2c7555..858fd5ad013 100644 --- a/nova/objects/fields.py +++ b/nova/objects/fields.py @@ -18,8 +18,6 @@ from oslo_versionedobjects import fields import six -# TODO(berrange) Temporary import for CPU* classes -from nova.compute import cpumodel # TODO(berrange) Temporary import for HVType class from nova.compute import hv_type # TODO(berrange) Temporary import for VMMode class @@ -282,21 +280,32 @@ class CPUThreadAllocationPolicy(BaseNovaEnum): class CPUMode(BaseNovaEnum): - # TODO(berrange): move all constants out of 'nova.compute.cpumodel' - # into fields on this class - ALL = cpumodel.ALL_CPUMODES + + CUSTOM = 'custom' + HOST_MODEL = 'host-model' + HOST_PASSTHROUGH = 'host-passthrough' + + ALL = (CUSTOM, HOST_MODEL, HOST_PASSTHROUGH) class CPUMatch(BaseNovaEnum): - # TODO(berrange): move all constants out of 'nova.compute.cpumodel' - # into fields on this class - ALL = cpumodel.ALL_MATCHES + + MINIMUM = 'minimum' + EXACT = 'exact' + STRICT = 'strict' + + ALL = (MINIMUM, EXACT, STRICT) class CPUFeaturePolicy(BaseNovaEnum): - # TODO(berrange): move all constants out of 'nova.compute.cpumodel' - # into fields on this class - ALL = cpumodel.ALL_POLICIES + + FORCE = 'force' + REQUIRE = 'require' + OPTIONAL = 'optional' + DISABLE = 'disable' + FORBID = 'forbid' + + ALL = (FORCE, REQUIRE, OPTIONAL, DISABLE, FORBID) class DiskBus(BaseNovaEnum): diff --git a/nova/tests/unit/objects/test_objects.py b/nova/tests/unit/objects/test_objects.py index b90656806fc..6c92f39337a 100644 --- a/nova/tests/unit/objects/test_objects.py +++ b/nova/tests/unit/objects/test_objects.py @@ -1201,8 +1201,8 @@ def obj_name(cls): 'Usage': '1.1-b738dbebeb20e3199fc0ebca6e292a47', 'UsageList': '1.0-de53f0fd078c27cc1d43400f4e8bcef8', 'USBDeviceBus': '1.0-e4c7dd6032e46cd74b027df5eb2d4750', - 'VirtCPUFeature': '1.0-3310718d8c72309259a6e39bdefe83ee', - 'VirtCPUModel': '1.0-288f2139801b5ed5ed1be25c93c7b845', + 'VirtCPUFeature': '1.0-ea2464bdd09084bd388e5f61d5d4fc86', + 'VirtCPUModel': '1.0-5e1864af9227f698326203d7249796b5', 'VirtCPUTopology': '1.0-fc694de72e20298f7c6bab1083fd4563', 'VirtualInterface': '1.3-efd3ca8ebcc5ce65fff5a25f31754c54', 'VirtualInterfaceList': '1.0-9750e2074437b3077e46359102779fc6', diff --git a/nova/tests/unit/objects/test_vcpu_model.py b/nova/tests/unit/objects/test_vcpu_model.py index 8059488696b..c2bb7451a6d 100644 --- a/nova/tests/unit/objects/test_vcpu_model.py +++ b/nova/tests/unit/objects/test_vcpu_model.py @@ -10,13 +10,12 @@ # License for the specific language governing permissions and limitations # under the License. -from nova.compute import cpumodel from nova import objects from nova.objects import fields as obj_fields from nova.tests.unit.objects import test_objects fake_cpu_model_feature = { - 'policy': cpumodel.POLICY_REQUIRE, + 'policy': obj_fields.CPUFeaturePolicy.REQUIRE, 'name': 'sse2', } @@ -26,10 +25,10 @@ fake_vcpumodel_dict = { 'arch': obj_fields.Architecture.I686, 'vendor': 'fake-vendor', - 'match': cpumodel.MATCH_EXACT, + 'match': obj_fields.CPUMatch.EXACT, 'topology': objects.VirtCPUTopology(sockets=1, cores=1, threads=1), 'features': [fake_cpu_model_feature_obj], - 'mode': cpumodel.MODE_HOST_MODEL, + 'mode': obj_fields.CPUMode.HOST_MODEL, 'model': 'fake-model', } fake_vcpumodel = objects.VirtCPUModel(**fake_vcpumodel_dict) diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 034aa0d8e68..9648a0e5d26 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -56,7 +56,6 @@ from six.moves import range from nova.api.metadata import base as instance_metadata -from nova.compute import cpumodel from nova.compute import manager from nova.compute import power_state from nova.compute import task_states @@ -5727,7 +5726,7 @@ def test_get_guest_with_perf_supported(self, for f in ('cmt', 'mbm_local', 'mbm_total'): feature = vconfig.LibvirtConfigGuestCPUFeature() feature.name = f - feature.policy = cpumodel.POLICY_REQUIRE + feature.policy = fields.CPUFeaturePolicy.REQUIRE features.append(feature) caps.host.cpu.features = set(features) @@ -17007,25 +17006,25 @@ def test_vcpu_model_from_config(self): feature1 = vconfig.LibvirtConfigGuestCPUFeature() feature2 = vconfig.LibvirtConfigGuestCPUFeature() feature1.name = 'sse' - feature1.policy = cpumodel.POLICY_REQUIRE + feature1.policy = fields.CPUFeaturePolicy.REQUIRE feature2.name = 'aes' - feature2.policy = cpumodel.POLICY_REQUIRE + feature2.policy = fields.CPUFeaturePolicy.REQUIRE cpu.features = set([feature1, feature2]) - cpu.mode = cpumodel.MODE_CUSTOM + cpu.mode = fields.CPUMode.CUSTOM cpu.sockets = 1 cpu.cores = 2 cpu.threads = 4 vcpu_model = drv._cpu_config_to_vcpu_model(cpu, None) - self.assertEqual(cpumodel.MATCH_EXACT, vcpu_model.match) - self.assertEqual(cpumodel.MODE_CUSTOM, vcpu_model.mode) + self.assertEqual(fields.CPUMatch.EXACT, vcpu_model.match) + self.assertEqual(fields.CPUMode.CUSTOM, vcpu_model.mode) self.assertEqual(4, vcpu_model.topology.threads) self.assertEqual(set(['sse', 'aes']), set([f.name for f in vcpu_model.features])) - cpu.mode = cpumodel.MODE_HOST_MODEL + cpu.mode = fields.CPUMode.HOST_MODEL vcpu_model_1 = drv._cpu_config_to_vcpu_model(cpu, vcpu_model) - self.assertEqual(cpumodel.MODE_HOST_MODEL, vcpu_model.mode) + self.assertEqual(fields.CPUMode.HOST_MODEL, vcpu_model.mode) self.assertEqual(vcpu_model, vcpu_model_1) @mock.patch.object(lvm, 'get_volume_size', return_value=10) @@ -17112,24 +17111,24 @@ def test_cleanup_encrypted_lvm(self): def test_vcpu_model_to_config(self): drv = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) - feature = objects.VirtCPUFeature(policy=cpumodel.POLICY_REQUIRE, - name='sse') - feature_1 = objects.VirtCPUFeature(policy=cpumodel.POLICY_FORBID, - name='aes') + feature = objects.VirtCPUFeature( + policy=fields.CPUFeaturePolicy.REQUIRE, name='sse') + feature_1 = objects.VirtCPUFeature( + policy=fields.CPUFeaturePolicy.FORBID, name='aes') topo = objects.VirtCPUTopology(sockets=1, cores=2, threads=4) - vcpu_model = objects.VirtCPUModel(mode=cpumodel.MODE_HOST_MODEL, + vcpu_model = objects.VirtCPUModel(mode=fields.CPUMode.HOST_MODEL, features=[feature, feature_1], topology=topo) cpu = drv._vcpu_model_to_cpu_config(vcpu_model) - self.assertEqual(cpumodel.MODE_HOST_MODEL, cpu.mode) + self.assertEqual(fields.CPUMode.HOST_MODEL, cpu.mode) self.assertEqual(1, cpu.sockets) self.assertEqual(4, cpu.threads) self.assertEqual(2, len(cpu.features)) self.assertEqual(set(['sse', 'aes']), set([f.name for f in cpu.features])) - self.assertEqual(set([cpumodel.POLICY_REQUIRE, - cpumodel.POLICY_FORBID]), + self.assertEqual(set([fields.CPUFeaturePolicy.REQUIRE, + fields.CPUFeaturePolicy.FORBID]), set([f.policy for f in cpu.features])) def test_trigger_crash_dump(self):