From a0ab1467eb978e49988380eddbee0a9b2d810474 Mon Sep 17 00:00:00 2001 From: lisali Date: Mon, 7 Mar 2016 14:24:15 +0000 Subject: [PATCH] Fix backup import During importing backup, Cinder finds out the backup with same id, including deleted backup. There is problems in current codes to get backup. This patch is to transfer read_deleted parameter in backup_get. Change-Id: Ie13dfe5980b1c60b44e03267b88cfc056b30043b Closes-bug: #1554055 --- cinder/db/sqlalchemy/api.py | 4 +++- cinder/tests/unit/test_db_api.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 1d7815189..10c5b39fb 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -3664,7 +3664,9 @@ def volume_glance_metadata_delete_by_snapshot(context, snapshot_id): @require_context def backup_get(context, backup_id, read_deleted=None, project_only=True): - return _backup_get(context, backup_id) + return _backup_get(context, backup_id, + read_deleted=read_deleted, + project_only=project_only) def _backup_get(context, backup_id, session=None, read_deleted=None, diff --git a/cinder/tests/unit/test_db_api.py b/cinder/tests/unit/test_db_api.py index f96ced30f..87b658b62 100644 --- a/cinder/tests/unit/test_db_api.py +++ b/cinder/tests/unit/test_db_api.py @@ -26,8 +26,10 @@ from cinder import context from cinder import db from cinder.db.sqlalchemy import api as sqlalchemy_api from cinder import exception +from cinder import objects from cinder import quota from cinder import test +from cinder.tests.unit import fake_constants THREE = 3 THREE_HUNDREDS = 300 @@ -2010,6 +2012,18 @@ class DBAPIBackupTestCase(BaseTest): backup_get = db.backup_get(self.ctxt, backup['id']) self._assertEqualObjects(backup, backup_get) + def test_backup_get_deleted(self): + backup_dic = {'user_id': 'user', + 'project_id': 'project', + 'volume_id': fake_constants.volume_id, + 'size': 1, + 'object_count': 1} + backup = objects.Backup(self.ctxt, **backup_dic) + backup.create() + backup.destroy() + backup_get = db.backup_get(self.ctxt, backup.id, read_deleted='yes') + self.assertEqual(backup.id, backup_get.id) + def tests_backup_get_all(self): all_backups = db.backup_get_all(self.ctxt) self._assertEqualListsOfObjects(self.created, all_backups) -- 2.45.2