objects: Makes sure Instance._save methods are called

This patch makes sure that _save hooks are called for Instance object's
related objects even when they are set to None (if they are at all
nullable)

We will need this for numa_topology, as we need to be able to update it
on save, and make sure it's gone if the new one is None.

Change-Id: Ied9e760b40446661a6269e41df6091aa16fbfc82
This commit is contained in:
Nikola Dipanov
2014-11-18 20:42:13 +01:00
parent d13205fb60
commit 7335af1ea3

View File

@@ -410,10 +410,12 @@ class Instance(base.NovaPersistentObject, base.NovaObject):
delattr(self, base.get_attrname('id'))
def _save_info_cache(self, context):
self.info_cache.save(context)
if self.info_cache:
self.info_cache.save(context)
def _save_security_groups(self, context):
for secgroup in self.security_groups:
security_groups = self.security_groups or []
for secgroup in security_groups:
secgroup.save(context)
self.security_groups.obj_reset_changes()
@@ -479,9 +481,10 @@ class Instance(base.NovaPersistentObject, base.NovaObject):
updates = {}
changes = self.obj_what_changed()
for field in self.fields:
if (self.obj_attr_is_set(field) and
isinstance(self[field], base.NovaObject)):
isinstance(self.fields[field], fields.ObjectField)):
try:
getattr(self, '_save_%s' % field)(context)
except AttributeError: