Merge "Let soft-deleted instance_system_metadata readable"
This commit is contained in:
commit
811fc4e27f
@ -2476,8 +2476,17 @@ def _instance_metadata_update_in_place(context, instance, metadata_type, model,
|
||||
elif key not in metadata:
|
||||
to_delete.append(keyvalue)
|
||||
|
||||
for condemned in to_delete:
|
||||
condemned.soft_delete(session=session)
|
||||
# NOTE: we have to hard_delete here otherwise we will get more than one
|
||||
# system_metadata record when we read deleted for an instance;
|
||||
# regular metadata doesn't have the same problem because we don't
|
||||
# allow reading deleted regular metadata anywhere.
|
||||
if metadata_type == 'system_metadata':
|
||||
for condemned in to_delete:
|
||||
session.delete(condemned)
|
||||
instance[metadata_type].remove(condemned)
|
||||
else:
|
||||
for condemned in to_delete:
|
||||
condemned.soft_delete(session=session)
|
||||
|
||||
for key, value in metadata.iteritems():
|
||||
newitem = model()
|
||||
@ -4986,7 +4995,8 @@ def _instance_system_metadata_get_multi(context, instance_uuids,
|
||||
if not instance_uuids:
|
||||
return []
|
||||
return model_query(context, models.InstanceSystemMetadata,
|
||||
session=session, use_slave=use_slave).\
|
||||
session=session, use_slave=use_slave,
|
||||
read_deleted='yes').\
|
||||
filter(
|
||||
models.InstanceSystemMetadata.instance_uuid.in_(instance_uuids))
|
||||
|
||||
|
@ -986,11 +986,8 @@ class InstanceSystemMetadata(BASE, NovaBase):
|
||||
ForeignKey('instances.uuid'),
|
||||
nullable=False)
|
||||
|
||||
primary_join = ('and_(InstanceSystemMetadata.instance_uuid == '
|
||||
'Instance.uuid, InstanceSystemMetadata.deleted == 0)')
|
||||
instance = orm.relationship(Instance, backref="system_metadata",
|
||||
foreign_keys=instance_uuid,
|
||||
primaryjoin=primary_join)
|
||||
foreign_keys=instance_uuid)
|
||||
|
||||
|
||||
class InstanceTypeProjects(BASE, NovaBase):
|
||||
|
@ -2632,6 +2632,9 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
||||
set_and_check(meta)
|
||||
del meta['gigawatts']
|
||||
set_and_check(meta)
|
||||
self.ctxt.read_deleted = 'yes'
|
||||
self.assertNotIn('gigawatts',
|
||||
db.instance_system_metadata_get(self.ctxt, instance.uuid))
|
||||
|
||||
def test_security_group_in_use(self):
|
||||
db.instance_create(self.ctxt, dict(host='foo'))
|
||||
|
@ -828,11 +828,12 @@ def last_bytes(file_like_object, num):
|
||||
return (file_like_object.read(), remaining)
|
||||
|
||||
|
||||
def metadata_to_dict(metadata):
|
||||
def metadata_to_dict(metadata, filter_deleted=False):
|
||||
result = {}
|
||||
for item in metadata:
|
||||
if not item.get('deleted'):
|
||||
result[item['key']] = item['value']
|
||||
if not filter_deleted and item.get('deleted'):
|
||||
continue
|
||||
result[item['key']] = item['value']
|
||||
return result
|
||||
|
||||
|
||||
@ -856,7 +857,8 @@ def instance_sys_meta(instance):
|
||||
if isinstance(instance['system_metadata'], dict):
|
||||
return instance['system_metadata']
|
||||
else:
|
||||
return metadata_to_dict(instance['system_metadata'])
|
||||
return metadata_to_dict(instance['system_metadata'],
|
||||
filter_deleted=True)
|
||||
|
||||
|
||||
def get_wrapped_function(function):
|
||||
@ -1126,7 +1128,7 @@ def get_image_from_system_metadata(system_meta):
|
||||
properties = {}
|
||||
|
||||
if not isinstance(system_meta, dict):
|
||||
system_meta = metadata_to_dict(system_meta)
|
||||
system_meta = metadata_to_dict(system_meta, filter_deleted=True)
|
||||
|
||||
for key, value in six.iteritems(system_meta):
|
||||
if value is None:
|
||||
|
Loading…
Reference in New Issue
Block a user