Refresh instance metadata in-place
For some reason that isn't entirely clear to me, the attempt to update instance metadata in _instance_update() results in a stale sqlalchemy object state. This is a similar issue to the one fixed in commit: 9fdf7552779d518af9cda4e366bf81fddb0cb6f2 For some reason, session.refresh() doesn't work for instance['metadata'] in the same way, which also raises suspicion that perhaps it's not the right fix for system_metadata either. This patch adds an _instance_update_metadata_in_place() method that updates the actual instance['metadata'] list _and_ the database, mirroring the high-level behavior of instance_metadata_update(), but without requiring us to refresh or re-fetch the metadata or the whole instance (as a workaround). Fixes bug 1096653 Change-Id: Ic5a205631b1b7dce3744960ed4201dcc7b4b2ae6
This commit is contained in:
@@ -325,12 +325,12 @@ class DbApiTestCase(test.TestCase):
|
||||
ctxt = context.get_admin_context()
|
||||
|
||||
# Create an instance with some metadata
|
||||
values = {'metadata': {'host': 'foo'},
|
||||
values = {'metadata': {'host': 'foo', 'key1': 'meow'},
|
||||
'system_metadata': {'original_image_ref': 'blah'}}
|
||||
instance = db.instance_create(ctxt, values)
|
||||
|
||||
# Update the metadata
|
||||
values = {'metadata': {'host': 'bar'},
|
||||
values = {'metadata': {'host': 'bar', 'key2': 'wuff'},
|
||||
'system_metadata': {'original_image_ref': 'baz'}}
|
||||
db.instance_update(ctxt, instance['uuid'], values)
|
||||
|
||||
@@ -338,6 +338,8 @@ class DbApiTestCase(test.TestCase):
|
||||
# updated
|
||||
instance_meta = db.instance_metadata_get(ctxt, instance['uuid'])
|
||||
self.assertEqual('bar', instance_meta['host'])
|
||||
self.assertEqual('wuff', instance_meta['key2'])
|
||||
self.assertNotIn('key1', instance_meta)
|
||||
|
||||
# Retrieve the system metadata to ensure it was successfully updated
|
||||
system_meta = db.instance_system_metadata_get(ctxt, instance['uuid'])
|
||||
|
||||
Reference in New Issue
Block a user