Merge "Avoid clobbering {system_,}metadata dicts passed to instance update"

This commit is contained in:
Jenkins 2013-10-08 06:23:35 +00:00 committed by Gerrit Code Review
commit e012b3f4c3
2 changed files with 13 additions and 0 deletions

View File

@ -2180,6 +2180,7 @@ def instance_update_and_get_original(context, instance_uuid, values,
# delete=True behavior of instance_metadata_update(...)
def _instance_metadata_update_in_place(context, instance, metadata_type, model,
metadata, session):
metadata = dict(metadata)
to_delete = []
for keyvalue in instance[metadata_type]:
key = keyvalue['key']

View File

@ -1339,6 +1339,18 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin):
for key in dt_keys:
self.assertEqual(inst[key], dt)
def test_instance_update_no_metadata_clobber(self):
meta = {'foo': 'bar'}
sys_meta = {'sfoo': 'sbar'}
values = {
'metadata': meta,
'system_metadata': sys_meta,
}
inst = db.instance_create(self.ctxt, {})
inst = db.instance_update(self.ctxt, inst['uuid'], values)
self.assertEqual({'foo': 'bar'}, meta)
self.assertEqual({'sfoo': 'sbar'}, sys_meta)
def test_instance_get_all_with_meta(self):
inst = self.create_instance_with_args()
for inst in db.instance_get_all(self.ctxt):