Make image props filter handle old vm_modes
The ImagePropertyFilter would fail to build an instance if the image used an older style vm_mode (e.g. 'pv') as described in nova.compute.vm_mode. This change will convert the vm mode string to the current form. Change-Id: Ibde37e28b02d9e866b286ea14c47a6a8411d94b4 Closes-Bug: #1276773
This commit is contained in:
parent
f474441263
commit
818353e8c8
|
@ -37,7 +37,10 @@ ALL = [HVM, XEN, UML, EXE]
|
|||
|
||||
def get_from_instance(instance):
|
||||
mode = instance['vm_mode']
|
||||
return name(mode)
|
||||
|
||||
|
||||
def name(mode):
|
||||
if mode is None:
|
||||
return None
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
# under the License.
|
||||
from distutils import versionpredicate
|
||||
|
||||
from nova.compute import vm_mode
|
||||
from nova.openstack.common.gettextutils import _
|
||||
from nova.openstack.common import log as logging
|
||||
from nova.scheduler import filters
|
||||
|
@ -43,6 +44,7 @@ class ImagePropertiesFilter(filters.BaseHostFilter):
|
|||
img_arch = image_props.get('architecture', None)
|
||||
img_h_type = image_props.get('hypervisor_type', None)
|
||||
img_vm_mode = image_props.get('vm_mode', None)
|
||||
img_vm_mode = vm_mode.name(img_vm_mode) # get canonical name
|
||||
checked_img_props = (img_arch, img_h_type, img_vm_mode)
|
||||
|
||||
# Supported if no compute-related instance properties are specified
|
||||
|
|
|
@ -45,3 +45,22 @@ class ComputeVMModeTest(test.NoDBTestCase):
|
|||
inst = dict(vm_mode="hvm")
|
||||
mode = vm_mode.get_from_instance(inst)
|
||||
self.assertEqual(mode, "hvm")
|
||||
|
||||
def test_name_pv_compat(self):
|
||||
mode = vm_mode.name('pv')
|
||||
self.assertEqual(vm_mode.XEN, mode)
|
||||
|
||||
def test_name_hv_compat(self):
|
||||
mode = vm_mode.name('hv')
|
||||
self.assertEqual(vm_mode.HVM, mode)
|
||||
|
||||
def test_name_hvm(self):
|
||||
mode = vm_mode.name('hvm')
|
||||
self.assertEqual(vm_mode.HVM, mode)
|
||||
|
||||
def test_name_none(self):
|
||||
mode = vm_mode.name(None)
|
||||
self.assertEqual(None, mode)
|
||||
|
||||
def test_name_invalid(self):
|
||||
self.assertRaises(exception.Invalid, vm_mode.name, 'invalid')
|
||||
|
|
|
@ -34,6 +34,7 @@ from nova.tests.scheduler import fakes
|
|||
from nova import utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
CONF.import_opt('my_ip', 'nova.netconf')
|
||||
|
||||
|
||||
|
@ -779,6 +780,30 @@ class HostFiltersTestCase(test.NoDBTestCase):
|
|||
host = fakes.FakeHostState('host1', 'node1', capabilities)
|
||||
self.assertFalse(filt_cls.host_passes(host, filter_properties))
|
||||
|
||||
def test_image_properties_filter_pv_mode_compat(self):
|
||||
# if an old image has 'pv' for a vm_mode it should be treated as xen
|
||||
self._stub_service_is_up(True)
|
||||
filt_cls = self.class_map['ImagePropertiesFilter']()
|
||||
img_props = {'properties': {'vm_mode': 'pv'}}
|
||||
filter_properties = {'request_spec': {'image': img_props}}
|
||||
hypervisor_version = utils.convert_version_to_int('6.0.0')
|
||||
capabilities = {'supported_instances': [('x86_64', 'xapi', 'xen')],
|
||||
'hypervisor_version': hypervisor_version}
|
||||
host = fakes.FakeHostState('host1', 'node1', capabilities)
|
||||
self.assertTrue(filt_cls.host_passes(host, filter_properties))
|
||||
|
||||
def test_image_properties_filter_hvm_mode_compat(self):
|
||||
# if an old image has 'hv' for a vm_mode it should be treated as xen
|
||||
self._stub_service_is_up(True)
|
||||
filt_cls = self.class_map['ImagePropertiesFilter']()
|
||||
img_props = {'properties': {'vm_mode': 'hv'}}
|
||||
filter_properties = {'request_spec': {'image': img_props}}
|
||||
hypervisor_version = utils.convert_version_to_int('6.0.0')
|
||||
capabilities = {'supported_instances': [('x86_64', 'kvm', 'hvm')],
|
||||
'hypervisor_version': hypervisor_version}
|
||||
host = fakes.FakeHostState('host1', 'node1', capabilities)
|
||||
self.assertTrue(filt_cls.host_passes(host, filter_properties))
|
||||
|
||||
def _do_test_compute_filter_extra_specs(self, ecaps, especs, passes):
|
||||
"""In real Openstack runtime environment,compute capabilities
|
||||
value may be number, so we should use number to do unit test.
|
||||
|
|
Loading…
Reference in New Issue