diff --git a/manila/share/manager.py b/manila/share/manager.py index 71d100945f..7fd5f41f29 100644 --- a/manila/share/manager.py +++ b/manila/share/manager.py @@ -207,8 +207,15 @@ class ShareManager(manager.SchedulerDependentManager): """Initialization for a standalone service.""" ctxt = context.get_admin_context() - self.driver.do_setup(ctxt) - self.driver.check_for_setup_error() + try: + self.driver.do_setup(ctxt) + self.driver.check_for_setup_error() + except Exception: + LOG.exception(_LE("Failed to initialize driver %s"), + self.driver.__class__.__name__) + # we don't want to continue since we failed + # to initialize the driver correctly. + return share_instances = self.db.share_instances_get_all_by_host(ctxt, self.host) diff --git a/manila/tests/share/test_manager.py b/manila/tests/share/test_manager.py index 64fc8bc81d..c779caf076 100644 --- a/manila/tests/share/test_manager.py +++ b/manila/tests/share/test_manager.py @@ -137,6 +137,26 @@ class ShareManagerTestCase(test.TestCase): self.share_manager.driver.check_for_setup_error.\ assert_called_once_with() + def test_init_host_with_driver_do_setup_fail(self): + self.mock_object(self.share_manager.driver, 'do_setup', + mock.Mock(side_effect=Exception())) + self.mock_object(manager.LOG, 'exception') + + self.share_manager.init_host() + + manager.LOG.exception.assert_called_with( + mock.ANY, self.share_manager.driver.__class__.__name__) + + def test_init_host_with_driver_check_for_setup_error_fail(self): + self.mock_object(self.share_manager.driver, 'check_for_setup_error', + mock.Mock(side_effect=Exception())) + self.mock_object(manager.LOG, 'exception') + + self.share_manager.init_host() + + manager.LOG.exception.assert_called_with( + mock.ANY, self.share_manager.driver.__class__.__name__) + def _setup_init_mocks(self, setup_access_rules=True): instances = [ db_utils.create_share(id='fake_id_1',