Prevent Instance.refresh() from returning a new info cache
If an older node does a refresh() on an instance, conductor will return a new copy of the InstanceInfoCache, which the client will balk at. Instead, add a refresh() method to info_cache and call it from Instance.refresh(). Closes-bug: #1265607 Change-Id: I6a4787a23cd851cf56958c61f8b0559a79847ca0
This commit is contained in:
@@ -474,8 +474,13 @@ class Instance(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):
|
||||
if field == 'info_cache':
|
||||
self.info_cache.refresh()
|
||||
# NOTE(danms): Make sure this shows up as touched
|
||||
self.info_cache = self.info_cache
|
||||
elif self[field] != current[field]:
|
||||
self[field] = current[field]
|
||||
self.obj_reset_changes()
|
||||
|
||||
def obj_load_attr(self, attrname):
|
||||
|
||||
@@ -96,3 +96,15 @@ class InstanceInfoCache(base.NovaPersistentObject, base.NovaObject):
|
||||
@base.remotable
|
||||
def delete(self, context):
|
||||
db.instance_info_cache_delete(context, self.instance_uuid)
|
||||
|
||||
@base.remotable
|
||||
def refresh(self, context):
|
||||
current = self.__class__.get_by_instance_uuid(context,
|
||||
self.instance_uuid)
|
||||
current._context = None
|
||||
|
||||
for field in self.fields:
|
||||
if self.obj_attr_is_set(field) and self[field] != current[field]:
|
||||
self[field] = current[field]
|
||||
|
||||
self.obj_reset_changes()
|
||||
|
||||
@@ -213,6 +213,9 @@ class _TestInstanceObject(object):
|
||||
use_slave=False
|
||||
).AndReturn(dict(self.fake_instance,
|
||||
host='new-host'))
|
||||
self.mox.StubOutWithMock(instance_info_cache.InstanceInfoCache,
|
||||
'refresh')
|
||||
instance_info_cache.InstanceInfoCache.refresh()
|
||||
self.mox.ReplayAll()
|
||||
inst = instance.Instance.get_by_uuid(self.context, fake_uuid)
|
||||
self.assertEqual(inst.host, 'orig-host')
|
||||
|
||||
@@ -96,6 +96,16 @@ class _TestInstanceInfoCacheObject(object):
|
||||
def test_save_without_update_cells(self):
|
||||
self._save_helper(None, False)
|
||||
|
||||
def test_refresh(self):
|
||||
obj = instance_info_cache.InstanceInfoCache.new(self.context,
|
||||
'fake-uuid1')
|
||||
self.mox.StubOutWithMock(db, 'instance_info_cache_get')
|
||||
db.instance_info_cache_get(self.context, 'fake-uuid1').AndReturn(
|
||||
fake_info_cache)
|
||||
self.mox.ReplayAll()
|
||||
obj.refresh()
|
||||
self.assertEqual(fake_info_cache['instance_uuid'], obj.instance_uuid)
|
||||
|
||||
|
||||
class TestInstanceInfoCacheObject(test_objects._LocalTest,
|
||||
_TestInstanceInfoCacheObject):
|
||||
|
||||
Reference in New Issue
Block a user