diff options
author | Stephen Finucane <sfinucan@redhat.com> | 2016-08-17 13:50:01 +0100 |
---|---|---|
committer | Stephen Finucane <sfinucan@redhat.com> | 2016-11-25 16:19:44 +0000 |
commit | 4a7502a5c9e84a8c8cef7f355d72425b26b8c379 (patch) | |
tree | 2f926bacbb146b12696edbb13886612ba5832f1a | |
parent | 747c0d04af95c8227823933c52f296fca1398cc2 (diff) | |
download | nova-4a7502a5c9e84a8c8cef7f355d72425b26b8c379.tar.gz |
objects: Move 'vm_mode' to 'fields.VMMode'
Resolve the relevant TODO. Migrate tests in the process.
Change-Id: I372266b158667683cad973f20976619c34538491
22 files changed, 245 insertions, 294 deletions
diff --git a/nova/compute/vm_mode.py b/nova/compute/vm_mode.py deleted file mode 100644 index bfcadb569e..0000000000 --- a/nova/compute/vm_mode.py +++ /dev/null @@ -1,87 +0,0 @@ -# Copyright 2012 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. - -"""Possible vm modes for instances. - -Compute instance vm modes represent the host/guest ABI used for the -virtual machine / container. Individual hypervisors may support -multiple different vm modes per host. Available vm modes for a hypervisor -driver may also vary according to the architecture it is running on. - -The 'vm_mode' parameter can be set against an instance to -choose what sort of VM to boot. - -""" - -from nova import exception - -HVM = "hvm" # Native ABI (aka fully virtualized) -XEN = "xen" # Xen 3.0 paravirtualized -UML = "uml" # User Mode Linux paravirtualized -EXE = "exe" # Executables in containers - -ALL = [HVM, XEN, UML, EXE] - - -def get_from_instance(instance): - """Get the vm mode for an instance - - :param instance: instance object to query - - :returns: canonicalized vm mode for the instance - """ - - mode = instance.vm_mode - return canonicalize(mode) - - -def is_valid(name): - """Check if a string is a valid vm mode - - :param name: vm mode name to validate - - :returns: True if @name is valid - """ - - return name in ALL - - -def canonicalize(mode): - """Canonicalize the vm mode - - :param name: vm mode name to canonicalize - - :returns: a canonical vm mode name - """ - - if mode is None: - return None - - mode = mode.lower() - - # For compatibility with pre-Folsom deployments - if mode == "pv": - mode = XEN - - if mode == "hv": - mode = HVM - - if mode == "baremetal": - mode = HVM - - if not is_valid(mode): - raise exception.InvalidVirtualMachineMode(vmmode=mode) - - return mode diff --git a/nova/objects/fields.py b/nova/objects/fields.py index 7534bfad6c..08d9c5e4f2 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 VMMode class -from nova.compute import vm_mode from nova import exception from nova.i18n import _ from nova.network import model as network_model @@ -541,18 +539,80 @@ class VIFModel(BaseNovaEnum): class VMMode(BaseNovaEnum): - # TODO(berrange): move all constants out of 'nova.compute.vm_mode' - # into fields on this class - ALL = vm_mode.ALL + """Represents possible vm modes for instances. + + Compute instance VM modes represent the host/guest ABI used for the + virtual machine or container. Individual hypervisors may support + multiple different vm modes per host. Available VM modes for a + hypervisor driver may also vary according to the architecture it is + running on. + """ + HVM = 'hvm' # Native ABI (aka fully virtualized) + XEN = 'xen' # Xen 3.0 paravirtualized + UML = 'uml' # User Mode Linux paravirtualized + EXE = 'exe' # Executables in containers + + ALL = (HVM, XEN, UML, EXE) def coerce(self, obj, attr, value): try: - value = vm_mode.canonicalize(value) + value = self.canonicalize(value) except exception.InvalidVirtualMachineMode: msg = _("Virtual machine mode '%s' is not valid") % value raise ValueError(msg) + return super(VMMode, self).coerce(obj, attr, value) + @classmethod + def get_from_instance(cls, instance): + """Get the vm mode for an instance + + :param instance: instance object to query + + :returns: canonicalized vm mode for the instance + """ + mode = instance.vm_mode + + return cls.canonicalize(mode) + + @classmethod + def is_valid(cls, name): + """Check if a string is a valid vm mode + + :param name: vm mode name to validate + + :returns: True if @name is valid + """ + return name in cls.ALL + + @classmethod + def canonicalize(cls, mode): + """Canonicalize the vm mode + + :param name: vm mode name to canonicalize + + :returns: a canonical vm mode name + """ + if mode is None: + return None + + mode = mode.lower() + + # For compatibility with pre-Folsom deployments + if mode == 'pv': + mode = cls.XEN + + if mode == 'hv': + mode = cls.HVM + + if mode == 'baremetal': + mode = cls.HVM + + if not cls.is_valid(mode): + raise exception.InvalidVirtualMachineMode(vmmode=mode) + + return mode + class WatchdogAction(BaseNovaEnum): diff --git a/nova/scheduler/filters/image_props_filter.py b/nova/scheduler/filters/image_props_filter.py index bd9ba75216..1bf241a487 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 vm_mode from nova.objects import fields from nova.scheduler import filters @@ -48,7 +47,7 @@ class ImagePropertiesFilter(filters.BaseHostFilter): checked_img_props = ( fields.Architecture.canonicalize(img_arch), fields.HVType.canonicalize(img_h_type), - vm_mode.canonicalize(img_vm_mode) + fields.VMMode.canonicalize(img_vm_mode) ) # Supported if no compute-related instance properties are specified diff --git a/nova/tests/unit/compute/test_compute_api.py b/nova/tests/unit/compute/test_compute_api.py index 516b6f2427..5f4ecaf6e5 100644 --- a/nova/tests/unit/compute/test_compute_api.py +++ b/nova/tests/unit/compute/test_compute_api.py @@ -31,7 +31,6 @@ from nova.compute import instance_actions from nova.compute import rpcapi as compute_rpcapi from nova.compute import task_states from nova.compute import utils as compute_utils -from nova.compute import vm_mode from nova.compute import vm_states from nova import conductor from nova import context @@ -3079,7 +3078,7 @@ class _ComputeAPIUnitTestMixIn(object): system_metadata=orig_system_metadata, expected_attrs=['system_metadata'], image_ref=orig_image_href, - vm_mode=vm_mode.HVM) + vm_mode=fields_obj.VMMode.HVM) flavor = instance.get_flavor() def get_image(context, image_href): @@ -3109,7 +3108,7 @@ class _ComputeAPIUnitTestMixIn(object): _check_auto_disk_config.assert_called_once_with(image=new_image) _checks_for_create_and_rebuild.assert_called_once_with(self.context, None, new_image, flavor, {}, [], None) - self.assertEqual(vm_mode.XEN, instance.vm_mode) + self.assertEqual(fields_obj.VMMode.XEN, instance.vm_mode) def _test_check_injected_file_quota_onset_file_limit_exceeded(self, side_effect): diff --git a/nova/tests/unit/compute/test_resource_tracker.py b/nova/tests/unit/compute/test_resource_tracker.py index 1016cd0dbd..0f713c88c2 100644 --- a/nova/tests/unit/compute/test_resource_tracker.py +++ b/nova/tests/unit/compute/test_resource_tracker.py @@ -23,7 +23,6 @@ from nova.compute.monitors import base as monitor_base from nova.compute import power_state from nova.compute import resource_tracker from nova.compute import task_states -from nova.compute import vm_mode from nova.compute import vm_states from nova import context from nova import exception as exc @@ -80,7 +79,7 @@ _COMPUTE_NODE_FIXTURES = [ objects.HVSpec.from_list([ obj_fields.Architecture.I686, obj_fields.HVType.KVM, - vm_mode.HVM]) + obj_fields.VMMode.HVM]) ], metrics=None, pci_device_pools=None, diff --git a/nova/tests/unit/compute/test_vmmode.py b/nova/tests/unit/compute/test_vmmode.py deleted file mode 100644 index 11a6c7e751..0000000000 --- a/nova/tests/unit/compute/test_vmmode.py +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright (C) 2012 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 vm_mode -from nova import exception -from nova import test -from nova.tests.unit import fake_instance - - -class ComputeVMModeTest(test.NoDBTestCase): - - def _fake_object(self, updates): - return fake_instance.fake_instance_obj(None, **updates) - - def test_case(self): - inst = self._fake_object(dict(vm_mode="HVM")) - mode = vm_mode.get_from_instance(inst) - self.assertEqual(mode, "hvm") - - def test_legacy_pv(self): - inst = self._fake_object(dict(vm_mode="pv")) - mode = vm_mode.get_from_instance(inst) - self.assertEqual(mode, "xen") - - def test_legacy_hv(self): - inst = self._fake_object(dict(vm_mode="hv")) - mode = vm_mode.get_from_instance(inst) - self.assertEqual(mode, "hvm") - - def test_bogus(self): - inst = self._fake_object(dict(vm_mode="wibble")) - self.assertRaises(exception.Invalid, - vm_mode.get_from_instance, - inst) - - def test_good(self): - inst = self._fake_object(dict(vm_mode="hvm")) - mode = vm_mode.get_from_instance(inst) - self.assertEqual(mode, "hvm") - - def test_name_pv_compat(self): - mode = vm_mode.canonicalize('pv') - self.assertEqual(vm_mode.XEN, mode) - - def test_name_hv_compat(self): - mode = vm_mode.canonicalize('hv') - self.assertEqual(vm_mode.HVM, mode) - - def test_name_baremetal_compat(self): - mode = vm_mode.canonicalize('baremetal') - self.assertEqual(vm_mode.HVM, mode) - - def test_name_hvm(self): - mode = vm_mode.canonicalize('hvm') - self.assertEqual(vm_mode.HVM, mode) - - def test_name_none(self): - mode = vm_mode.canonicalize(None) - self.assertIsNone(mode) - - def test_name_invalid(self): - self.assertRaises(exception.InvalidVirtualMachineMode, - vm_mode.canonicalize, 'invalid') diff --git a/nova/tests/unit/objects/test_fields.py b/nova/tests/unit/objects/test_fields.py index ce644499be..7b8e52900a 100644 --- a/nova/tests/unit/objects/test_fields.py +++ b/nova/tests/unit/objects/test_fields.py @@ -25,6 +25,7 @@ from nova.network import model as network_model from nova.objects import fields from nova import signature_utils from nova import test +from nova.tests.unit import fake_instance from nova import utils @@ -267,6 +268,62 @@ class TestHVType(TestField): 'wibble') +class TestVMMode(TestField): + def _fake_object(self, updates): + return fake_instance.fake_instance_obj(None, **updates) + + def test_case(self): + inst = self._fake_object(dict(vm_mode='HVM')) + mode = fields.VMMode.get_from_instance(inst) + self.assertEqual(mode, 'hvm') + + def test_legacy_pv(self): + inst = self._fake_object(dict(vm_mode='pv')) + mode = fields.VMMode.get_from_instance(inst) + self.assertEqual(mode, 'xen') + + def test_legacy_hv(self): + inst = self._fake_object(dict(vm_mode='hv')) + mode = fields.VMMode.get_from_instance(inst) + self.assertEqual(mode, 'hvm') + + def test_bogus(self): + inst = self._fake_object(dict(vm_mode='wibble')) + self.assertRaises(exception.Invalid, + fields.VMMode.get_from_instance, + inst) + + def test_good(self): + inst = self._fake_object(dict(vm_mode='hvm')) + mode = fields.VMMode.get_from_instance(inst) + self.assertEqual(mode, 'hvm') + + def test_canonicalize_pv_compat(self): + mode = fields.VMMode.canonicalize('pv') + self.assertEqual(fields.VMMode.XEN, mode) + + def test_canonicalize_hv_compat(self): + mode = fields.VMMode.canonicalize('hv') + self.assertEqual(fields.VMMode.HVM, mode) + + def test_canonicalize_baremetal_compat(self): + mode = fields.VMMode.canonicalize('baremetal') + self.assertEqual(fields.VMMode.HVM, mode) + + def test_canonicalize_hvm(self): + mode = fields.VMMode.canonicalize('hvm') + self.assertEqual(fields.VMMode.HVM, mode) + + def test_canonicalize_none(self): + mode = fields.VMMode.canonicalize(None) + self.assertIsNone(mode) + + def test_canonicalize_invalid(self): + self.assertRaises(exception.InvalidVirtualMachineMode, + fields.VMMode.canonicalize, + 'invalid') + + 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 1e5ba9f74e..8a6bdd05a4 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 vm_mode from nova import objects from nova.objects import fields as obj_fields from nova.tests.unit.objects import test_objects @@ -22,25 +21,25 @@ from nova.tests.unit.objects import test_objects spec_dict = { 'arch': obj_fields.Architecture.I686, 'hv_type': obj_fields.HVType.KVM, - 'vm_mode': vm_mode.HVM + 'vm_mode': obj_fields.VMMode.HVM } spec_list = [ obj_fields.Architecture.I686, obj_fields.HVType.KVM, - vm_mode.HVM + obj_fields.VMMode.HVM ] spec_dict_vz = { 'arch': obj_fields.Architecture.I686, 'hv_type': obj_fields.HVType.VIRTUOZZO, - 'vm_mode': vm_mode.HVM + 'vm_mode': obj_fields.VMMode.HVM } spec_dict_parallels = { 'arch': obj_fields.Architecture.I686, 'hv_type': obj_fields.HVType.PARALLELS, - 'vm_mode': vm_mode.HVM + 'vm_mode': obj_fields.VMMode.HVM } @@ -54,7 +53,7 @@ class _TestHVSpecObject(object): spec_obj = objects.HVSpec() spec_obj.arch = obj_fields.Architecture.I686 spec_obj.hv_type = obj_fields.HVType.KVM - spec_obj.vm_mode = vm_mode.HVM + spec_obj.vm_mode = obj_fields.VMMode.HVM spec = spec_obj.to_list() self.assertEqual(spec_list, spec) diff --git a/nova/tests/unit/objects/test_objects.py b/nova/tests/unit/objects/test_objects.py index 6c92f39337..a1bbe3744e 100644 --- a/nova/tests/unit/objects/test_objects.py +++ b/nova/tests/unit/objects/test_objects.py @@ -1129,10 +1129,10 @@ object_data = { 'FloatingIPList': '1.11-7f2ba670714e1b7bab462ab3290f7159', 'HostMapping': '1.0-1a3390a696792a552ab7bd31a77ba9ac', 'HyperVLiveMigrateData': '1.1-9987a3cec31a81abac6fba7cc722e43f', - 'HVSpec': '1.2-e1ef66eb58ac1be510300c5d9f8ad931', + 'HVSpec': '1.2-e6cf4455367f301baa926e3972978d55', 'IDEDeviceBus': '1.0-29d4c9f27ac44197f01b6ac1b7e16502', 'ImageMeta': '1.8-642d1b2eb3e880a367f37d72dd76162d', - 'ImageMetaProps': '1.15-28e104f642cbf04c7899d349e7e4d05d', + 'ImageMetaProps': '1.15-070af88560aebda534a5d57e0d26e795', 'Instance': '2.3-4f98ab23f4b0a25fabb1040c8f5edecc', 'InstanceAction': '1.1-f9f293e526b66fca0d05c3b3a2d13914', 'InstanceActionEvent': '1.1-e56a64fa4710e43ef7af2ad9d6028b33', 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 e08ad43de5..18a4346b61 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 vm_mode from nova import objects from nova.objects import fields as obj_fields from nova.scheduler.filters import image_props_filter @@ -31,7 +30,7 @@ class TestImagePropsFilter(test.NoDBTestCase): properties=objects.ImageMetaProps( hw_architecture=obj_fields.Architecture.X86_64, img_hv_type=obj_fields.HVType.KVM, - hw_vm_mode=vm_mode.HVM, + hw_vm_mode=obj_fields.VMMode.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') @@ -39,7 +38,7 @@ class TestImagePropsFilter(test.NoDBTestCase): 'supported_instances': [( obj_fields.Architecture.X86_64, obj_fields.HVType.KVM, - vm_mode.HVM)], + obj_fields.VMMode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) @@ -49,14 +48,14 @@ class TestImagePropsFilter(test.NoDBTestCase): properties=objects.ImageMetaProps( hw_architecture=obj_fields.Architecture.ARMV7, img_hv_type=obj_fields.HVType.QEMU, - hw_vm_mode=vm_mode.HVM)) + hw_vm_mode=obj_fields.VMMode.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, obj_fields.HVType.KVM, - vm_mode.HVM)], + obj_fields.VMMode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertFalse(self.filt_cls.host_passes(host, spec_obj)) @@ -66,7 +65,7 @@ class TestImagePropsFilter(test.NoDBTestCase): properties=objects.ImageMetaProps( hw_architecture=obj_fields.Architecture.X86_64, img_hv_type=obj_fields.HVType.KVM, - hw_vm_mode=vm_mode.HVM, + hw_vm_mode=obj_fields.VMMode.HVM, img_hv_requested_version='>=6.2')) hypervisor_version = versionutils.convert_version_to_int('6.0.0') spec_obj = objects.RequestSpec(image=img_props) @@ -75,7 +74,7 @@ class TestImagePropsFilter(test.NoDBTestCase): 'supported_instances': [( obj_fields.Architecture.X86_64, obj_fields.HVType.KVM, - vm_mode.HVM)], + obj_fields.VMMode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertFalse(self.filt_cls.host_passes(host, spec_obj)) @@ -84,14 +83,14 @@ class TestImagePropsFilter(test.NoDBTestCase): img_props = objects.ImageMeta( properties=objects.ImageMetaProps( hw_architecture=obj_fields.Architecture.X86_64, - hw_vm_mode=vm_mode.HVM)) + hw_vm_mode=obj_fields.VMMode.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, obj_fields.HVType.KVM, - vm_mode.HVM)], + obj_fields.VMMode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) @@ -100,14 +99,14 @@ class TestImagePropsFilter(test.NoDBTestCase): img_props = objects.ImageMeta( properties=objects.ImageMetaProps( hw_architecture=obj_fields.Architecture.X86_64, - hw_vm_mode=vm_mode.HVM)) + hw_vm_mode=obj_fields.VMMode.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, obj_fields.HVType.XEN, - vm_mode.XEN)], + obj_fields.VMMode.XEN)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertFalse(self.filt_cls.host_passes(host, spec_obj)) @@ -119,7 +118,7 @@ class TestImagePropsFilter(test.NoDBTestCase): 'supported_instances': [( obj_fields.Architecture.X86_64, obj_fields.HVType.KVM, - vm_mode.HVM)], + obj_fields.VMMode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) @@ -129,7 +128,7 @@ class TestImagePropsFilter(test.NoDBTestCase): properties=objects.ImageMetaProps( hw_architecture=obj_fields.Architecture.X86_64, img_hv_type=obj_fields.HVType.KVM, - hw_vm_mode=vm_mode.HVM)) + hw_vm_mode=obj_fields.VMMode.HVM)) hypervisor_version = versionutils.convert_version_to_int('6.0.0') spec_obj = objects.RequestSpec(image=img_props) capabilities = { @@ -143,7 +142,7 @@ class TestImagePropsFilter(test.NoDBTestCase): properties=objects.ImageMetaProps( hw_architecture=obj_fields.Architecture.X86_64, img_hv_type=obj_fields.HVType.KVM, - hw_vm_mode=vm_mode.HVM, + hw_vm_mode=obj_fields.VMMode.HVM, img_hv_requested_version='>=6.0')) spec_obj = objects.RequestSpec(image=img_props) capabilities = { @@ -151,7 +150,7 @@ class TestImagePropsFilter(test.NoDBTestCase): 'supported_instances': [( obj_fields.Architecture.X86_64, obj_fields.HVType.KVM, - vm_mode.HVM)]} + obj_fields.VMMode.HVM)]} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) @@ -160,7 +159,7 @@ class TestImagePropsFilter(test.NoDBTestCase): properties=objects.ImageMetaProps( hw_architecture=obj_fields.Architecture.X86_64, img_hv_type=obj_fields.HVType.KVM, - hw_vm_mode=vm_mode.HVM, + hw_vm_mode=obj_fields.VMMode.HVM, img_hv_requested_version='>=6.0')) spec_obj = objects.RequestSpec(image=img_props) capabilities = { @@ -168,7 +167,7 @@ class TestImagePropsFilter(test.NoDBTestCase): 'supported_instances': [( obj_fields.Architecture.X86_64, obj_fields.HVType.KVM, - vm_mode.HVM)], + obj_fields.VMMode.HVM)], 'hypervisor_version': 5000} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertFalse(self.filt_cls.host_passes(host, spec_obj)) @@ -184,7 +183,7 @@ class TestImagePropsFilter(test.NoDBTestCase): 'supported_instances': [( obj_fields.Architecture.X86_64, obj_fields.HVType.XEN, - vm_mode.XEN)], + obj_fields.VMMode.XEN)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) @@ -200,7 +199,7 @@ class TestImagePropsFilter(test.NoDBTestCase): 'supported_instances': [( obj_fields.Architecture.X86_64, obj_fields.HVType.KVM, - vm_mode.HVM)], + obj_fields.VMMode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) @@ -216,7 +215,7 @@ class TestImagePropsFilter(test.NoDBTestCase): 'supported_instances': [( obj_fields.Architecture.I686, obj_fields.HVType.KVM, - vm_mode.HVM)], + obj_fields.VMMode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) @@ -232,7 +231,7 @@ class TestImagePropsFilter(test.NoDBTestCase): 'supported_instances': [( obj_fields.Architecture.I686, obj_fields.HVType.XEN, - vm_mode.HVM)], + obj_fields.VMMode.HVM)], 'hypervisor_version': hypervisor_version} host = fakes.FakeHostState('host1', 'node1', capabilities) self.assertTrue(self.filt_cls.host_passes(host, spec_obj)) @@ -249,7 +248,7 @@ class TestImagePropsFilter(test.NoDBTestCase): 'supported_instances': [( obj_fields.Architecture.I686, obj_fields.HVType.BAREMETAL, - vm_mode.HVM)], + obj_fields.VMMode.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/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 5f42830f85..e2ccd792b9 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -59,7 +59,6 @@ from nova.api.metadata import base as instance_metadata from nova.compute import manager from nova.compute import power_state from nova.compute import task_states -from nova.compute import vm_mode from nova.compute import vm_states import nova.conf from nova import context @@ -1860,7 +1859,7 @@ class LibvirtConnTestCase(test.NoDBTestCase): vconfig.LibvirtConfigGuestFeatureAPIC) self.assertEqual(cfg.memory, 6 * units.Ki) self.assertEqual(cfg.vcpus, 28) - self.assertEqual(cfg.os_type, vm_mode.HVM) + self.assertEqual(cfg.os_type, fields.VMMode.HVM) self.assertEqual(cfg.os_boot_dev, ["hd"]) self.assertIsNone(cfg.os_root) self.assertEqual(len(cfg.devices), 10) @@ -1935,7 +1934,7 @@ class LibvirtConnTestCase(test.NoDBTestCase): self.assertEqual(instance_ref["uuid"], cfg.uuid) self.assertEqual(instance_ref.flavor.memory_mb * units.Ki, cfg.memory) self.assertEqual(instance_ref.flavor.vcpus, cfg.vcpus) - self.assertEqual(vm_mode.EXE, cfg.os_type) + self.assertEqual(fields.VMMode.EXE, cfg.os_type) self.assertEqual("/sbin/init", cfg.os_init_path) self.assertEqual("console=tty0 console=ttyS0", cfg.os_cmdline) self.assertIsNone(cfg.os_root) @@ -1960,7 +1959,7 @@ class LibvirtConnTestCase(test.NoDBTestCase): self.assertEqual(instance_ref["uuid"], cfg.uuid) self.assertEqual(instance_ref.flavor.memory_mb * units.Ki, cfg.memory) self.assertEqual(instance_ref.vcpus, cfg.vcpus) - self.assertEqual(vm_mode.EXE, cfg.os_type) + self.assertEqual(fields.VMMode.EXE, cfg.os_type) self.assertEqual("/sbin/init", cfg.os_init_path) self.assertEqual("console=tty0 console=ttyS0", cfg.os_cmdline) self.assertIsNone(cfg.os_root) @@ -3157,7 +3156,7 @@ class LibvirtConnTestCase(test.NoDBTestCase): vconfig.LibvirtConfigGuestFeatureAPIC) self.assertEqual(cfg.memory, instance_ref.flavor.memory_mb * units.Ki) self.assertEqual(cfg.vcpus, instance_ref.flavor.vcpus) - self.assertEqual(cfg.os_type, vm_mode.HVM) + self.assertEqual(cfg.os_type, fields.VMMode.HVM) self.assertEqual(cfg.os_boot_dev, ["hd"]) self.assertIsNone(cfg.os_root) self.assertEqual(len(cfg.devices), 10) @@ -4073,7 +4072,7 @@ class LibvirtConnTestCase(test.NoDBTestCase): drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) instance_ref = objects.Instance(**self.test_instance) - instance_ref['vm_mode'] = vm_mode.HVM + instance_ref['vm_mode'] = fields.VMMode.HVM image_meta = objects.ImageMeta.from_dict(self.test_image_meta) disk_info = blockinfo.get_disk_info(CONF.libvirt.virt_type, @@ -4083,7 +4082,7 @@ class LibvirtConnTestCase(test.NoDBTestCase): cfg = drvr._get_guest_config(instance_ref, [], image_meta, disk_info) - self.assertEqual(cfg.os_type, vm_mode.HVM) + self.assertEqual(cfg.os_type, fields.VMMode.HVM) self.assertEqual(cfg.os_loader, CONF.libvirt.xen_hvmloader_path) self.assertEqual(3, len(cfg.features)) self.assertIsInstance(cfg.features[0], @@ -4112,7 +4111,7 @@ class LibvirtConnTestCase(test.NoDBTestCase): cfg = drvr._get_guest_config(instance_ref, [], image_meta, disk_info) - self.assertEqual(cfg.os_type, vm_mode.XEN) + self.assertEqual(cfg.os_type, fields.VMMode.XEN) self.assertEqual(1, len(cfg.features)) self.assertIsInstance(cfg.features[0], vconfig.LibvirtConfigGuestFeaturePAE) @@ -4210,29 +4209,35 @@ class LibvirtConnTestCase(test.NoDBTestCase): def test_use_ps2_mouse(self): self.flags(pointer_model='ps2mouse') - tablet = self._test_get_guest_usb_tablet(True, True, vm_mode.HVM) + tablet = self._test_get_guest_usb_tablet( + True, True, fields.VMMode.HVM) self.assertIsNone(tablet) def test_get_guest_usb_tablet_wipe(self): self.flags(use_usb_tablet=True, group='libvirt') - tablet = self._test_get_guest_usb_tablet(True, True, vm_mode.HVM) + tablet = self._test_get_guest_usb_tablet( + True, True, fields.VMMode.HVM) self.assertIsNotNone(tablet) - tablet = self._test_get_guest_usb_tablet(True, False, vm_mode.HVM) + tablet = self._test_get_guest_usb_tablet( + True, False, fields.VMMode.HVM) self.assertIsNotNone(tablet) - tablet = self._test_get_guest_usb_tablet(False, True, vm_mode.HVM) + tablet = self._test_get_guest_usb_tablet( + False, True, fields.VMMode.HVM) self.assertIsNotNone(tablet) - tablet = self._test_get_guest_usb_tablet(False, False, vm_mode.HVM) + tablet = self._test_get_guest_usb_tablet( + False, False, fields.VMMode.HVM) self.assertIsNone(tablet) - tablet = self._test_get_guest_usb_tablet(True, True, "foo") + tablet = self._test_get_guest_usb_tablet( + True, True, "foo") self.assertIsNone(tablet) tablet = self._test_get_guest_usb_tablet( - False, True, vm_mode.HVM, True) + False, True, fields.VMMode.HVM, True) self.assertIsNone(tablet) def test_get_guest_usb_tablet_image_meta(self): @@ -4240,19 +4245,19 @@ class LibvirtConnTestCase(test.NoDBTestCase): image_meta = {"properties": {"hw_pointer_model": "usbtablet"}} tablet = self._test_get_guest_usb_tablet( - True, True, vm_mode.HVM, image_meta=image_meta) + True, True, fields.VMMode.HVM, image_meta=image_meta) self.assertIsNotNone(tablet) tablet = self._test_get_guest_usb_tablet( - True, False, vm_mode.HVM, image_meta=image_meta) + True, False, fields.VMMode.HVM, image_meta=image_meta) self.assertIsNotNone(tablet) tablet = self._test_get_guest_usb_tablet( - False, True, vm_mode.HVM, image_meta=image_meta) + False, True, fields.VMMode.HVM, image_meta=image_meta) self.assertIsNotNone(tablet) tablet = self._test_get_guest_usb_tablet( - False, False, vm_mode.HVM, image_meta=image_meta) + False, False, fields.VMMode.HVM, image_meta=image_meta) self.assertIsNone(tablet) tablet = self._test_get_guest_usb_tablet( @@ -4260,7 +4265,7 @@ class LibvirtConnTestCase(test.NoDBTestCase): self.assertIsNone(tablet) tablet = self._test_get_guest_usb_tablet( - False, True, vm_mode.HVM, True, image_meta=image_meta) + False, True, fields.VMMode.HVM, True, image_meta=image_meta) self.assertIsNone(tablet) def test_get_guest_usb_tablet_image_meta_no_vnc(self): @@ -4271,32 +4276,32 @@ class LibvirtConnTestCase(test.NoDBTestCase): self.assertRaises( exception.UnsupportedPointerModelRequested, self._test_get_guest_usb_tablet, - False, False, vm_mode.HVM, True, image_meta=image_meta) + False, False, fields.VMMode.HVM, True, image_meta=image_meta) def test_get_guest_no_pointer_model_usb_tablet_set(self): self.flags(use_usb_tablet=True, group='libvirt') self.flags(pointer_model=None) - tablet = self._test_get_guest_usb_tablet(True, True, vm_mode.HVM) + tablet = self._test_get_guest_usb_tablet(True, True, fields.VMMode.HVM) self.assertIsNotNone(tablet) def test_get_guest_no_pointer_model_usb_tablet_not_set(self): self.flags(use_usb_tablet=False, group='libvirt') self.flags(pointer_model=None) - tablet = self._test_get_guest_usb_tablet(True, True, vm_mode.HVM) + tablet = self._test_get_guest_usb_tablet(True, True, fields.VMMode.HVM) self.assertIsNone(tablet) def test_get_guest_pointer_model_usb_tablet(self): self.flags(use_usb_tablet=False, group='libvirt') self.flags(pointer_model='usbtablet') - tablet = self._test_get_guest_usb_tablet(True, True, vm_mode.HVM) + tablet = self._test_get_guest_usb_tablet(True, True, fields.VMMode.HVM) self.assertIsNotNone(tablet) def test_get_guest_pointer_model_usb_tablet_image(self): image_meta = {"properties": {"hw_pointer_model": "usbtablet"}} tablet = self._test_get_guest_usb_tablet( - True, True, vm_mode.HVM, image_meta=image_meta) + True, True, fields.VMMode.HVM, image_meta=image_meta) self.assertIsNotNone(tablet) def test_get_guest_pointer_model_usb_tablet_image_no_HVM(self): @@ -4306,7 +4311,7 @@ class LibvirtConnTestCase(test.NoDBTestCase): self.assertRaises( exception.UnsupportedPointerModelRequested, self._test_get_guest_usb_tablet, - True, True, vm_mode.XEN, image_meta=image_meta) + True, True, fields.VMMode.XEN, image_meta=image_meta) def test_get_guest_config_with_watchdog_action_flavor(self): self.flags(virt_type='kvm', group='libvirt') @@ -5762,13 +5767,13 @@ class LibvirtConnTestCase(test.NoDBTestCase): def test_xml_and_uri_no_ramdisk_no_kernel_xen_hvm(self): instance_data = dict(self.test_instance) - instance_data.update({'vm_mode': vm_mode.HVM}) + instance_data.update({'vm_mode': fields.VMMode.HVM}) self._check_xml_and_uri(instance_data, expect_kernel=False, expect_ramdisk=False, expect_xen_hvm=True) def test_xml_and_uri_no_ramdisk_no_kernel_xen_pv(self): instance_data = dict(self.test_instance) - instance_data.update({'vm_mode': vm_mode.XEN}) + instance_data.update({'vm_mode': fields.VMMode.XEN}) self._check_xml_and_uri(instance_data, expect_kernel=False, expect_ramdisk=False, expect_xen_hvm=False, xen_only=True) @@ -6537,24 +6542,24 @@ class LibvirtConnTestCase(test.NoDBTestCase): instance_ref = objects.Instance(**instance) image_meta = objects.ImageMeta.from_dict(self.test_image_meta) - xen_vm_mode = vm_mode.XEN + xen_vm_mode = fields.VMMode.XEN if expect_xen_hvm: - xen_vm_mode = vm_mode.HVM + xen_vm_mode = fields.VMMode.HVM type_uri_map = {'qemu': ('qemu:///system', [(lambda t: t.find('.').get('type'), 'qemu'), (lambda t: t.find('./os/type').text, - vm_mode.HVM), + fields.VMMode.HVM), (lambda t: t.find('./devices/emulator'), None)]), 'kvm': ('qemu:///system', [(lambda t: t.find('.').get('type'), 'kvm'), (lambda t: t.find('./os/type').text, - vm_mode.HVM), + fields.VMMode.HVM), (lambda t: t.find('./devices/emulator'), None)]), 'uml': ('uml:///system', [(lambda t: t.find('.').get('type'), 'uml'), (lambda t: t.find('./os/type').text, - vm_mode.UML)]), + fields.VMMode.UML)]), 'xen': ('xen:///', [(lambda t: t.find('.').get('type'), 'xen'), (lambda t: t.find('./os/type').text, @@ -12319,13 +12324,13 @@ class LibvirtConnTestCase(test.NoDBTestCase): caps.host.cpu = cpu guest = vconfig.LibvirtConfigGuest() - guest.ostype = vm_mode.HVM + guest.ostype = fields.VMMode.HVM guest.arch = fields.Architecture.X86_64 guest.domtype = ["kvm"] caps.guests.append(guest) guest = vconfig.LibvirtConfigGuest() - guest.ostype = vm_mode.HVM + guest.ostype = fields.VMMode.HVM guest.arch = fields.Architecture.I686 guest.domtype = ["kvm"] caps.guests.append(guest) @@ -14803,7 +14808,7 @@ class LibvirtConnTestCase(test.NoDBTestCase): self.assertEqual(instance_ref["uuid"], cfg.uuid) self.assertEqual(instance_ref.flavor.memory_mb * units.Ki, cfg.memory) self.assertEqual(instance_ref.flavor.vcpus, cfg.vcpus) - self.assertEqual(vm_mode.HVM, cfg.os_type) + self.assertEqual(fields.VMMode.HVM, cfg.os_type) self.assertIsNone(cfg.os_root) self.assertEqual(6, len(cfg.devices)) self.assertIsInstance(cfg.devices[0], @@ -14830,7 +14835,7 @@ class LibvirtConnTestCase(test.NoDBTestCase): self.flags(virt_type='parallels', group='libvirt') drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) ct_instance = self.test_instance.copy() - ct_instance["vm_mode"] = vm_mode.EXE + ct_instance["vm_mode"] = fields.VMMode.EXE instance_ref = objects.Instance(**ct_instance) image_meta = objects.ImageMeta.from_dict(self.test_image_meta) @@ -14847,7 +14852,7 @@ class LibvirtConnTestCase(test.NoDBTestCase): self.assertEqual(instance_ref["uuid"], cfg.uuid) self.assertEqual(instance_ref.flavor.memory_mb * units.Ki, cfg.memory) self.assertEqual(instance_ref.flavor.vcpus, cfg.vcpus) - self.assertEqual(vm_mode.EXE, cfg.os_type) + self.assertEqual(fields.VMMode.EXE, cfg.os_type) self.assertEqual("/sbin/init", cfg.os_init_path) self.assertIsNone(cfg.os_root) if rescue: @@ -14932,8 +14937,8 @@ class LibvirtConnTestCase(test.NoDBTestCase): self.assertTrue(disk_found) def test_get_guest_config_parallels_volume(self): - self._test_get_guest_config_parallels_volume(vm_mode.EXE, 4) - self._test_get_guest_config_parallels_volume(vm_mode.HVM, 6) + self._test_get_guest_config_parallels_volume(fields.VMMode.EXE, 4) + self._test_get_guest_config_parallels_volume(fields.VMMode.HVM, 6) def test_get_guest_disk_config_rbd_older_config_drive_fall_back(self): # New config drives are stored in rbd but existing instances have @@ -15025,7 +15030,7 @@ class LibvirtConnTestCase(test.NoDBTestCase): self.flags(virt_type='parallels', group='libvirt') instance = objects.Instance(**self.test_instance) - instance.vm_mode = vm_mode.EXE + instance.vm_mode = fields.VMMode.EXE fake_dom = FakeVirtDomain(fake_xml=dummyxml) drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False) mock_get_domain.return_value = fake_dom diff --git a/nova/tests/unit/virt/xenapi/test_vm_utils.py b/nova/tests/unit/virt/xenapi/test_vm_utils.py index df6c90dfd4..140289f500 100644 --- a/nova/tests/unit/virt/xenapi/test_vm_utils.py +++ b/nova/tests/unit/virt/xenapi/test_vm_utils.py @@ -30,11 +30,11 @@ import six from nova.compute import flavors from nova.compute import power_state -from nova.compute import vm_mode import nova.conf from nova import context from nova import exception from nova import objects +from nova.objects import fields as obj_fields from nova import test from nova.tests.unit import fake_flavor from nova.tests.unit import fake_instance @@ -1613,37 +1613,37 @@ class DetermineVmModeTestCase(VMUtilsTestBase): def test_determine_vm_mode_returns_xen_mode(self): instance = self._fake_object({"vm_mode": "xen"}) - self.assertEqual(vm_mode.XEN, + self.assertEqual(obj_fields.VMMode.XEN, vm_utils.determine_vm_mode(instance, None)) def test_determine_vm_mode_returns_hvm_mode(self): instance = self._fake_object({"vm_mode": "hvm"}) - self.assertEqual(vm_mode.HVM, + self.assertEqual(obj_fields.VMMode.HVM, vm_utils.determine_vm_mode(instance, None)) def test_determine_vm_mode_returns_xen_for_linux(self): instance = self._fake_object({"vm_mode": None, "os_type": "linux"}) - self.assertEqual(vm_mode.XEN, + self.assertEqual(obj_fields.VMMode.XEN, vm_utils.determine_vm_mode(instance, None)) def test_determine_vm_mode_returns_hvm_for_windows(self): instance = self._fake_object({"vm_mode": None, "os_type": "windows"}) - self.assertEqual(vm_mode.HVM, + self.assertEqual(obj_fields.VMMode.HVM, vm_utils.determine_vm_mode(instance, None)) def test_determine_vm_mode_returns_hvm_by_default(self): instance = self._fake_object({"vm_mode": None, "os_type": None}) - self.assertEqual(vm_mode.HVM, + self.assertEqual(obj_fields.VMMode.HVM, vm_utils.determine_vm_mode(instance, None)) def test_determine_vm_mode_returns_xen_for_VHD(self): instance = self._fake_object({"vm_mode": None, "os_type": None}) - self.assertEqual(vm_mode.XEN, + self.assertEqual(obj_fields.VMMode.XEN, vm_utils.determine_vm_mode(instance, vm_utils.ImageType.DISK_VHD)) def test_determine_vm_mode_returns_xen_for_DISK(self): instance = self._fake_object({"vm_mode": None, "os_type": None}) - self.assertEqual(vm_mode.XEN, + self.assertEqual(obj_fields.VMMode.XEN, vm_utils.determine_vm_mode(instance, vm_utils.ImageType.DISK)) diff --git a/nova/virt/fake.py b/nova/virt/fake.py index 31d193de2d..1027e2a1fb 100644 --- a/nova/virt/fake.py +++ b/nova/virt/fake.py @@ -32,7 +32,6 @@ from oslo_utils import versionutils from nova.compute import power_state from nova.compute import task_states -from nova.compute import vm_mode import nova.conf from nova.console import type as ctype from nova import exception @@ -149,7 +148,7 @@ class FakeDriver(driver.ComputeDriver): 'supported_instances': [( obj_fields.Architecture.X86_64, obj_fields.HVType.FAKE, - vm_mode.HVM)], + obj_fields.VMMode.HVM)], 'numa_topology': None, } self._mounts = {} diff --git a/nova/virt/hyperv/hostops.py b/nova/virt/hyperv/hostops.py index 2fabdc2461..7684f1fd51 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 vm_mode import nova.conf from nova.i18n import _ from nova.objects import fields as obj_fields @@ -159,10 +158,10 @@ class HostOps(object): 'supported_instances': [ (obj_fields.Architecture.I686, obj_fields.HVType.HYPERV, - vm_mode.HVM), + obj_fields.VMMode.HVM), (obj_fields.Architecture.X86_64, obj_fields.HVType.HYPERV, - vm_mode.HVM)], + obj_fields.VMMode.HVM)], 'numa_topology': None, } diff --git a/nova/virt/ironic/driver.py b/nova/virt/ironic/driver.py index e50bc767a3..0d828ed6a8 100644 --- a/nova/virt/ironic/driver.py +++ b/nova/virt/ironic/driver.py @@ -36,7 +36,6 @@ import six.moves.urllib.parse as urlparse from nova.api.metadata import base as instance_metadata from nova.compute import power_state from nova.compute import task_states -from nova.compute import vm_mode from nova.compute import vm_states import nova.conf from nova.console import type as console_type @@ -98,7 +97,7 @@ def _get_nodes_supported_instances(cpu_arch=None): return [] return [(cpu_arch, obj_fields.HVType.BAREMETAL, - vm_mode.HVM)] + obj_fields.VMMode.HVM)] def _log_ironic_polling(what, node, instance): diff --git a/nova/virt/libvirt/blockinfo.py b/nova/virt/libvirt/blockinfo.py index 5fcb4b76f8..e5f89af17f 100644 --- a/nova/virt/libvirt/blockinfo.py +++ b/nova/virt/libvirt/blockinfo.py @@ -76,7 +76,6 @@ from oslo_config import cfg import six from nova import block_device -from nova.compute import vm_mode from nova import exception from nova.i18n import _ from nova.objects import base as obj_base @@ -248,8 +247,8 @@ def get_disk_bus_for_device_type(instance, elif virt_type == "lxc": return "lxc" elif virt_type == "xen": - guest_vm_mode = vm_mode.get_from_instance(instance) - if guest_vm_mode == vm_mode.HVM: + guest_vm_mode = obj_fields.VMMode.get_from_instance(instance) + if guest_vm_mode == obj_fields.VMMode.HVM: return "ide" else: return "xen" diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 64e0d8ec97..163687bb79 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -64,7 +64,6 @@ from nova import block_device from nova.compute import power_state from nova.compute import task_states from nova.compute import utils as compute_utils -from nova.compute import vm_mode import nova.conf from nova.console import serial as serial_console from nova.console import type as ctype @@ -3489,7 +3488,8 @@ class LibvirtDriver(driver.ComputeDriver): fs.source_dir = os.path.join( libvirt_utils.get_instance_path(instance), 'rootfs') devices.append(fs) - elif os_type == vm_mode.EXE and CONF.libvirt.virt_type == "parallels": + elif (os_type == fields.VMMode.EXE and + CONF.libvirt.virt_type == "parallels"): if rescue: fsrescue = self._get_guest_fs_config(instance, "disk.rescue") devices.append(fsrescue) @@ -3993,13 +3993,13 @@ class LibvirtDriver(driver.ComputeDriver): def _get_guest_os_type(self, virt_type): """Returns the guest OS type based on virt type.""" if virt_type == "lxc": - ret = vm_mode.EXE + ret = fields.VMMode.EXE elif virt_type == "uml": - ret = vm_mode.UML + ret = fields.VMMode.UML elif virt_type == "xen": - ret = vm_mode.XEN + ret = fields.VMMode.XEN else: - ret = vm_mode.HVM + ret = fields.VMMode.HVM return ret def _set_guest_for_rescue(self, rescue, guest, inst_path, virt_type, @@ -4093,7 +4093,7 @@ class LibvirtDriver(driver.ComputeDriver): guest.features.append(vconfig.LibvirtConfigGuestFeaturePAE()) if (virt_type not in ("lxc", "uml", "parallels", "xen") or - (virt_type == "xen" and guest.os_type == vm_mode.HVM)): + (virt_type == "xen" and guest.os_type == fields.VMMode.HVM)): guest.features.append(vconfig.LibvirtConfigGuestFeatureACPI()) guest.features.append(vconfig.LibvirtConfigGuestFeatureAPIC()) @@ -4126,7 +4126,7 @@ class LibvirtDriver(driver.ComputeDriver): # be overridden by the user with image_meta.properties, which # is carried out in the next if statement below this one. guestarch = libvirt_utils.get_arch(image_meta) - if guest.os_type == vm_mode.XEN: + if guest.os_type == fields.VMMode.XEN: video.type = 'xen' elif CONF.libvirt.virt_type == 'parallels': video.type = 'vga' @@ -4293,7 +4293,7 @@ class LibvirtDriver(driver.ComputeDriver): def _configure_guest_by_virt_type(self, guest, virt_type, caps, instance, image_meta, flavor, root_device_name): if virt_type == "xen": - if guest.os_type == vm_mode.HVM: + if guest.os_type == fields.VMMode.HVM: guest.os_loader = CONF.libvirt.xen_hvmloader_path elif virt_type in ("kvm", "qemu"): if caps.host.cpu.arch in (fields.Architecture.I686, @@ -4328,7 +4328,7 @@ class LibvirtDriver(driver.ComputeDriver): guest.os_kernel = "/usr/bin/linux" guest.os_root = root_device_name elif virt_type == "parallels": - if guest.os_type == vm_mode.EXE: + if guest.os_type == fields.VMMode.EXE: guest.os_init_path = "/sbin/init" def _conf_non_lxc_uml(self, virt_type, guest, root_device_name, rescue, @@ -4526,7 +4526,7 @@ class LibvirtDriver(driver.ComputeDriver): # for nova.api.ec2.cloud.CloudController.get_metadata() instance.root_device_name = root_device_name - guest.os_type = (vm_mode.get_from_instance(instance) or + guest.os_type = (fields.VMMode.get_from_instance(instance) or self._get_guest_os_type(virt_type)) caps = self._host.get_capabilities() @@ -4675,7 +4675,7 @@ class LibvirtDriver(driver.ComputeDriver): def _get_guest_usb_tablet(self, os_type): tablet = None - if os_type == vm_mode.HVM: + if os_type == fields.VMMode.HVM: tablet = vconfig.LibvirtConfigGuestInput() tablet.type = "tablet" tablet.bus = "usb" @@ -5040,7 +5040,7 @@ class LibvirtDriver(driver.ComputeDriver): instance_cap = ( fields.Architecture.canonicalize(g.arch), fields.HVType.canonicalize(dt), - vm_mode.canonicalize(g.ostype)) + fields.VMMode.canonicalize(g.ostype)) instance_caps.append(instance_cap) return instance_caps @@ -6802,7 +6802,7 @@ class LibvirtDriver(driver.ComputeDriver): doc.findall('.//devices/%s/target' % device_type)) if (CONF.libvirt.virt_type == 'parallels' and - doc.find('os/type').text == vm_mode.EXE): + doc.find('os/type').text == fields.VMMode.EXE): node_type = 'filesystem' else: node_type = 'disk' diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py index 65f63f2089..67b445400a 100644 --- a/nova/virt/libvirt/utils.py +++ b/nova/virt/libvirt/utils.py @@ -26,7 +26,6 @@ from lxml import etree from oslo_concurrency import processutils from oslo_log import log as logging -from nova.compute import vm_mode import nova.conf from nova.i18n import _ from nova.i18n import _LI @@ -360,7 +359,8 @@ def find_disk(virt_dom): disk_path = source.get('dir') disk_path = disk_path[0:disk_path.rfind('rootfs')] disk_path = os.path.join(disk_path, 'disk') - elif CONF.libvirt.virt_type == 'parallels' and os_type == vm_mode.EXE: + elif (CONF.libvirt.virt_type == 'parallels' and + os_type == obj_fields.VMMode.EXE): filesystem = domain.find('devices/filesystem') driver = filesystem.find('driver') diff --git a/nova/virt/vmwareapi/host.py b/nova/virt/vmwareapi/host.py index 118201f78a..a9a6b04e99 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 vm_mode import nova.conf from nova import context from nova import exception @@ -99,10 +98,10 @@ class VCState(object): data["supported_instances"] = [ (obj_fields.Architecture.I686, obj_fields.HVType.VMWARE, - vm_mode.HVM), + obj_fields.VMMode.HVM), (obj_fields.Architecture.X86_64, obj_fields.HVType.VMWARE, - vm_mode.HVM)] + obj_fields.VMMode.HVM)] self._stats = data if self._auto_service_disabled: diff --git a/nova/virt/xenapi/host.py b/nova/virt/xenapi/host.py index 50c63091e5..5e74f08a31 100644 --- a/nova/virt/xenapi/host.py +++ b/nova/virt/xenapi/host.py @@ -25,7 +25,6 @@ from oslo_serialization import jsonutils import six from nova.compute import task_states -from nova.compute import vm_mode from nova.compute import vm_states from nova import context from nova import exception @@ -285,7 +284,7 @@ def to_supported_instances(host_capabilities): ostype, _version, guestarch = capability.split("-") guestarch = obj_fields.Architecture.canonicalize(guestarch) - ostype = vm_mode.canonicalize(ostype) + ostype = obj_fields.VMMode.canonicalize(ostype) result.append((guestarch, obj_fields.HVType.XEN, ostype)) except ValueError: diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 7c2e70755a..543e7e25bb 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -43,11 +43,11 @@ import six.moves.urllib.parse as urlparse from nova.api.metadata import base as instance_metadata from nova.compute import power_state from nova.compute import task_states -from nova.compute import vm_mode import nova.conf from nova import exception from nova.i18n import _, _LE, _LI, _LW from nova.network import model as network_model +from nova.objects import fields as obj_fields from nova import utils from nova.virt import configdrive from nova.virt import diagnostics @@ -1608,23 +1608,24 @@ def determine_disk_image_type(image_meta): def determine_vm_mode(instance, disk_image_type): - current_mode = vm_mode.get_from_instance(instance) - if current_mode == vm_mode.XEN or current_mode == vm_mode.HVM: + current_mode = obj_fields.VMMode.get_from_instance(instance) + if (current_mode == obj_fields.VMMode.XEN or + current_mode == obj_fields.VMMode.HVM): return current_mode os_type = instance['os_type'] if os_type == "linux": - return vm_mode.XEN + return obj_fields.VMMode.XEN if os_type == "windows": - return vm_mode.HVM + return obj_fields.VMMode.HVM # disk_image_type specific default for backwards compatibility if disk_image_type == ImageType.DISK_VHD or \ disk_image_type == ImageType.DISK: - return vm_mode.XEN + return obj_fields.VMMode.XEN # most images run OK as HVM - return vm_mode.HVM + return obj_fields.VMMode.HVM def set_vm_name_label(session, vm_ref, name_label): diff --git a/nova/virt/xenapi/vmops.py b/nova/virt/xenapi/vmops.py index a39ae2f084..9054051e4c 100644 --- a/nova/virt/xenapi/vmops.py +++ b/nova/virt/xenapi/vmops.py @@ -39,7 +39,6 @@ from nova import block_device from nova import compute from nova.compute import power_state from nova.compute import task_states -from nova.compute import vm_mode from nova.compute import vm_states import nova.conf from nova.console import type as ctype @@ -47,6 +46,7 @@ from nova import context as nova_context from nova import exception from nova.i18n import _, _LE, _LI, _LW from nova import objects +from nova.objects import fields as obj_fields from nova.pci import manager as pci_manager from nova import utils from nova.virt import configdrive @@ -703,7 +703,7 @@ class VMOps(object): LOG.debug("vm_mode not found in rescue image properties." "Setting vm_mode to %s", mode, instance=instance) else: - mode = vm_mode.canonicalize(rescue_vm_mode) + mode = obj_fields.VMMode.canonicalize(rescue_vm_mode) if instance.vm_mode != mode: # Update database with normalized (or determined) value @@ -711,7 +711,7 @@ class VMOps(object): instance.save() device_id = vm_utils.get_vm_device_id(self._session, image_meta) - use_pv_kernel = (mode == vm_mode.XEN) + use_pv_kernel = (mode == obj_fields.VMMode.XEN) LOG.debug("Using PV kernel: %s", use_pv_kernel, instance=instance) vm_ref = vm_utils.create_vm(self._session, instance, name_label, kernel_file, ramdisk_file, |