Undo changes to obj_make_compatible

Commit 7cdfdccf1bb936d559bd3e247094a817bb3c03f4 attempted to make
the obj_make_compatible calls consistent, but it actually changed
them the wrong way. This fixes them to unwrap nova_object.data
and updates the test that was testing the reverse.

Change-Id: I1a5db4e9817390ba3c2423d33387f780c890de64
Closes-Bug: #1373535
This commit is contained in:
Vishvananda Ishaya 2014-09-13 11:56:57 -07:00
parent d3e1752699
commit 279b6e98bc
6 changed files with 23 additions and 18 deletions

@ -67,8 +67,13 @@ class BlockDeviceMapping(base.NovaPersistentObject, base.NovaObject):
def obj_make_compatible(self, primitive, target_version):
target_version = utils.convert_version_to_tuple(target_version)
if target_version < (1, 2) and 'instance' in primitive:
self.instance.obj_make_compatible(primitive['instance'], '1.13')
self.instance.obj_make_compatible(
primitive['instance']['nova_object.data'], '1.13')
primitive['instance']['nova_object.version'] = '1.13'
elif target_version < (1, 3) and 'instance' in primitive:
self.instance.obj_make_compatible(
primitive['instance']['nova_object.data'], '1.14')
primitive['instance']['nova_object.version'] = '1.14'
@staticmethod
def _from_db_object(context, block_device_obj,

@ -54,10 +54,12 @@ class FixedIP(obj_base.NovaPersistentObject, obj_base.NovaObject):
if target_version < (1, 4) and 'default_route' in primitive:
del primitive['default_route']
if target_version < (1, 3) and 'instance' in primitive:
self.instance.obj_make_compatible(primitive['instance'], '1.14')
self.instance.obj_make_compatible(
primitive['instance']['nova_object.data'], '1.14')
primitive['instance']['nova_object.version'] = '1.14'
if target_version < (1, 2) and 'instance' in primitive:
self.instance.obj_make_compatible(primitive['instance'], '1.13')
self.instance.obj_make_compatible(
primitive['instance']['nova_object.data'], '1.13')
primitive['instance']['nova_object.version'] = '1.13'
@property

@ -44,13 +44,16 @@ class FloatingIP(obj_base.NovaPersistentObject, obj_base.NovaObject):
def obj_make_compatible(self, primitive, target_version):
target_version = utils.convert_version_to_tuple(target_version)
if target_version < (1, 2) and 'fixed_ip' in primitive:
self.fixed_ip.obj_make_compatible(primitive['fixed_ip'], '1.1')
self.fixed_ip.obj_make_compatible(
primitive['fixed_ip']['nova_object.data'], '1.1')
primitive['fixed_ip']['nova_object.version'] = '1.1'
elif target_version < (1, 3) and self.obj_attr_is_set('fixed_ip'):
self.fixed_ip.obj_make_compatible(primitive['fixed_ip'], '1.2')
self.fixed_ip.obj_make_compatible(
primitive['fixed_ip']['nova_object.data'], '1.2')
primitive['fixed_ip']['nova_object.version'] = '1.2'
elif target_version < (1, 4) and self.obj_attr_is_set('fixed_ip'):
self.fixed_ip.obj_make_compatible(primitive['fixed_ip'], '1.3')
self.fixed_ip.obj_make_compatible(
primitive['fixed_ip']['nova_object.data'], '1.3')
primitive['fixed_ip']['nova_object.version'] = '1.3'
@staticmethod

@ -214,8 +214,8 @@ class Instance(base.NovaPersistentObject, base.NovaObject):
del primitive['numa_topology']
if target_version < (1, 10) and 'info_cache' in primitive:
# NOTE(danms): Instance <= 1.9 (havana) had info_cache 1.4
self.info_cache.obj_make_compatible(primitive['info_cache'],
'1.4')
self.info_cache.obj_make_compatible(
primitive['info_cache']['nova_object.data'], '1.4')
primitive['info_cache']['nova_object.version'] = '1.4'
if target_version < (1, 7):
# NOTE(danms): Before 1.7, we couldn't handle unicode in
@ -225,10 +225,8 @@ class Instance(base.NovaPersistentObject, base.NovaObject):
primitive[field] = primitive[field].encode('ascii', 'replace')
if target_version < (1, 15) and 'pci_devices' in primitive:
# NOTE(baoli): Instance <= 1.14 (icehouse) had PciDeviceList 1.0
# NOTE(vish): pci_devices is a list object so we must pull the
# underlying primitive out of the nova_object_data.
self.pci_devices.obj_make_compatible(
primitive['pci_devices']['nova_object.data'], '1.0')
primitive['pci_devices']['nova_object.data'], '1.0')
primitive['pci_devices']['nova_object.version'] = '1.0'
if target_version < (1, 6):
# NOTE(danms): Before 1.6 there was no pci_devices list

@ -49,7 +49,7 @@ class Service(base.NovaPersistentObject, base.NovaObject):
target_version = utils.convert_version_to_tuple(target_version)
if target_version < (1, 3) and 'compute_node' in primitive:
self.compute_node.obj_make_compatible(
primitive['compute_node'], '1.4')
primitive['compute_node']['nova_object.data'], '1.4')
primitive['compute_node']['nova_object.version'] = '1.4'
@staticmethod

@ -244,12 +244,9 @@ class _TestFloatingIPObject(object):
floating = objects.FloatingIP()
fixed = objects.FixedIP()
floating.fixed_ip = fixed
with mock.patch.object(fixed, 'obj_make_compatible') as compat:
primitive = {'fixed_ip': {'nova_object.data': {}}}
floating.obj_make_compatible(primitive, '1.1')
compat.assert_called_once_with(primitive['fixed_ip'], '1.1')
self.assertEqual('1.1',
primitive['fixed_ip']['nova_object.version'])
primitive = floating.obj_to_primitive(target_version='1.1')
self.assertEqual('1.1',
primitive['nova_object.data']['fixed_ip']['nova_object.version'])
class TestFloatingIPObject(test_objects._LocalTest,