Skip to content

Commit

Permalink
StorPool: Raise on spopenstack, SP_OURID issues
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sp-bmilanov authored and kpawar89 committed Jul 4, 2024
1 parent 7c2c80c commit b290711
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
21 changes: 13 additions & 8 deletions os_brick/initiator/connectors/storpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,19 @@ def __init__(self, root_helper, driver=None,
raise exception.BrickException(
'Could not import the StorPool API bindings')

if spopenstack is not None:
try:
self._attach = spopenstack.AttachDB(log=LOG)
except Exception as e:
raise exception.BrickException(
'Could not initialize the StorPool API bindings: %s' % (e))
else:
self._attach = None
if spopenstack is None:
raise exception.BrickException(
'Could not import the required module "storpool.spopenstack"')

try:
self._attach = spopenstack.AttachDB(log=LOG)
except Exception as e:
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):
"""Retry detaching.
Expand Down
10 changes: 10 additions & 0 deletions os_brick/tests/initiator/connectors/test_storpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ def setUp(self):
None, execute=self.execute)
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):
volume_name = volumeNameExt(self.fakeProp['volume'])
api = mock.MagicMock(spec=['volumesReassignWait', 'volumeInfo'])
Expand Down

0 comments on commit b290711

Please sign in to comment.