diff --git a/nova/objects/image_meta.py b/nova/objects/image_meta.py index 203b52c81d29..b9aba9e88908 100644 --- a/nova/objects/image_meta.py +++ b/nova/objects/image_meta.py @@ -14,6 +14,7 @@ import copy +from nova import exception from nova import objects from nova.objects import base from nova.objects import fields @@ -135,6 +136,30 @@ class ImageMetaProps(base.NovaObject): # Version 1.7: added img_config_drive field VERSION = ImageMeta.VERSION + def obj_make_compatible(self, primitive, target_version): + super(ImageMetaProps, self).obj_make_compatible(primitive, + target_version) + target_version = utils.convert_version_to_tuple(target_version) + if target_version < (1, 7): + primitive.pop('img_config_drive', None) + if target_version < (1, 5): + primitive.pop('os_admin_user', None) + if target_version < (1, 4): + primitive.pop('hw_vif_multiqueue_enabled', None) + if target_version < (1, 2): + primitive.pop('img_hv_type', None) + primitive.pop('img_hv_requested_version', None) + if target_version < (1, 1): + primitive.pop('os_require_quiesce', None) + + if target_version < (1, 6): + bus = primitive.get('hw_disk_bus', None) + if bus in ('lxc', 'uml'): + raise exception.ObjectActionError( + action='obj_make_compatible', + reason='hw_disk_bus=%s not supported in version %s' % ( + bus, target_version)) + # Maximum number of NUMA nodes permitted for the guest topology NUMA_NODES_MAX = 128 diff --git a/nova/tests/unit/objects/test_image_meta.py b/nova/tests/unit/objects/test_image_meta.py index ae7dae3b6ff2..50befb6d5a86 100644 --- a/nova/tests/unit/objects/test_image_meta.py +++ b/nova/tests/unit/objects/test_image_meta.py @@ -14,6 +14,7 @@ import datetime +from nova import exception from nova import objects from nova import test @@ -274,3 +275,23 @@ class TestImageMetaProps(test.NoDBTestCase): self.assertIsNone(virtprops.get("hw_numa_nodes")) self.assertEqual([set([0, 1, 2, 3])], virtprops.hw_numa_cpus) + + def test_obj_make_compatible(self): + props = { + 'img_config_drive': 'mandatory', + 'os_admin_user': 'root', + 'hw_vif_multiqueue_enabled': True, + 'img_hv_type': 'kvm', + 'img_hv_requested_version': '>= 1.0', + 'os_require_quiesce': True, + } + + obj = objects.ImageMetaProps(**props) + primitive = obj.obj_to_primitive('1.0') + self.assertFalse(any([x in primitive['nova_object.data'] + for x in props])) + + for bus in ('lxc', 'uml'): + obj.hw_disk_bus = bus + self.assertRaises(exception.ObjectActionError, + obj.obj_to_primitive, '1.0')