Biser Milanov | 6e82c53 | 2023-06-07 10:33:59 +0300 | [diff] [blame^] | 1 | From 52e433e79281d2ab3f6a42d0ba3ba28bf6f2ff40 Mon Sep 17 00:00:00 2001 |
Biser Milanov | ec7ff6c | 2023-06-02 17:46:23 +0300 | [diff] [blame] | 2 | From: Biser Milanov <biser.milanov@storpool.com> |
| 3 | Date: Fri, 2 Jun 2023 17:43:45 +0300 |
| 4 | Subject: [PATCH] StorPool: Raise on spopenstack, SP_OURID issues |
| 5 | |
Biser Milanov | 6e82c53 | 2023-06-07 10:33:59 +0300 | [diff] [blame^] | 6 | Change-Id: I6030d433dcf45f496bfee79aa00b2af9b51fd420 |
Biser Milanov | ec7ff6c | 2023-06-02 17:46:23 +0300 | [diff] [blame] | 7 | --- |
| 8 | os_brick/initiator/connectors/storpool.py | 21 ++++++++++++------- |
| 9 | .../initiator/connectors/test_storpool.py | 10 +++++++++ |
| 10 | 2 files changed, 23 insertions(+), 8 deletions(-) |
| 11 | |
| 12 | diff --git a/os_brick/initiator/connectors/storpool.py b/os_brick/initiator/connectors/storpool.py |
| 13 | index 9752ad9..43dc7f2 100644 |
| 14 | --- a/os_brick/initiator/connectors/storpool.py |
| 15 | +++ b/os_brick/initiator/connectors/storpool.py |
| 16 | @@ -42,14 +42,19 @@ class StorPoolConnector(base.BaseLinuxConnector): |
| 17 | raise exception.BrickException( |
| 18 | 'Could not import the StorPool API bindings') |
| 19 | |
| 20 | - if spopenstack is not None: |
| 21 | - try: |
| 22 | - self._attach = spopenstack.AttachDB(log=LOG) |
| 23 | - except Exception as e: |
| 24 | - raise exception.BrickException( |
| 25 | - 'Could not initialize the StorPool API bindings: %s' % (e)) |
| 26 | - else: |
| 27 | - self._attach = None |
| 28 | + if spopenstack is None: |
| 29 | + raise exception.BrickException( |
| 30 | + 'Could not import the required module "storpool.spopenstack"') |
| 31 | + |
| 32 | + try: |
| 33 | + self._attach = spopenstack.AttachDB(log=LOG) |
| 34 | + except Exception as e: |
| 35 | + raise exception.BrickException( |
| 36 | + 'Could not initialize the StorPool API bindings: %s' % (e)) |
| 37 | + |
| 38 | + if "SP_OURID" not in self._attach.config(): |
| 39 | + raise exception.BrickException( |
| 40 | + 'Could not read "SP_OURID" from the StorPool configuration"') |
| 41 | |
| 42 | def _detach_retry(self, sp_ourid, volume): |
| 43 | """Retry detaching. |
| 44 | diff --git a/os_brick/tests/initiator/connectors/test_storpool.py b/os_brick/tests/initiator/connectors/test_storpool.py |
Biser Milanov | 6e82c53 | 2023-06-07 10:33:59 +0300 | [diff] [blame^] | 45 | index 86cf216..66b8f81 100644 |
Biser Milanov | ec7ff6c | 2023-06-02 17:46:23 +0300 | [diff] [blame] | 46 | --- a/os_brick/tests/initiator/connectors/test_storpool.py |
| 47 | +++ b/os_brick/tests/initiator/connectors/test_storpool.py |
Biser Milanov | 6e82c53 | 2023-06-07 10:33:59 +0300 | [diff] [blame^] | 48 | @@ -107,6 +107,16 @@ class StorPoolConnectorTestCase(test_connector.ConnectorTestCase): |
Biser Milanov | ec7ff6c | 2023-06-02 17:46:23 +0300 | [diff] [blame] | 49 | None, execute=self.execute) |
| 50 | self.adb = self.connector._attach |
| 51 | |
| 52 | + def test_raise_if_spopenstack_missing(self): |
| 53 | + with mock.patch.object(connector, 'spopenstack', None): |
| 54 | + self.assertRaises(exception.BrickException, |
| 55 | + connector.StorPoolConnector, "") |
| 56 | + |
| 57 | + def test_raise_if_sp_ourid_missing(self): |
| 58 | + with mock.patch.object(spopenstack.AttachDB, 'config', lambda x: {}): |
| 59 | + self.assertRaises(exception.BrickException, |
| 60 | + connector.StorPoolConnector, "") |
| 61 | + |
| 62 | def test_connect_volume(self): |
| 63 | volume_name = volumeNameExt(self.fakeProp['volume']) |
| 64 | api = mock.MagicMock(spec=['volumesReassignWait', 'volumeInfo']) |
| 65 | -- |
| 66 | 2.25.1 |
| 67 | |