Skip to content

Commit

Permalink
Merge "objects: Move 'cpumodel' to 'fields.CPU*'"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Nov 29, 2016
2 parents f47716c + 33a52cd commit 99ca2ea
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 79 deletions.
45 changes: 0 additions & 45 deletions nova/compute/cpumodel.py

This file was deleted.

31 changes: 20 additions & 11 deletions nova/objects/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions nova/tests/unit/objects/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 3 additions & 4 deletions nova/tests/unit/objects/test_vcpu_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

Expand All @@ -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)
Expand Down
33 changes: 16 additions & 17 deletions nova/tests/unit/virt/libvirt/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 99ca2ea

Please sign in to comment.