Fix backup-import error when the deleted record in the same db

If we revive the deleted backup record, cinder-api will raise a
DBDuplicateEntry error, this patch will allow user to import the deleted
record either in the same db or not.

Change-Id: I87a287f5db912e9aeaa401871178c49414098d06
Closes-Bug: #1696361
This commit is contained in:
luqitao 2017-10-13 09:37:52 +08:00
parent d6cfe5ed88
commit ea5e4f3945
2 changed files with 9 additions and 5 deletions

View File

@ -498,16 +498,18 @@ class API(base.Base):
'project_id': context.project_id,
'volume_id': IMPORT_VOLUME_ID,
'status': fields.BackupStatus.CREATING,
'deleted_at': None,
'deleted': False,
'metadata': {}
}
try:
# Try to get the backup with that ID in all projects even among
# deleted entries.
backup = objects.BackupImport.get_by_id(context,
backup_record['id'],
read_deleted='yes',
project_only=False)
backup = objects.BackupImport.get_by_id(
context.elevated(read_deleted='yes'),
backup_record['id'],
project_only=False)
# If record exists and it's not deleted we cannot proceed with the
# import

View File

@ -6784,8 +6784,10 @@ def worker_destroy(context, **filters):
@require_context
def resource_exists(context, model, resource_id, session=None):
conditions = [model.id == resource_id]
# Match non deleted resources by the id
conditions = [model.id == resource_id, ~model.deleted]
if 'no' == context.read_deleted:
conditions.append(~model.deleted)
# If the context is not admin we limit it to the context's project
if is_user_context(context) and hasattr(model, 'project_id'):
conditions.append(model.project_id == context.project_id)