]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix broken StorPool driver
authorJohn Griffith <john.griffith8@gmail.com>
Tue, 23 Dec 2014 00:05:01 +0000 (17:05 -0700)
committerJohn Griffith <john.griffith8@gmail.com>
Wed, 24 Dec 2014 14:58:03 +0000 (07:58 -0700)
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
cinder/volume/drivers/storpool.py

index d5e02cf0673a238335d3e3e9884ec7e9c68812e2..6a6fec7969d33a027261ee32b3213cf86f4c300e 100644 (file)
@@ -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)
index f8cc49c5716cf73322660a4dfa7fe9a2e0fce7ad..36a5116bcfbbec64eefd5369c5d0a1d6c742d936 100644 (file)
 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: