From 84431839d972a9a2339ee220e3183130cd47c11c Mon Sep 17 00:00:00 2001 From: John Griffith Date: Mon, 22 Dec 2014 17:05:01 -0700 Subject: [PATCH] Fix broken StorPool driver The newly added StorPool driver has a number of issues; It imports it's own 3'rd party libs which are not in the requirements file, it declares conf options but never registers them, and as a result of these two things it break the ability to generate a configuration file. This patch adds a try_import around the import storpool calls like we do in other drivers, and it registers the config options properly. We also move the api setting out of init and into the check_setup so the service doesn't crash if somebody tries to load the driver without the required storpool modules. Closes-Bug: 1405023 Closes-Bug: 1405022 Closes-Bug: 1405016 Closes-Bug: 1403532 Change-Id: I61340ab7c5abcdc21dbb12cf0693da036e69e90c --- cinder/tests/test_storpool.py | 2 +- cinder/volume/drivers/storpool.py | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cinder/tests/test_storpool.py b/cinder/tests/test_storpool.py index d5e02cf06..6a6fec796 100644 --- a/cinder/tests/test_storpool.py +++ b/cinder/tests/test_storpool.py @@ -161,9 +161,9 @@ class StorPoolTestCase(test.TestCase): self.driver = driver.StorPoolDriver(execute=mock_exec, configuration=self.cfg) + self.driver.check_for_setup_error() def test_initialized(self): - self.driver.check_for_setup_error() self.driver.validate_connector(None) self.driver.validate_connector(5) c = self.driver.initialize_connection(None, None) diff --git a/cinder/volume/drivers/storpool.py b/cinder/volume/drivers/storpool.py index f8cc49c57..36a5116bc 100644 --- a/cinder/volume/drivers/storpool.py +++ b/cinder/volume/drivers/storpool.py @@ -18,20 +18,23 @@ from __future__ import absolute_import from oslo.config import cfg +from oslo.utils import importutils from oslo.utils import units import six from cinder import exception -from cinder.i18n import _LE +from cinder.i18n import _, _LE from cinder.openstack.common import log as logging from cinder.volume import driver from cinder.volume import volume_types LOG = logging.getLogger(__name__) -from storpool import spapi -from storpool import spopenstack -from storpool import sptypes +storpool = importutils.try_import('storpool') +if storpool: + from storpool import spapi + from storpool import spopenstack + from storpool import sptypes storpool_opts = [ @@ -43,9 +46,12 @@ storpool_opts = [ help='The default StorPool chain replication value. ' 'Used when creating a volume with no specified type if ' 'storpool_template is not set. Also used for calculating ' - 'the apparent free space reported in the stats.') + 'the apparent free space reported in the stats.'), ] +CONF = cfg.CONF +CONF.register_opts(storpool_opts) + class StorPoolDriver(driver.VolumeDriver): """The StorPool block device driver using the StorPool API""" @@ -58,7 +64,7 @@ class StorPoolDriver(driver.VolumeDriver): self._sp_config = None self._ourId = None self._ourIdInt = None - self._attach = spopenstack.AttachDB(log=LOG) + self._attach = None def _backendException(self, e): return exception.VolumeBackendAPIException(data=six.text_type(e)) @@ -179,6 +185,11 @@ class StorPoolDriver(driver.VolumeDriver): raise self._backendException(e) def check_for_setup_error(self): + if storpool is None: + msg = _('storpool libraries not found') + raise exception.VolumeBackendAPIException(data=msg) + + self._attach = spopenstack.AttachDB(log=LOG) try: self._attach.api() except Exception as e: -- 2.45.2