StorPool: Raise on spopenstack, SP_OURID issues
The module 'spopenstack' is required for this connector, but is installed as needed. Detecting early on if it is missing makes debugging faster. The same is true for the "SP_OURID" configuration item in `_attach.config()`. Change-Id: I6030d433dcf45f496bfee79aa00b2af9b51fd420
This commit is contained in:
parent
7c2c80c9a5
commit
b290711cfb
@ -59,14 +59,19 @@ class StorPoolConnector(base.BaseLinuxConnector):
|
|||||||
raise exception.BrickException(
|
raise exception.BrickException(
|
||||||
'Could not import the StorPool API bindings')
|
'Could not import the StorPool API bindings')
|
||||||
|
|
||||||
if spopenstack is not None:
|
if spopenstack is None:
|
||||||
try:
|
raise exception.BrickException(
|
||||||
self._attach = spopenstack.AttachDB(log=LOG)
|
'Could not import the required module "storpool.spopenstack"')
|
||||||
except Exception as e:
|
|
||||||
raise exception.BrickException(
|
try:
|
||||||
'Could not initialize the StorPool API bindings: %s' % (e))
|
self._attach = spopenstack.AttachDB(log=LOG)
|
||||||
else:
|
except Exception as e:
|
||||||
self._attach = None
|
raise exception.BrickException(
|
||||||
|
'Could not initialize the StorPool API bindings: %s' % (e))
|
||||||
|
|
||||||
|
if "SP_OURID" not in self._attach.config():
|
||||||
|
raise exception.BrickException(
|
||||||
|
'Could not read "SP_OURID" from the StorPool configuration"')
|
||||||
|
|
||||||
def _detach_retry(self, sp_ourid, volume):
|
def _detach_retry(self, sp_ourid, volume):
|
||||||
"""Retry detaching.
|
"""Retry detaching.
|
||||||
|
@ -110,6 +110,16 @@ class StorPoolConnectorTestCase(test_connector.ConnectorTestCase):
|
|||||||
None, execute=self.execute)
|
None, execute=self.execute)
|
||||||
self.adb = self.connector._attach
|
self.adb = self.connector._attach
|
||||||
|
|
||||||
|
def test_raise_if_spopenstack_missing(self):
|
||||||
|
with mock.patch.object(connector, 'spopenstack', None):
|
||||||
|
self.assertRaises(exception.BrickException,
|
||||||
|
connector.StorPoolConnector, "")
|
||||||
|
|
||||||
|
def test_raise_if_sp_ourid_missing(self):
|
||||||
|
with mock.patch.object(spopenstack.AttachDB, 'config', lambda x: {}):
|
||||||
|
self.assertRaises(exception.BrickException,
|
||||||
|
connector.StorPoolConnector, "")
|
||||||
|
|
||||||
def test_connect_volume(self):
|
def test_connect_volume(self):
|
||||||
volume_name = volumeNameExt(self.fakeProp['volume'])
|
volume_name = volumeNameExt(self.fakeProp['volume'])
|
||||||
api = mock.MagicMock(spec=['volumesReassignWait', 'volumeInfo'])
|
api = mock.MagicMock(spec=['volumesReassignWait', 'volumeInfo'])
|
||||||
|
Loading…
Reference in New Issue
Block a user