Use object instead of string when reset backup

Now in reset backup status api, the "backup service" is a string,
it should be an object.

Closes-bug: #1607157

Change-Id: Id86260fffed488ee316f83c179cd948378cfbb73
This commit is contained in:
wangxiyuan 2016-07-27 14:58:02 +08:00
parent 4beb06902e
commit 855a0c334c
2 changed files with 21 additions and 5 deletions

View File

@ -815,17 +815,17 @@ class BackupManager(manager.SchedulerDependentManager):
{'backup_id': backup.id,
'status': status})
backup_service = self._map_service_to_driver(backup.service)
LOG.info(_LI('Backup service: %s.'), backup_service)
if backup_service is not None:
backup_service_name = self._map_service_to_driver(backup.service)
LOG.info(_LI('Backup service: %s.'), backup_service_name)
if backup_service_name is not None:
configured_service = self.driver_name
if backup_service != configured_service:
if backup_service_name != configured_service:
err = _('Reset backup status aborted, the backup service'
' currently configured [%(configured_service)s] '
'is not the backup service that was used to create'
' this backup [%(backup_service)s].') % \
{'configured_service': configured_service,
'backup_service': backup_service}
'backup_service': backup_service_name}
raise exception.InvalidBackup(reason=err)
# Verify backup
try:
@ -833,6 +833,7 @@ class BackupManager(manager.SchedulerDependentManager):
if (status == fields.BackupStatus.AVAILABLE
and backup['status'] != fields.BackupStatus.RESTORING):
# check whether we could verify the backup is ok or not
backup_service = self.service.get_backup_driver(context)
if isinstance(backup_service,
driver.BackupDriverWithVerify):
backup_service.verify(backup.id)

View File

@ -1277,8 +1277,23 @@ class BackupTestCaseWithVerify(BaseBackupTest):
with mock.patch.object(manager.BackupManager,
'_map_service_to_driver') as \
mock_map_service_to_driver:
# It should works when the service name is a string
mock_map_service_to_driver.return_value = 'swift'
self.backup_mgr.reset_status(self.ctxt,
backup,
fields.BackupStatus.AVAILABLE)
mock_clean_temp.assert_called_once_with(self.ctxt, backup)
new_backup = db.backup_get(self.ctxt, backup.id)
self.assertEqual(fields.BackupStatus.AVAILABLE,
new_backup['status'])
mock_map_service_to_driver.return_value = \
fake_service.get_backup_driver(self.ctxt)
self.backup_mgr.reset_status(self.ctxt,
backup,
fields.BackupStatus.ERROR)
mock_clean_temp.reset_mock()
self.backup_mgr.reset_status(self.ctxt,
backup,
fields.BackupStatus.AVAILABLE)