From dd66afbd1ddd6f1a4156bb340dd29da2709308ea Mon Sep 17 00:00:00 2001 From: wangxiyuan Date: Thu, 2 Mar 2017 17:26:23 +0800 Subject: [PATCH] Set backup available after verify In backup import request, the backup is set to available before it is verified. Then if the verification failed, the backup's status is set to error. This leads to an unreasonble status change: creating -> available -> error. The available status should be set after the verification when all work is done. And the status change should be like: creating -> available, or creating -> error Closes-bug: #1669628 Change-Id: I67f30df8a8112c953f24f6d2f7d5152416d4f0df --- cinder/backup/manager.py | 7 +++++-- cinder/tests/unit/backup/test_backup.py | 8 +++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cinder/backup/manager.py b/cinder/backup/manager.py index e7be5b8b25d..c3d8a0c1854 100644 --- a/cinder/backup/manager.py +++ b/cinder/backup/manager.py @@ -764,7 +764,6 @@ class BackupManager(manager.ThreadPoolManager): raise exception.InvalidBackup(reason=msg) # Overwrite some fields - backup_options['status'] = fields.BackupStatus.AVAILABLE backup_options['service'] = self.driver_name backup_options['availability_zone'] = self.az backup_options['host'] = self.host @@ -772,7 +771,7 @@ class BackupManager(manager.ThreadPoolManager): # Remove some values which are not actual fields and some that # were set by the API node for key in ('name', 'user_id', 'project_id', 'deleted_at', - 'deleted', 'fail_reason'): + 'deleted', 'fail_reason', 'status'): backup_options.pop(key, None) # Update the database @@ -793,6 +792,10 @@ class BackupManager(manager.ThreadPoolManager): with excutils.save_and_reraise_exception(): self._update_backup_error(backup, six.text_type(err)) + # Update the backup's status + backup.update({"status": fields.BackupStatus.AVAILABLE}) + backup.save() + LOG.info(_LI('Import record id %s metadata from driver ' 'finished.'), backup.id) diff --git a/cinder/tests/unit/backup/test_backup.py b/cinder/tests/unit/backup/test_backup.py index bbef92ac00c..f1a73121f63 100644 --- a/cinder/tests/unit/backup/test_backup.py +++ b/cinder/tests/unit/backup/test_backup.py @@ -1227,7 +1227,13 @@ class BackupTestCaseWithVerify(BaseBackupTest): (backup_driver.__module__, backup_driver.__class__.__name__, 'verify')) - with mock.patch(_mock_backup_verify_class): + + def mock_verify(backup_id): + backup = db.backup_get(self.ctxt, backup_id) + self.assertEqual(fields.BackupStatus.CREATING, backup['status']) + + with mock.patch(_mock_backup_verify_class) as mock_backup_verify: + mock_backup_verify.side_effect = mock_verify self.backup_mgr.import_record(self.ctxt, imported_record, export['backup_service'],