From aae2fb4b04efa4111159341ca09718444ee5d03b Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 7 Jan 2013 14:17:07 -0500 Subject: [PATCH] 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 --- nova/tests/test_db_api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index af329daf..a17113a4 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -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'])