From a586083a096cdff4015852b447bbde3f678685c9 Mon Sep 17 00:00:00 2001 From: Gage Hugo Date: Mon, 23 May 2016 14:07:08 -0500 Subject: [PATCH] Remove DictCompat from instance_info_cache This changes over all occurrences of dictionary syntax on the instance_info_cache object to use object syntax. Change-Id: I87f4acf99a6fa8061e08f8a941f8f0c60e26c51f Partially-Implements: bp rm-object-dict-compat-newton --- nova/objects/instance_info_cache.py | 11 +++++------ nova/tests/unit/fake_network.py | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/nova/objects/instance_info_cache.py b/nova/objects/instance_info_cache.py index fc86d05b0062..11e76af2360f 100644 --- a/nova/objects/instance_info_cache.py +++ b/nova/objects/instance_info_cache.py @@ -25,10 +25,8 @@ from nova.objects import fields LOG = logging.getLogger(__name__) -# TODO(berrange): Remove NovaObjectDictCompat @base.NovaObjectRegistry.register -class InstanceInfoCache(base.NovaPersistentObject, base.NovaObject, - base.NovaObjectDictCompat): +class InstanceInfoCache(base.NovaPersistentObject, base.NovaObject): # Version 1.0: Initial version # Version 1.1: Converted network_info to store the model. # Version 1.2: Added new() and update_cells kwarg to save(). @@ -46,7 +44,7 @@ class InstanceInfoCache(base.NovaPersistentObject, base.NovaObject, @staticmethod def _from_db_object(context, info_cache, db_obj): for field in info_cache.fields: - info_cache[field] = db_obj[field] + setattr(info_cache, field, db_obj[field]) info_cache.obj_reset_changes() info_cache._context = context return info_cache @@ -114,7 +112,8 @@ class InstanceInfoCache(base.NovaPersistentObject, base.NovaObject, current._context = None for field in self.fields: - if self.obj_attr_is_set(field) and self[field] != current[field]: - self[field] = current[field] + if (self.obj_attr_is_set(field) and + getattr(self, field) != getattr(current, field)): + setattr(self, field, getattr(current, field)) self.obj_reset_changes() diff --git a/nova/tests/unit/fake_network.py b/nova/tests/unit/fake_network.py index 41baa5797c81..f3500669805f 100644 --- a/nova/tests/unit/fake_network.py +++ b/nova/tests/unit/fake_network.py @@ -469,7 +469,7 @@ def _create_instances_with_cached_ips(orig_func, *args, **kwargs): instances, reservation_id = orig_func(*args, **kwargs) fake_cache = _get_fake_cache() for instance in instances: - instance['info_cache']['network_info'] = fake_cache + instance['info_cache'].network_info = fake_cache db.instance_info_cache_update(args[1], instance['uuid'], {'network_info': fake_cache}) return (instances, reservation_id)