Call _init_volume_driver in backup manager

When fixing backup using temp snapshot code path, the call to
_init_volume_driver was missed:
    https://review.openstack.org/#/c/321943/

For drivers that rely on do_setup to initialize the driver, this
is a problem because the driver cannot be used without this call.

This patch fixes the problem by calling _init_volume_driver in
init_host.

Change-Id: Ic197046a480dbf8d73a229580e59cd6d489355fa
Closes-Bug: #1594225
This commit is contained in:
xing-yang 2016-05-21 23:08:25 -04:00
parent 1a5431fe51
commit cbdd0fa1fa
2 changed files with 35 additions and 1 deletions

View File

@ -170,6 +170,23 @@ class BackupManager(manager.SchedulerDependentManager):
LOG.debug("Registering default backend %s.", default)
self.volume_managers['default'] = default
def _init_volume_driver(self, ctxt, driver):
LOG.info(_LI("Starting volume driver %(driver_name)s (%(version)s)."),
{'driver_name': driver.__class__.__name__,
'version': driver.get_version()})
try:
driver.do_setup(ctxt)
driver.check_for_setup_error()
except Exception:
LOG.exception(_LE("Error encountered during initialization of "
"driver: %(name)s."),
{'name': driver.__class__.__name__})
# we don't want to continue since we failed
# to initialize the driver correctly.
return
driver.set_initialized()
@property
def driver_name(self):
"""This function maps old backup services to backup drivers."""
@ -192,6 +209,9 @@ class BackupManager(manager.SchedulerDependentManager):
"""Run initialization needed for a standalone service."""
ctxt = context.get_admin_context()
for mgr in self.volume_managers.values():
self._init_volume_driver(ctxt, mgr.driver)
try:
self._cleanup_incomplete_backup_operations(ctxt)
except Exception:

View File

@ -26,6 +26,7 @@ from oslo_db import exception as db_exc
from oslo_utils import importutils
from oslo_utils import timeutils
import cinder
from cinder.backup import api
from cinder.backup import manager
from cinder import context
@ -204,8 +205,15 @@ class BaseBackupTest(test.TestCase):
class BackupTestCase(BaseBackupTest):
"""Test Case for backups."""
@mock.patch.object(cinder.tests.unit.fake_driver.FakeISCSIDriver,
'set_initialized')
@mock.patch.object(cinder.tests.unit.fake_driver.FakeISCSIDriver,
'do_setup')
@mock.patch.object(cinder.tests.unit.fake_driver.FakeISCSIDriver,
'check_for_setup_error')
@mock.patch('cinder.context.get_admin_context')
def test_init_host(self, mock_get_admin_context):
def test_init_host(self, mock_get_admin_context, mock_check, mock_setup,
mock_set_initialized):
"""Test stuck volumes and backups.
Make sure stuck volumes and backups are reset to correct
@ -249,8 +257,14 @@ class BackupTestCase(BaseBackupTest):
temp_snapshot_id=temp_snap.id)
mock_get_admin_context.side_effect = get_admin_context
self.volume = importutils.import_object(CONF.volume_manager)
self.backup_mgr.volume_managers = {'driver': self.volume}
self.backup_mgr.init_host()
mock_setup.assert_called_once_with(self.ctxt)
mock_check.assert_called_once_with()
mock_set_initialized.assert_called_once_with()
vol1 = db.volume_get(self.ctxt, vol1_id)
self.assertEqual('available', vol1['status'])
vol2 = db.volume_get(self.ctxt, vol2_id)