Merge "Check specific driver enabled in create_backup"

This commit is contained in:
Jenkins 2015-11-18 01:29:18 +00:00 committed by Gerrit Code Review
commit 6a4f2c31a6
2 changed files with 46 additions and 2 deletions

View File

@ -395,7 +395,7 @@ class BackupManager(manager.SchedulerDependentManager):
# before going forward. The exception will be caught,
# the volume status will be set back to available and
# the backup status to 'error'
utils.require_driver_initialized(self.driver)
utils.require_driver_initialized(self._get_driver(backend))
backup_service = self.service.get_backup_driver(context)
self._get_driver(backend).backup_volume(context, backup,
@ -490,7 +490,7 @@ class BackupManager(manager.SchedulerDependentManager):
# before going forward. The exception will be caught,
# the volume status will be set back to available and
# the backup status to 'error'
utils.require_driver_initialized(self.driver)
utils.require_driver_initialized(self._get_driver(backend))
backup_service = self.service.get_backup_driver(context)
self._get_driver(backend).restore_backup(context, backup,

View File

@ -540,6 +540,27 @@ class BackupTestCase(BaseBackupTest):
self.backup_mgr.create_backup(self.ctxt, backup)
self.assertEqual(2, notify.call_count)
def test_require_driver_initialized_in_create_backup(self):
"""Test backup creation.
Test require_driver_initialized with _get_driver
in a normal backup creation.
"""
vol_size = 1
vol_id = self._create_volume_db_entry(size=vol_size)
backup = self._create_backup_db_entry(volume_id=vol_id)
self.backup_mgr._get_driver = mock.MagicMock()
self.backup_mgr._get_volume_backend = mock.MagicMock()
self.backup_mgr._get_volume_backend.return_value = 'mybackend'
self.backup_mgr.create_backup(self.ctxt, backup)
self.assertEqual(2, self.backup_mgr._get_driver.call_count)
self.assertEqual(self.backup_mgr._get_driver.call_args_list[0],
mock.call('mybackend'))
self.assertEqual(self.backup_mgr._get_driver.call_args_list[1],
mock.call('mybackend'))
def test_restore_backup_with_bad_volume_status(self):
"""Test error handling.
@ -648,6 +669,29 @@ class BackupTestCase(BaseBackupTest):
self.backup_mgr.restore_backup(self.ctxt, backup, vol_id)
self.assertEqual(2, notify.call_count)
def test_require_driver_initialized_in_restore_backup(self):
"""Test backup restoration.
Test require_driver_initialized with _get_driver
in a normal backup restoration.
"""
vol_size = 1
vol_id = self._create_volume_db_entry(status='restoring-backup',
size=vol_size)
backup = self._create_backup_db_entry(status='restoring',
volume_id=vol_id)
self.backup_mgr._get_driver = mock.MagicMock()
self.backup_mgr._get_volume_backend = mock.MagicMock()
self.backup_mgr._get_volume_backend.return_value = 'mybackend'
self.backup_mgr.restore_backup(self.ctxt, backup, vol_id)
self.assertEqual(2, self.backup_mgr._get_driver.call_count)
self.assertEqual(self.backup_mgr._get_driver.call_args_list[0],
mock.call('mybackend'))
self.assertEqual(self.backup_mgr._get_driver.call_args_list[1],
mock.call('mybackend'))
def test_delete_backup_with_bad_backup_status(self):
"""Test error handling.