From 747c0d04af95c8227823933c52f296fca1398cc2 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 17 Aug 2016 12:37:49 +0100 Subject: [PATCH] objects: Move 'hv_type' to 'fields.HVType' Resolve the relevant TODO. Migrate tests in the process. Change-Id: I760737578e1f4a7b35f97b4df72cde597ac519f0 --- nova/compute/hv_type.py | 106 ------------------ nova/objects/fields.py | 73 +++++++++++- nova/objects/hv_spec.py | 5 +- nova/scheduler/filters/image_props_filter.py | 3 +- nova/scheduler/ironic_host_manager.py | 4 +- nova/tests/unit/compute/test_hvtype.py | 52 --------- .../unit/compute/test_resource_tracker.py | 3 +- nova/tests/unit/objects/test_fields.py | 39 ++++++- nova/tests/unit/objects/test_hv_spec.py | 11 +- .../filters/test_image_props_filters.py | 65 +++++++---- nova/tests/unit/virt/xenapi/test_xenapi.py | 9 +- nova/virt/fake.py | 5 +- nova/virt/hyperv/hostops.py | 8 +- nova/virt/ironic/driver.py | 3 +- nova/virt/libvirt/driver.py | 3 +- nova/virt/vmwareapi/host.py | 9 +- nova/virt/xenapi/host.py | 3 +- 17 files changed, 182 insertions(+), 219 deletions(-) delete mode 100644 nova/compute/hv_type.py delete mode 100644 nova/tests/unit/compute/test_hvtype.py diff --git a/nova/compute/hv_type.py b/nova/compute/hv_type.py deleted file mode 100644 index 0840544e88b5..000000000000 --- a/nova/compute/hv_type.py +++ /dev/null @@ -1,106 +0,0 @@ -# Copyright 2014 Red Hat, Inc. -# All Rights Reserved. -# -# 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. - -"""Constants and helper APIs for dealing with virtualization types - -The constants provide the standard names for all known guest -virtualization types. This is not to be confused with the Nova -hypervisor driver types, since one driver may support multiple -virtualization types and one virtualization type (eg 'xen') may -be supported by multiple drivers ('XenAPI' or 'Libvirt-Xen'). -""" - -from nova import exception - - -# This list is all known hypervisors -# even if not currently supported by OpenStack. -BAREMETAL = "baremetal" -BHYVE = "bhyve" -DOCKER = "docker" -FAKE = "fake" -HYPERV = "hyperv" -IRONIC = "ironic" -KQEMU = "kqemu" -KVM = "kvm" -LXC = "lxc" -LXD = "lxd" -OPENVZ = "openvz" -PARALLELS = "parallels" -VIRTUOZZO = "vz" -PHYP = "phyp" -QEMU = "qemu" -TEST = "test" -UML = "uml" -VBOX = "vbox" -VMWARE = "vmware" -XEN = "xen" -ZVM = "zvm" - -ALL = ( - BAREMETAL, - BHYVE, - DOCKER, - FAKE, - HYPERV, - IRONIC, - KQEMU, - KVM, - LXC, - LXD, - OPENVZ, - PARALLELS, - PHYP, - QEMU, - TEST, - UML, - VBOX, - VIRTUOZZO, - VMWARE, - XEN, - ZVM, -) - - -def is_valid(name): - """Check if a string is a valid hypervisor type - - :param name: hypervisor type name to validate - - :returns: True if @name is valid - """ - return name in ALL - - -def canonicalize(name): - """Canonicalize the hypervisor type name - - :param name: hypervisor type name to canonicalize - - :returns: a canonical hypervisor type name - """ - - if name is None: - return None - - newname = name.lower() - - if newname == "xapi": - newname = XEN - - if not is_valid(newname): - raise exception.InvalidHypervisorVirtType(hv_type=name) - - return newname diff --git a/nova/objects/fields.py b/nova/objects/fields.py index 858fd5ad013e..7534bfad6cb0 100644 --- a/nova/objects/fields.py +++ b/nova/objects/fields.py @@ -18,8 +18,6 @@ import re from oslo_versionedobjects import fields import six -# TODO(berrange) Temporary import for HVType class -from nova.compute import hv_type # TODO(berrange) Temporary import for VMMode class from nova.compute import vm_mode from nova import exception @@ -332,18 +330,81 @@ class FirmwareType(BaseNovaEnum): class HVType(BaseNovaEnum): - # TODO(berrange): move all constants out of 'nova.compute.hv_type' - # into fields on this class - ALL = hv_type.ALL + """Represents virtualization types. + + Provide the standard names for all known guest virtualization + types. This is not to be confused with the Nova hypervisor driver + types, since one driver may support multiple virtualization types + and one virtualization type (eg 'xen') may be supported by multiple + drivers ('XenAPI' or 'Libvirt-Xen'). + """ + + BAREMETAL = 'baremetal' + BHYVE = 'bhyve' + DOCKER = 'docker' + FAKE = 'fake' + HYPERV = 'hyperv' + IRONIC = 'ironic' + KQEMU = 'kqemu' + KVM = 'kvm' + LXC = 'lxc' + LXD = 'lxd' + OPENVZ = 'openvz' + PARALLELS = 'parallels' + VIRTUOZZO = 'vz' + PHYP = 'phyp' + QEMU = 'qemu' + TEST = 'test' + UML = 'uml' + VBOX = 'vbox' + VMWARE = 'vmware' + XEN = 'xen' + ZVM = 'zvm' + + ALL = (BAREMETAL, BHYVE, DOCKER, FAKE, HYPERV, IRONIC, KQEMU, KVM, LXC, + LXD, OPENVZ, PARALLELS, PHYP, QEMU, TEST, UML, VBOX, VIRTUOZZO, + VMWARE, XEN, ZVM) def coerce(self, obj, attr, value): try: - value = hv_type.canonicalize(value) + value = self.canonicalize(value) except exception.InvalidHypervisorVirtType: msg = _("Hypervisor virt type '%s' is not valid") % value raise ValueError(msg) + return super(HVType, self).coerce(obj, attr, value) + @classmethod + def is_valid(cls, name): + """Check if a string is a valid hypervisor type + + :param name: hypervisor type name to validate + + :returns: True if @name is valid + """ + return name in cls.ALL + + @classmethod + def canonicalize(cls, name): + """Canonicalize the hypervisor type name + + :param name: hypervisor type name to canonicalize + + :returns: a canonical hypervisor type name + """ + if name is None: + return None + + newname = name.lower() + + if newname == 'xapi': + newname = cls.XEN + + if not cls.is_valid(newname): + raise exception.InvalidHypervisorVirtType(hv_type=name) + + return newname + class ImageSignatureHashType(BaseNovaEnum): # Represents the possible hash methods used for image signing diff --git a/nova/objects/hv_spec.py b/nova/objects/hv_spec.py index 60c8e57878f2..454f74396a78 100644 --- a/nova/objects/hv_spec.py +++ b/nova/objects/hv_spec.py @@ -15,7 +15,6 @@ from oslo_utils import versionutils -from nova.compute import hv_type from nova.objects import base from nova.objects import fields @@ -48,5 +47,5 @@ class HVSpec(base.NovaObject): super(HVSpec, self).obj_make_compatible(primitive, target_version) target_version = versionutils.convert_version_to_tuple(target_version) if (target_version < (1, 1) and 'hv_type' in primitive and - hv_type.VIRTUOZZO == primitive['hv_type']): - primitive['hv_type'] = hv_type.PARALLELS + fields.HVType.VIRTUOZZO == primitive['hv_type']): + primitive['hv_type'] = fields.HVType.PARALLELS diff --git a/nova/scheduler/filters/image_props_filter.py b/nova/scheduler/filters/image_props_filter.py index 8e6ad77f77b3..bd9ba7521687 100644 --- a/nova/scheduler/filters/image_props_filter.py +++ b/nova/scheduler/filters/image_props_filter.py @@ -19,7 +19,6 @@ from distutils import versionpredicate from oslo_log import log as logging from oslo_utils import versionutils -from nova.compute import hv_type from nova.compute import vm_mode from nova.objects import fields from nova.scheduler import filters @@ -48,7 +47,7 @@ class ImagePropertiesFilter(filters.BaseHostFilter): img_vm_mode = image_props.get('hw_vm_mode') checked_img_props = ( fields.Architecture.canonicalize(img_arch), - hv_type.canonicalize(img_h_type), + fields.HVType.canonicalize(img_h_type), vm_mode.canonicalize(img_vm_mode) ) diff --git a/nova/scheduler/ironic_host_manager.py b/nova/scheduler/ironic_host_manager.py index 391058ae6dae..bcb9d71b8a3a 100644 --- a/nova/scheduler/ironic_host_manager.py +++ b/nova/scheduler/ironic_host_manager.py @@ -21,10 +21,10 @@ This host manager will consume all cpu's, disk space, and ram from a host / node as it is supporting Baremetal hosts, which can not be subdivided into multiple instances. """ -from nova.compute import hv_type import nova.conf from nova import context as context_module from nova import objects +from nova.objects import fields as obj_fields from nova.scheduler import host_manager CONF = nova.conf.CONF @@ -78,7 +78,7 @@ class IronicHostManager(host_manager.HostManager): @staticmethod def _is_ironic_compute(compute): ht = compute.hypervisor_type if 'hypervisor_type' in compute else None - return ht == hv_type.IRONIC + return ht == obj_fields.HVType.IRONIC def _load_filters(self): if CONF.filter_scheduler.use_baremetal_filters: diff --git a/nova/tests/unit/compute/test_hvtype.py b/nova/tests/unit/compute/test_hvtype.py deleted file mode 100644 index 3c0e84e1c11e..000000000000 --- a/nova/tests/unit/compute/test_hvtype.py +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright (C) 2014 Red Hat, Inc. -# -# 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. - -from nova.compute import hv_type -from nova import exception -from nova import test - - -class HvTypeTest(test.NoDBTestCase): - - def test_valid_string(self): - self.assertTrue(hv_type.is_valid("vmware")) - - def test_valid_constant(self): - self.assertTrue(hv_type.is_valid(hv_type.QEMU)) - - def test_valid_docker(self): - self.assertTrue(hv_type.is_valid("docker")) - - def test_valid_lxd(self): - self.assertTrue(hv_type.is_valid("lxd")) - - def test_valid_vz(self): - self.assertTrue(hv_type.is_valid(hv_type.VIRTUOZZO)) - - def test_valid_bogus(self): - self.assertFalse(hv_type.is_valid("acmehypervisor")) - - def test_canonicalize_none(self): - self.assertIsNone(hv_type.canonicalize(None)) - - def test_canonicalize_case(self): - self.assertEqual(hv_type.QEMU, hv_type.canonicalize("QeMu")) - - def test_canonicalize_xapi(self): - self.assertEqual(hv_type.XEN, hv_type.canonicalize("xapi")) - - def test_canonicalize_invalid(self): - self.assertRaises(exception.InvalidHypervisorVirtType, - hv_type.canonicalize, - "wibble") diff --git a/nova/tests/unit/compute/test_resource_tracker.py b/nova/tests/unit/compute/test_resource_tracker.py index 11bdd9b4bd0f..1016cd0dbde2 100644 --- a/nova/tests/unit/compute/test_resource_tracker.py +++ b/nova/tests/unit/compute/test_resource_tracker.py @@ -19,7 +19,6 @@ from oslo_utils import timeutils from oslo_utils import units from nova.compute import claims -from nova.compute import hv_type from nova.compute.monitors import base as monitor_base from nova.compute import power_state from nova.compute import resource_tracker @@ -80,7 +79,7 @@ _COMPUTE_NODE_FIXTURES = [ supported_hv_specs=[ objects.HVSpec.from_list([ obj_fields.Architecture.I686, - hv_type.KVM, + obj_fields.HVType.KVM, vm_mode.HVM]) ], metrics=None, diff --git a/nova/tests/unit/objects/test_fields.py b/nova/tests/unit/objects/test_fields.py index 891a9486ad6d..ce644499beb4 100644 --- a/nova/tests/unit/objects/test_fields.py +++ b/nova/tests/unit/objects/test_fields.py @@ -224,12 +224,49 @@ class TestArchitecture(TestField): self.assertEqual(fields.Architecture.I686, fields.Architecture.canonicalize('x86_32p')) - def test_canonicalize_bogus(self): + def test_canonicalize_invalid(self): self.assertRaises(exception.InvalidArchitectureName, fields.Architecture.canonicalize, 'x86_64wibble') +class TestHVType(TestField): + def test_valid_string(self): + self.assertTrue(fields.HVType.is_valid('vmware')) + + def test_valid_constant(self): + self.assertTrue(fields.HVType.is_valid(fields.HVType.QEMU)) + + def test_valid_docker(self): + self.assertTrue(fields.HVType.is_valid('docker')) + + def test_valid_lxd(self): + self.assertTrue(fields.HVType.is_valid('lxd')) + + def test_valid_vz(self): + self.assertTrue(fields.HVType.is_valid( + fields.HVType.VIRTUOZZO)) + + def test_valid_bogus(self): + self.assertFalse(fields.HVType.is_valid('acmehypervisor')) + + def test_canonicalize_none(self): + self.assertIsNone(fields.HVType.canonicalize(None)) + + def test_canonicalize_case(self): + self.assertEqual(fields.HVType.QEMU, + fields.HVType.canonicalize('QeMu')) + + def test_canonicalize_xapi(self): + self.assertEqual(fields.HVType.XEN, + fields.HVType.canonicalize('xapi')) + + def test_canonicalize_invalid(self): + self.assertRaises(exception.InvalidHypervisorVirtType, + fields.HVType.canonicalize, + 'wibble') + + class TestImageSignatureTypes(TestField): # Ensure that the object definition is updated # in step with the signature_utils module diff --git a/nova/tests/unit/objects/test_hv_spec.py b/nova/tests/unit/objects/test_hv_spec.py index 6968bf58bc8a..1e5ba9f74e3f 100644 --- a/nova/tests/unit/objects/test_hv_spec.py +++ b/nova/tests/unit/objects/test_hv_spec.py @@ -13,7 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -from nova.compute import hv_type from nova.compute import vm_mode from nova import objects from nova.objects import fields as obj_fields @@ -22,25 +21,25 @@ from nova.tests.unit.objects import test_objects spec_dict = { 'arch': obj_fields.Architecture.I686, - 'hv_type': hv_type.KVM, + 'hv_type': obj_fields.HVType.KVM, 'vm_mode': vm_mode.HVM } spec_list = [ obj_fields.Architecture.I686, - hv_type.KVM, + obj_fields.HVType.KVM, vm_mode.HVM ] spec_dict_vz = { 'arch': obj_fields.Architecture.I686, - 'hv_type': hv_type.VIRTUOZZO, + 'hv_type': obj_fields.HVType.VIRTUOZZO, 'vm_mode': vm_mode.HVM } spec_dict_parallels = { 'arch': obj_fields.Architecture.I686, - 'hv_type': hv_type.PARALLELS, + 'hv_type': obj_fields.HVType.PARALLELS, 'vm_mode': vm_mode.HVM } @@ -54,7 +53,7 @@ class _TestHVSpecObject(object): def test_hv_spec_to_list(self): spec_obj = objects.HVSpec() spec_obj.arch = obj_fields.Architecture.I686 - spec_obj.hv_type = hv_type.KVM + spec_obj.hv_type = obj_fields.HVType.KVM spec_obj.vm_mode = vm_mode.HVM spec = spec_obj.to_list() self.assertEqual(spec_list, spec) diff --git a/nova/tests/unit/scheduler/filters/test_image_props_filters.py b/nova/tests/unit/scheduler/filters/test_image_props_filters.py index be0547b83d41..e08ad43de5d2 100644 --- a/nova/tests/unit/scheduler/filters/test_image_props_filters.py +++ b/nova/tests/unit/scheduler/filters/test_image_props_filters.py @@ -12,7 +12,6 @@ from oslo_utils import versionutils -from nova.compute import hv_type from nova.compute import vm_mode from nova import objects from nova.objects import fields as obj_fields @@ -31,14 +30,16 @@ class TestImagePropsFilter(test.NoDBTestCase): img_props = objects.ImageMeta( properties=objects.ImageMetaProps( hw_architecture=obj_fields.Architecture.X86_64, - img_hv_type=hv_type.KVM, + img_hv_type=obj_fields.HVType.KVM, hw_vm_mode=vm_mode.HVM, img_hv_requested_version='>=6.0,<6.2')) spec_obj = objects.RequestSpec(image=img_props) hypervisor_version = versionutils.convert_version_to_int('6.0.0') capabilities = { 'supported_instances': [( - obj_fields.Architecture.X86_64, hv_type.KVM, vm_mode.HVM)], + obj_fields.Architecture.X86_64, + obj_fields.HVType.KVM, + vm_mode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) @@ -47,13 +48,15 @@ class TestImagePropsFilter(test.NoDBTestCase): img_props = objects.ImageMeta( properties=objects.ImageMetaProps( hw_architecture=obj_fields.Architecture.ARMV7, - img_hv_type=hv_type.QEMU, + img_hv_type=obj_fields.HVType.QEMU, hw_vm_mode=vm_mode.HVM)) hypervisor_version = versionutils.convert_version_to_int('6.0.0') spec_obj = objects.RequestSpec(image=img_props) capabilities = { 'supported_instances': [( - obj_fields.Architecture.X86_64, hv_type.KVM, vm_mode.HVM)], + obj_fields.Architecture.X86_64, + obj_fields.HVType.KVM, + vm_mode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertFalse(self.filt_cls.host_passes(host, spec_obj)) @@ -62,7 +65,7 @@ class TestImagePropsFilter(test.NoDBTestCase): img_props = objects.ImageMeta( properties=objects.ImageMetaProps( hw_architecture=obj_fields.Architecture.X86_64, - img_hv_type=hv_type.KVM, + img_hv_type=obj_fields.HVType.KVM, hw_vm_mode=vm_mode.HVM, img_hv_requested_version='>=6.2')) hypervisor_version = versionutils.convert_version_to_int('6.0.0') @@ -70,7 +73,9 @@ class TestImagePropsFilter(test.NoDBTestCase): capabilities = { 'enabled': True, 'supported_instances': [( - obj_fields.Architecture.X86_64, hv_type.KVM, vm_mode.HVM)], + obj_fields.Architecture.X86_64, + obj_fields.HVType.KVM, + vm_mode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertFalse(self.filt_cls.host_passes(host, spec_obj)) @@ -84,7 +89,9 @@ class TestImagePropsFilter(test.NoDBTestCase): spec_obj = objects.RequestSpec(image=img_props) capabilities = { 'supported_instances': [( - obj_fields.Architecture.X86_64, hv_type.KVM, vm_mode.HVM)], + obj_fields.Architecture.X86_64, + obj_fields.HVType.KVM, + vm_mode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) @@ -98,7 +105,9 @@ class TestImagePropsFilter(test.NoDBTestCase): spec_obj = objects.RequestSpec(image=img_props) capabilities = { 'supported_instances': [( - obj_fields.Architecture.X86_64, hv_type.XEN, vm_mode.XEN)], + obj_fields.Architecture.X86_64, + obj_fields.HVType.XEN, + vm_mode.XEN)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertFalse(self.filt_cls.host_passes(host, spec_obj)) @@ -108,7 +117,9 @@ class TestImagePropsFilter(test.NoDBTestCase): hypervisor_version = versionutils.convert_version_to_int('6.0.0') capabilities = { 'supported_instances': [( - obj_fields.Architecture.X86_64, hv_type.KVM, vm_mode.HVM)], + obj_fields.Architecture.X86_64, + obj_fields.HVType.KVM, + vm_mode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) @@ -117,7 +128,7 @@ class TestImagePropsFilter(test.NoDBTestCase): img_props = objects.ImageMeta( properties=objects.ImageMetaProps( hw_architecture=obj_fields.Architecture.X86_64, - img_hv_type=hv_type.KVM, + img_hv_type=obj_fields.HVType.KVM, hw_vm_mode=vm_mode.HVM)) hypervisor_version = versionutils.convert_version_to_int('6.0.0') spec_obj = objects.RequestSpec(image=img_props) @@ -131,14 +142,16 @@ class TestImagePropsFilter(test.NoDBTestCase): img_props = objects.ImageMeta( properties=objects.ImageMetaProps( hw_architecture=obj_fields.Architecture.X86_64, - img_hv_type=hv_type.KVM, + img_hv_type=obj_fields.HVType.KVM, hw_vm_mode=vm_mode.HVM, img_hv_requested_version='>=6.0')) spec_obj = objects.RequestSpec(image=img_props) capabilities = { 'enabled': True, 'supported_instances': [( - obj_fields.Architecture.X86_64, hv_type.KVM, vm_mode.HVM)]} + obj_fields.Architecture.X86_64, + obj_fields.HVType.KVM, + vm_mode.HVM)]} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) @@ -146,14 +159,16 @@ class TestImagePropsFilter(test.NoDBTestCase): img_props = objects.ImageMeta( properties=objects.ImageMetaProps( hw_architecture=obj_fields.Architecture.X86_64, - img_hv_type=hv_type.KVM, + img_hv_type=obj_fields.HVType.KVM, hw_vm_mode=vm_mode.HVM, img_hv_requested_version='>=6.0')) spec_obj = objects.RequestSpec(image=img_props) capabilities = { 'enabled': True, 'supported_instances': [( - obj_fields.Architecture.X86_64, hv_type.KVM, vm_mode.HVM)], + obj_fields.Architecture.X86_64, + obj_fields.HVType.KVM, + vm_mode.HVM)], 'hypervisor_version': 5000} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertFalse(self.filt_cls.host_passes(host, spec_obj)) @@ -167,7 +182,9 @@ class TestImagePropsFilter(test.NoDBTestCase): spec_obj = objects.RequestSpec(image=img_props) capabilities = { 'supported_instances': [( - obj_fields.Architecture.X86_64, hv_type.XEN, vm_mode.XEN)], + obj_fields.Architecture.X86_64, + obj_fields.HVType.XEN, + vm_mode.XEN)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) @@ -181,7 +198,9 @@ class TestImagePropsFilter(test.NoDBTestCase): spec_obj = objects.RequestSpec(image=img_props) capabilities = { 'supported_instances': [( - obj_fields.Architecture.X86_64, hv_type.KVM, vm_mode.HVM)], + obj_fields.Architecture.X86_64, + obj_fields.HVType.KVM, + vm_mode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) @@ -195,7 +214,9 @@ class TestImagePropsFilter(test.NoDBTestCase): spec_obj = objects.RequestSpec(image=img_props) capabilities = { 'supported_instances': [( - obj_fields.Architecture.I686, hv_type.KVM, vm_mode.HVM)], + obj_fields.Architecture.I686, + obj_fields.HVType.KVM, + vm_mode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) @@ -209,7 +230,9 @@ class TestImagePropsFilter(test.NoDBTestCase): spec_obj = objects.RequestSpec(image=img_props) capabilities = { 'supported_instances': [( - obj_fields.Architecture.I686, hv_type.XEN, vm_mode.HVM)], + obj_fields.Architecture.I686, + obj_fields.HVType.XEN, + vm_mode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) @@ -224,7 +247,9 @@ class TestImagePropsFilter(test.NoDBTestCase): spec_obj = objects.RequestSpec(image=img_props) capabilities = { 'supported_instances': [( - obj_fields.Architecture.I686, hv_type.BAREMETAL, vm_mode.HVM)], + obj_fields.Architecture.I686, + obj_fields.HVType.BAREMETAL, + vm_mode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) diff --git a/nova/tests/unit/virt/xenapi/test_xenapi.py b/nova/tests/unit/virt/xenapi/test_xenapi.py index 9717057d8bc0..103f825a8c5a 100644 --- a/nova/tests/unit/virt/xenapi/test_xenapi.py +++ b/nova/tests/unit/virt/xenapi/test_xenapi.py @@ -34,7 +34,6 @@ import six import testtools from nova.compute import api as compute_api -from nova.compute import hv_type from nova.compute import power_state from nova.compute import task_states from nova.compute import utils as compute_utils @@ -2277,19 +2276,19 @@ class ToSupportedInstancesTestCase(test.NoDBTestCase): def test_return_value(self): self.assertEqual( - [(obj_fields.Architecture.X86_64, hv_type.XEN, 'xen')], + [(obj_fields.Architecture.X86_64, obj_fields.HVType.XEN, 'xen')], host.to_supported_instances([u'xen-3.0-x86_64'])) def test_invalid_values_do_not_break(self): self.assertEqual( - [(obj_fields.Architecture.X86_64, hv_type.XEN, 'xen')], + [(obj_fields.Architecture.X86_64, obj_fields.HVType.XEN, 'xen')], host.to_supported_instances([u'xen-3.0-x86_64', 'spam'])) def test_multiple_values(self): self.assertEqual( [ - (obj_fields.Architecture.X86_64, hv_type.XEN, 'xen'), - (obj_fields.Architecture.I686, hv_type.XEN, 'hvm') + (obj_fields.Architecture.X86_64, obj_fields.HVType.XEN, 'xen'), + (obj_fields.Architecture.I686, obj_fields.HVType.XEN, 'hvm') ], host.to_supported_instances([u'xen-3.0-x86_64', 'hvm-3.0-x86_32']) ) diff --git a/nova/virt/fake.py b/nova/virt/fake.py index 424f9856354a..31d193de2d8d 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -30,7 +30,6 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import versionutils -from nova.compute import hv_type from nova.compute import power_state from nova.compute import task_states from nova.compute import vm_mode @@ -148,7 +147,9 @@ class FakeDriver(driver.ComputeDriver): 'cpu_info': {}, 'disk_available_least': 0, 'supported_instances': [( - obj_fields.Architecture.X86_64, hv_type.FAKE, vm_mode.HVM)], + obj_fields.Architecture.X86_64, + obj_fields.HVType.FAKE, + vm_mode.HVM)], 'numa_topology': None, } self._mounts = {} diff --git a/nova/virt/hyperv/hostops.py b/nova/virt/hyperv/hostops.py index 2965aa88bb9a..2fabdc24619b 100644 --- a/nova/virt/hyperv/hostops.py +++ b/nova/virt/hyperv/hostops.py @@ -26,7 +26,6 @@ from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import units -from nova.compute import hv_type from nova.compute import vm_mode import nova.conf from nova.i18n import _ @@ -158,8 +157,11 @@ class HostOps(object): 'vcpus_used': 0, 'cpu_info': jsonutils.dumps(cpu_info), 'supported_instances': [ - (obj_fields.Architecture.I686, hv_type.HYPERV, vm_mode.HVM), - (obj_fields.Architecture.X86_64, hv_type.HYPERV, + (obj_fields.Architecture.I686, + obj_fields.HVType.HYPERV, + vm_mode.HVM), + (obj_fields.Architecture.X86_64, + obj_fields.HVType.HYPERV, vm_mode.HVM)], 'numa_topology': None, } diff --git a/nova/virt/ironic/driver.py b/nova/virt/ironic/driver.py index 53774faf1fff..e50bc767a318 100644 --- a/nova/virt/ironic/driver.py +++ b/nova/virt/ironic/driver.py @@ -34,7 +34,6 @@ import six import six.moves.urllib.parse as urlparse from nova.api.metadata import base as instance_metadata -from nova.compute import hv_type from nova.compute import power_state from nova.compute import task_states from nova.compute import vm_mode @@ -98,7 +97,7 @@ def _get_nodes_supported_instances(cpu_arch=None): if not cpu_arch: return [] return [(cpu_arch, - hv_type.BAREMETAL, + obj_fields.HVType.BAREMETAL, vm_mode.HVM)] diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index fe471e80da55..64e0d8ec979a 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -61,7 +61,6 @@ from six.moves import range from nova.api.metadata import base as instance_metadata from nova import block_device -from nova.compute import hv_type from nova.compute import power_state from nova.compute import task_states from nova.compute import utils as compute_utils @@ -5040,7 +5039,7 @@ class LibvirtDriver(driver.ComputeDriver): for dt in g.domtype: instance_cap = ( fields.Architecture.canonicalize(g.arch), - hv_type.canonicalize(dt), + fields.HVType.canonicalize(dt), vm_mode.canonicalize(g.ostype)) instance_caps.append(instance_cap) diff --git a/nova/virt/vmwareapi/host.py b/nova/virt/vmwareapi/host.py index 53bbfbb1042a..118201f78a7f 100644 --- a/nova/virt/vmwareapi/host.py +++ b/nova/virt/vmwareapi/host.py @@ -22,7 +22,6 @@ from oslo_utils import units from oslo_utils import versionutils from oslo_vmware import exceptions as vexc -from nova.compute import hv_type from nova.compute import vm_mode import nova.conf from nova import context @@ -98,8 +97,12 @@ class VCState(object): str(about_info.version)) data["hypervisor_hostname"] = self._host_name data["supported_instances"] = [ - (obj_fields.Architecture.I686, hv_type.VMWARE, vm_mode.HVM), - (obj_fields.Architecture.X86_64, hv_type.VMWARE, vm_mode.HVM)] + (obj_fields.Architecture.I686, + obj_fields.HVType.VMWARE, + vm_mode.HVM), + (obj_fields.Architecture.X86_64, + obj_fields.HVType.VMWARE, + vm_mode.HVM)] self._stats = data if self._auto_service_disabled: diff --git a/nova/virt/xenapi/host.py b/nova/virt/xenapi/host.py index 99d45f3ae044..50c63091e598 100644 --- a/nova/virt/xenapi/host.py +++ b/nova/virt/xenapi/host.py @@ -24,7 +24,6 @@ from oslo_log import log as logging from oslo_serialization import jsonutils import six -from nova.compute import hv_type from nova.compute import task_states from nova.compute import vm_mode from nova.compute import vm_states @@ -288,7 +287,7 @@ def to_supported_instances(host_capabilities): guestarch = obj_fields.Architecture.canonicalize(guestarch) ostype = vm_mode.canonicalize(ostype) - result.append((guestarch, hv_type.XEN, ostype)) + result.append((guestarch, obj_fields.HVType.XEN, ostype)) except ValueError: LOG.warning(_LW("Failed to extract instance support from %s"), capability)