Revert "Temporarily renegenerate the iSCSI patch"

This reverts commit bf1b0ea4cf6462b70fcd544e84725f0406ab3776.

Reason for revert: No longer required

Change-Id: I815eff330b9f30e253ccc413533b0c09204f375f
diff --git a/patches/openstack/cinder/sep-sp-iscsi.patch b/patches/openstack/cinder/sep-sp-iscsi.patch
index b5f1ecc..1ec0908 100644
--- a/patches/openstack/cinder/sep-sp-iscsi.patch
+++ b/patches/openstack/cinder/sep-sp-iscsi.patch
@@ -31,26 +31,25 @@
  .../storpool-iscsi-cefcfe590a07c5c7.yaml      |  15 +
  4 files changed, 972 insertions(+), 11 deletions(-)
  create mode 100644 releasenotes/notes/storpool-iscsi-cefcfe590a07c5c7.yaml
+
 diff --git a/cinder/tests/unit/volume/drivers/test_storpool.py b/cinder/tests/unit/volume/drivers/test_storpool.py
-index 2015c734d..5a45775ce 100644
+index 44707d0b8..d6347e1d5 100644
 --- a/cinder/tests/unit/volume/drivers/test_storpool.py
 +++ b/cinder/tests/unit/volume/drivers/test_storpool.py
-@@ -13,9 +13,13 @@
- #    License for the specific language governing permissions and limitations
+@@ -14,14 +14,24 @@
  #    under the License.
  
-+from __future__ import annotations
  
++from __future__ import annotations
++
 +import dataclasses
  import itertools
  import re
-+import sys
+ import sys
 +from typing import Any, NamedTuple, TYPE_CHECKING  # noqa: H301
  from unittest import mock
  
  import ddt
-@@ -23,13 +27,20 @@ from os_brick.initiator import storpool_utils
- from os_brick.tests.initiator import test_storpool_utils
  from oslo_utils import units
  
 +if TYPE_CHECKING:
@@ -59,21 +58,20 @@
 +    else:
 +        from typing_extensions import Self
 +
-+
+ 
+ fakeStorPool = mock.Mock()
+ fakeStorPool.spopenstack = mock.Mock()
+@@ -31,6 +41,7 @@ fakeStorPool.sptypes = mock.Mock()
+ sys.modules['storpool'] = fakeStorPool
+ 
+ 
 +from cinder.common import constants
  from cinder import exception
  from cinder.tests.unit import fake_constants
  from cinder.tests.unit import test
- from cinder.volume import configuration as conf
+@@ -38,6 +49,13 @@ from cinder.volume import configuration as conf
  from cinder.volume.drivers import storpool as driver
  
--
- volume_types = {
-     fake_constants.VOLUME_TYPE_ID: {},
-     fake_constants.VOLUME_TYPE2_ID: {'storpool_template': 'ssd'},
-@@ -58,6 +69,12 @@ def mock_volume_types(f):
- def volumeName(vid):
-     return 'os--volume-{id}'.format(id=vid)
  
 +_ISCSI_IQN_OURS = 'beleriand'
 +_ISCSI_IQN_OTHER = 'rohan'
@@ -81,24 +79,64 @@
 +_ISCSI_PAT_OTHER = 'roh*'
 +_ISCSI_PAT_BOTH = '*riand roh*'
 +_ISCSI_PORTAL_GROUP = 'openstack_pg'
- 
- def snapshotName(vtype, vid, more=None):
-     return 'os--{t}--{m}--snapshot-{id}'.format(
-@@ -67,6 +84,10 @@ def snapshotName(vtype, vid, more=None):
-     )
++
+ volume_types = {
+     fake_constants.VOLUME_TYPE_ID: {},
+     fake_constants.VOLUME_TYPE2_ID: {'storpool_template': 'ssd'},
+@@ -71,6 +89,10 @@ def snapshotName(vtype, vid):
+     return 'os--snap--{t}--{id}'.format(t=vtype, id=vid)
  
  
 +def targetName(vid):
 +    return 'iqn.2012-11.storpool:{id}'.format(id=vid)
 +
 +
- class MockAPI(object):
-     def __init__(self, *args):
-         self._disks = {}
-@@ -178,6 +199,241 @@ class MockVolumeDB(object):
-             'volume_type': self.vol_types.get(vid),
-         }
+ class MockDisk(object):
+     def __init__(self, diskId):
+         self.id = diskId
+@@ -195,6 +217,315 @@ def MockVolumeUpdateDesc(size):
+     return {'size': size}
  
+ 
++@dataclasses.dataclass(frozen=True)
++class MockIscsiNetwork:
++    """Mock a StorPool IP CIDR network definition (partially)."""
++
++    address: str
++
++
++@dataclasses.dataclass(frozen=True)
++class MockIscsiPortalGroup:
++    """Mock a StorPool iSCSI portal group definition (partially)."""
++
++    name: str
++    networks: list[MockIscsiNetwork]
++
++
++@dataclasses.dataclass(frozen=True)
++class MockIscsiExport:
++    """Mock a StorPool iSCSI exported volume/target definition."""
++
++    portalGroup: str
++    target: str
++
++
++@dataclasses.dataclass(frozen=True)
++class MockIscsiInitiator:
++    """Mock a StorPool iSCSI initiator definition."""
++
++    name: str
++    exports: list[MockIscsiExport]
++
++
++@dataclasses.dataclass(frozen=True)
++class MockIscsiTarget:
++    """Mock a StorPool iSCSI volume-to-target mapping definition."""
++
++    name: str
++    volume: str
++
++
 +class IscsiTestCase(NamedTuple):
 +    """A single test case for the iSCSI config and export methods."""
 +
@@ -112,81 +150,92 @@
 +class MockIscsiConfig:
 +    """Mock the structure returned by the "get current config" query."""
 +
++    portalGroups: dict[str, MockIscsiPortalGroup]
++    initiators: dict[str, MockIscsiInitiator]
++    targets: dict[str, MockIscsiTarget]
++
 +    @classmethod
-+    def build(cls, tcase: IscsiTestCase) -> dict:
++    def build(cls, tcase: IscsiTestCase) -> Self:
 +        """Build a test config structure."""
 +        initiators = {
-+            '0': {'name': _ISCSI_IQN_OTHER, 'exports': []},
++            '0': MockIscsiInitiator(name=_ISCSI_IQN_OTHER, exports=[]),
 +        }
 +        if tcase.initiator is not None:
-+            initiators['1'] = {
-+                'name': tcase.initiator,
-+                'exports': (
++            initiators['1'] = MockIscsiInitiator(
++                name=tcase.initiator,
++                exports=(
 +                    [
-+                        {
-+                            'portalGroup': _ISCSI_PORTAL_GROUP,
-+                            'target': targetName(tcase.volume),
-+                        },
++                        MockIscsiExport(
++                            portalGroup=_ISCSI_PORTAL_GROUP,
++                            target=targetName(tcase.volume),
++                        ),
 +                    ]
 +                    if tcase.exported
 +                    else []
 +                ),
-+            }
++            )
 +
 +        targets = {
-+            '0': {
-+                'name': targetName(fake_constants.VOLUME2_ID),
-+                'volume': volumeName(fake_constants.VOLUME2_ID),
-+            },
++            '0': MockIscsiTarget(
++                name=targetName(fake_constants.VOLUME2_ID),
++                volume=volumeName(fake_constants.VOLUME2_ID),
++            ),
 +        }
 +        if tcase.volume is not None:
-+            targets['1'] = {
-+                'name': targetName(tcase.volume),
-+                'volume': volumeName(tcase.volume),
-+            }
++            targets['1'] = MockIscsiTarget(
++                name=targetName(tcase.volume),
++                volume=volumeName(tcase.volume),
++            )
 +
-+        return {
-+
-+            'portalGroups': {
-+                '0': {
-+                    'name': _ISCSI_PORTAL_GROUP + '-not',
-+                    'networks': [],
-+                },
-+                '1': {
-+                    'name': _ISCSI_PORTAL_GROUP,
-+                    'networks': [
-+                        {'address': "192.0.2.0"},
-+                        {'address': "195.51.100.0"},
++        return cls(
++            portalGroups={
++                '0': MockIscsiPortalGroup(
++                    name=_ISCSI_PORTAL_GROUP + '-not',
++                    networks=[],
++                ),
++                '1': MockIscsiPortalGroup(
++                    name=_ISCSI_PORTAL_GROUP,
++                    networks=[
++                        MockIscsiNetwork(address="192.0.2.0"),
++                        MockIscsiNetwork(address="195.51.100.0"),
 +                    ],
-+                },
++                ),
 +            },
-+            'initiators': initiators,
-+            'targets': targets,
++            initiators=initiators,
++            targets=targets,
++        )
 +
-+        }
 +
++@dataclasses.dataclass(frozen=True)
++class MockIscsiConfigTop:
++    """Mock the top level of the "get the iSCSI configuration" response."""
++
++    iscsi: MockIscsiConfig
 +
 +
 +class MockIscsiAPI:
 +    """Mock only the iSCSI-related calls of the StorPool API bindings."""
 +
 +    _asrt: test.TestCase
-+    _configs: list[dict]
++    _configs: list[MockIscsiConfig]
 +
 +    def __init__(
 +        self,
-+        configs: list[dict],
++        configs: list[MockIscsiConfig],
 +        asrt: test.TestCase,
 +    ) -> None:
 +        """Store the reference to the list of iSCSI config objects."""
 +        self._asrt = asrt
 +        self._configs = configs
 +
-+    def get_iscsi_config(self) -> dict:
++    def iSCSIConfig(self) -> MockIscsiConfigTop:
 +        """Return the last version of the iSCSI configuration."""
-+        return {'iscsi': self._configs[-1]}
++        return MockIscsiConfigTop(iscsi=self._configs[-1])
 +
-+    def _handle_export(self, cfg: dict, cmd: dict[str, Any]) -> dict:
++    def _handle_export(
++        self,
++        cfg: MockIscsiConfig, cmd: dict[str, Any],
++    ) -> MockIscsiConfig:
 +        """Add an export for an initiator."""
 +        self._asrt.assertDictEqual(
 +            cmd,
@@ -196,24 +245,30 @@
 +                'volumeName': volumeName(fake_constants.VOLUME_ID),
 +            },
 +        )
-+        self._asrt.assertEqual(cfg['initiators']['1']['name'], cmd['initiator'])
-+        self._asrt.assertListEqual(cfg['initiators']['1']['exports'], [])
++        self._asrt.assertEqual(cfg.initiators['1'].name, cmd['initiator'])
++        self._asrt.assertListEqual(cfg.initiators['1'].exports, [])
 +
-+        cfg['initiators'] = {
-+            **cfg['initiators'],
-+            '1': {
-+                **cfg['initiators']['1'],
-+                'exports': [
-+                    {
-+                        'portalGroup': cmd['portalGroup'],
-+                        'target': targetName(fake_constants.VOLUME_ID),
-+                    },
-+                ],
++        return dataclasses.replace(
++            cfg,
++            initiators={
++                **cfg.initiators,
++                '1': dataclasses.replace(
++                    cfg.initiators['1'],
++                    exports=[
++                        MockIscsiExport(
++                            portalGroup=cmd['portalGroup'],
++                            target=targetName(fake_constants.VOLUME_ID),
++                        ),
++                    ],
++                ),
 +            },
-+        }
-+        return cfg
++        )
 +
-+    def _handle_delete_export(self, cfg: dict, cmd: dict[str, Any]) -> dict:
++    def _handle_delete_export(
++        self,
++        cfg: MockIscsiConfig,
++        cmd: dict[str, Any],
++    ) -> MockIscsiConfig:
 +        """Delete an export for an initiator."""
 +        self._asrt.assertDictEqual(
 +            cmd,
@@ -223,16 +278,21 @@
 +                'volumeName': volumeName(fake_constants.VOLUME_ID),
 +            },
 +        )
-+        self._asrt.assertEqual(cfg['initiators']['1']['name'], cmd['initiator'])
++        self._asrt.assertEqual(cfg.initiators['1'].name, cmd['initiator'])
 +        self._asrt.assertListEqual(
-+            cfg['initiators']['1']['exports'],
-+            [{'portalGroup': _ISCSI_PORTAL_GROUP,
-+                             'target': cfg['targets']['1']['name']}])
++            cfg.initiators['1'].exports,
++            [MockIscsiExport(portalGroup=_ISCSI_PORTAL_GROUP,
++                             target=cfg.targets['1'].name)])
 +
-+        del cfg['initiators']['1']
-+        return cfg
++        updated_initiators = cfg.initiators
++        del updated_initiators['1']
++        return dataclasses.replace(cfg, initiators=updated_initiators)
 +
-+    def _handle_create_initiator(self, cfg: dict, cmd: dict[str, Any]) -> dict:
++    def _handle_create_initiator(
++        self,
++        cfg: MockIscsiConfig,
++        cmd: dict[str, Any],
++    ) -> MockIscsiConfig:
 +        """Add a whole new initiator."""
 +        self._asrt.assertDictEqual(
 +            cmd,
@@ -244,49 +304,61 @@
 +        )
 +        self._asrt.assertNotIn(
 +            cmd['name'],
-+            [init['name'] for init in cfg['initiators'].values()],
++            [init.name for init in cfg.initiators.values()],
 +        )
-+        self._asrt.assertListEqual(sorted(cfg['initiators']), ['0'])
++        self._asrt.assertListEqual(sorted(cfg.initiators), ['0'])
 +
-+        cfg['initiators'] = {
-+            **cfg['initiators'],
-+            '1': {'name': cmd['name'], 'exports': []},
-+        }
-+        return cfg
++        return dataclasses.replace(
++            cfg,
++            initiators={
++                **cfg.initiators,
++                '1': MockIscsiInitiator(name=cmd['name'], exports=[]),
++            },
++        )
 +
-+
-+    def _handle_create_target(self, cfg: dict, cmd: dict[str, Any]) -> dict:
++    def _handle_create_target(
++        self,
++        cfg: MockIscsiConfig,
++        cmd: dict[str, Any],
++    ) -> MockIscsiConfig:
 +        """Add a target for a volume so that it may be exported."""
 +        self._asrt.assertDictEqual(
 +            cmd,
 +            {'volumeName': volumeName(fake_constants.VOLUME_ID)},
 +        )
-+        self._asrt.assertListEqual(sorted(cfg['targets']), ['0'])
-+        cfg['targets'] = {
-+            **cfg['targets'],
-+            '1': {
-+                'name': targetName(fake_constants.VOLUME_ID),
-+                'volume': volumeName(fake_constants.VOLUME_ID),
++        self._asrt.assertListEqual(sorted(cfg.targets), ['0'])
++        return dataclasses.replace(
++            cfg,
++            targets={
++                **cfg.targets,
++                '1': MockIscsiTarget(
++                    name=targetName(fake_constants.VOLUME_ID),
++                    volume=volumeName(fake_constants.VOLUME_ID),
++                ),
 +            },
-+        }
-+        return cfg
++        )
 +
-+    def _handle_delete_target(self, cfg: dict, cmd: dict[str, Any]) -> dict:
++    def _handle_delete_target(
++        self,
++        cfg: MockIscsiConfig,
++        cmd: dict[str, Any]
++    ) -> MockIscsiConfig:
 +        """Remove a target for a volume."""
 +        self._asrt.assertDictEqual(
 +            cmd,
 +            {'volumeName': volumeName(fake_constants.VOLUME_ID)},
 +        )
 +
-+        self._asrt.assertListEqual(sorted(cfg['targets']), ['0', '1'])
-+        del cfg['targets']['1']
-+        return cfg
++        self._asrt.assertListEqual(sorted(cfg.targets), ['0', '1'])
++        updated_targets = cfg.targets
++        del updated_targets['1']
++        return dataclasses.replace(cfg, targets=updated_targets)
 +
 +    def _handle_initiator_add_network(
 +        self,
-+        cfg: dict,
++        cfg: MockIscsiConfig,
 +        cmd: dict[str, Any],
-+    ) -> dict:
++    ) -> MockIscsiConfig:
 +        """Add a network that an initiator is allowed to log in from."""
 +        self._asrt.assertDictEqual(
 +            cmd,
@@ -295,7 +367,7 @@
 +                'net': '0.0.0.0/0',
 +            },
 +        )
-+        return cfg
++        return dataclasses.replace(cfg)
 +
 +    _CMD_HANDLERS = {
 +        'createInitiator': _handle_create_initiator,
@@ -306,7 +378,7 @@
 +        'initiatorAddNetwork': _handle_initiator_add_network,
 +    }
 +
-+    def post_iscsi_config(
++    def iSCSIConfigChange(
 +        self,
 +        commands: dict[str, list[dict[str, dict[str, Any]]]],
 +    ) -> None:
@@ -334,10 +406,11 @@
 +    IscsiTestCase(_ISCSI_IQN_OURS, fake_constants.VOLUME_ID, True, 0),
 +]
 +
- 
++
  def MockSPConfig(section = 's01'):
      res = {}
-@@ -198,7 +454,15 @@ class StorPoolTestCase(test.TestCase):
+     m = re.match('^s0*([A-Za-z0-9]+)$', section)
+@@ -237,7 +568,15 @@ class StorPoolTestCase(test.TestCase):
          self.cfg.volume_backend_name = 'storpool_test'
          self.cfg.storpool_template = None
          self.cfg.storpool_replication = 3
@@ -345,16 +418,16 @@
 +        self.cfg.storpool_iscsi_export_to = ''
 +        self.cfg.storpool_iscsi_learn_initiator_iqns = True
 +        self.cfg.storpool_iscsi_portal_group = _ISCSI_PORTAL_GROUP
-+
-+        self._setup_test_driver()
  
++        self._setup_test_driver()
++
 +    def _setup_test_driver(self):
 +        """Initialize a StorPool driver as per the current configuration."""
          mock_exec = mock.Mock()
          mock_exec.return_value = ('', '')
  
-@@ -216,7 +480,7 @@ class StorPoolTestCase(test.TestCase):
-             self.driver.check_for_setup_error()
+@@ -246,7 +585,7 @@ class StorPoolTestCase(test.TestCase):
+         self.driver.check_for_setup_error()
  
      @ddt.data(
 -        (5, TypeError),
@@ -362,7 +435,7 @@
          ({'no-host': None}, KeyError),
          ({'host': 'sbad'}, driver.StorPoolConfigurationInvalid),
          ({'host': 's01'}, None),
-@@ -232,7 +496,7 @@ class StorPoolTestCase(test.TestCase):
+@@ -262,7 +601,7 @@ class StorPoolTestCase(test.TestCase):
                                conn)
  
      @ddt.data(
@@ -371,7 +444,7 @@
          ({'no-host': None}, KeyError),
          ({'host': 'sbad'}, driver.StorPoolConfigurationInvalid),
      )
-@@ -271,7 +535,7 @@ class StorPoolTestCase(test.TestCase):
+@@ -301,7 +640,7 @@ class StorPoolTestCase(test.TestCase):
              self.assertEqual(21, pool['total_capacity_gb'])
              self.assertEqual(5, int(pool['free_capacity_gb']))
  
@@ -380,7 +453,7 @@
              self.assertFalse(pool['QoS_support'])
              self.assertFalse(pool['thick_provisioning_support'])
              self.assertTrue(pool['thin_provisioning_support'])
-@@ -690,3 +954,179 @@ class StorPoolTestCase(test.TestCase):
+@@ -720,3 +1059,179 @@ class StorPoolTestCase(test.TestCase):
                                 'No such volume',
                                 self.driver.revert_to_snapshot, None,
                                 {'id': vol_id}, {'id': snap_id})
@@ -440,16 +513,16 @@
 +
 +    def _validate_iscsi_config(
 +        self,
-+        cfg: dict,
++        cfg: MockIscsiConfig,
 +        res: dict[str, Any],
 +        tcase: IscsiTestCase,
 +    ) -> None:
 +        """Make sure the returned structure makes sense."""
 +        initiator = res['initiator']
-+        cfg_initiator = cfg['initiators'].get('1')
++        cfg_initiator = cfg.initiators.get('1')
 +
-+        self.assertIs(res['cfg']['iscsi'], cfg)
-+        self.assertEqual(res['pg']['name'], _ISCSI_PORTAL_GROUP)
++        self.assertIs(res['cfg'].iscsi, cfg)
++        self.assertEqual(res['pg'].name, _ISCSI_PORTAL_GROUP)
 +
 +        if tcase.initiator is None:
 +            self.assertIsNone(initiator)
@@ -461,7 +534,7 @@
 +            self.assertIsNone(res['target'])
 +        else:
 +            self.assertIsNotNone(res['target'])
-+        self.assertEqual(res['target'], cfg['targets'].get('1'))
++        self.assertEqual(res['target'], cfg.targets.get('1'))
 +
 +        if tcase.initiator is None:
 +            self.assertIsNone(cfg_initiator)
@@ -470,7 +543,7 @@
 +            self.assertIsNotNone(cfg_initiator)
 +            if tcase.exported:
 +                self.assertIsNotNone(res['export'])
-+                self.assertEqual(res['export'], cfg_initiator['exports'][0])
++                self.assertEqual(res['export'], cfg_initiator.exports[0])
 +            else:
 +                self.assertIsNone(res['export'])
 +
@@ -480,7 +553,7 @@
 +        cfg_orig = MockIscsiConfig.build(tcase)
 +        configs = [cfg_orig]
 +        iapi = MockIscsiAPI(configs, self)
-+        with mock.patch.object(self.driver, '_sp_api', iapi):
++        with mock.patch.object(self.driver._attach, 'api', new=lambda: iapi):
 +            res = self.driver._get_iscsi_config(
 +                _ISCSI_IQN_OURS,
 +                fake_constants.VOLUME_ID,
@@ -494,7 +567,7 @@
 +        cfg_orig = MockIscsiConfig.build(tcase)
 +        configs = [cfg_orig]
 +        iapi = MockIscsiAPI(configs, self)
-+        with mock.patch.object(self.driver, '_sp_api', iapi):
++        with mock.patch.object(self.driver._attach, 'api', new=lambda: iapi):
 +            self.driver._create_iscsi_export(
 +                {
 +                    'id': fake_constants.VOLUME_ID,
@@ -509,13 +582,13 @@
 +
 +        self.assertEqual(len(configs), tcase.commands_count + 1)
 +        cfg_final = configs[-1]
-+        self.assertEqual(cfg_final['initiators']['1']['name'], _ISCSI_IQN_OURS)
++        self.assertEqual(cfg_final.initiators['1'].name, _ISCSI_IQN_OURS)
 +        self.assertEqual(
-+            cfg_final['initiators']['1']['exports'][0]['target'],
++            cfg_final.initiators['1'].exports[0].target,
 +            targetName(fake_constants.VOLUME_ID),
 +        )
 +        self.assertEqual(
-+            cfg_final['targets']['1']['volume'],
++            cfg_final.targets['1'].volume,
 +            volumeName(fake_constants.VOLUME_ID),
 +        )
 +
@@ -525,26 +598,26 @@
 +        configs = [cfg_orig]
 +        iapi = MockIscsiAPI(configs, self)
 +
-+        def _target_exists(cfg: dict, volume: str) -> bool:
-+            for name, target in cfg['targets'].items():
-+                if target['volume'] == volumeName(volume):
++        def _target_exists(cfg: MockIscsiConfig, volume: str) -> bool:
++            for name, target in cfg.targets.items():
++                if target.volume == volumeName(volume):
 +                    return True
 +            return False
 +
-+        def _export_exists(cfg: dict, volume: str) -> bool:
-+            for name, initiator in cfg['initiators'].items():
-+                for export in initiator['exports']:
-+                    if export['target'] == targetName(volume):
++        def _export_exists(cfg: MockIscsiConfig, volume: str) -> bool:
++            for name, initiator in cfg.initiators.items():
++                for export in initiator.exports:
++                    if export.target == targetName(volume):
 +                        return True
 +            return False
 +
 +        if tcase.exported:
 +            self.assertTrue(
-+                _target_exists(iapi.get_iscsi_config()['iscsi'], tcase.volume))
++                _target_exists(iapi.iSCSIConfig().iscsi, tcase.volume))
 +            self.assertTrue(
-+                _export_exists(iapi.get_iscsi_config()['iscsi'], tcase.volume))
++                _export_exists(iapi.iSCSIConfig().iscsi, tcase.volume))
 +
-+        with mock.patch.object(self.driver, '_sp_api', iapi):
++        with mock.patch.object(self.driver._attach, 'api', new=lambda: iapi):
 +            self.driver._remove_iscsi_export(
 +                {
 +                    'id': fake_constants.VOLUME_ID,
@@ -557,32 +630,22 @@
 +            )
 +
 +        self.assertFalse(
-+            _target_exists(iapi.get_iscsi_config()['iscsi'], tcase.volume))
++            _target_exists(iapi.iSCSIConfig().iscsi, tcase.volume))
 +        self.assertFalse(
-+            _export_exists(iapi.get_iscsi_config()['iscsi'], tcase.volume))
++            _export_exists(iapi.iSCSIConfig().iscsi, tcase.volume))
 diff --git a/cinder/volume/drivers/storpool.py b/cinder/volume/drivers/storpool.py
-index 2dc7bb6be..ec6f6ba50 100644
+index a8200a7f1..d931200f6 100644
 --- a/cinder/volume/drivers/storpool.py
 +++ b/cinder/volume/drivers/storpool.py
-@@ -15,13 +15,17 @@
+@@ -15,6 +15,7 @@
  
  """StorPool block device driver"""
  
 +import fnmatch
  import platform
  
- from os_brick.initiator import storpool_utils
  from oslo_config import cfg
- from oslo_log import log as logging
- from oslo_utils import excutils
-+from oslo_utils import netutils
- from oslo_utils import units
-+from oslo_utils import uuidutils
-+import six
- 
- from cinder.common import constants
- from cinder import context
-@@ -36,6 +40,32 @@ LOG = logging.getLogger(__name__)
+@@ -43,6 +44,32 @@ if storpool:
  
  
  storpool_opts = [
@@ -615,67 +678,27 @@
      cfg.StrOpt('storpool_template',
                 default=None,
                 help='The StorPool template for volumes with no type.'),
-@@ -51,10 +81,38 @@ CONF = cfg.CONF
- CONF.register_opts(storpool_opts, group=configuration.SHARED_CONF_GROUP)
- 
- 
-+def _extract_cinder_ids(urls):
-+    ids = []
-+    for url in urls:
-+        # The url can also be None and a TypeError is raised
-+        # TypeError: a bytes-like object is required, not 'str'
-+        if not url:
-+            continue
-+        parts = netutils.urlsplit(url)
-+        if parts.scheme == 'cinder':
-+            if parts.path:
-+                vol_id = parts.path.split('/')[-1]
-+            else:
-+                vol_id = parts.netloc
-+            if uuidutils.is_uuid_like(vol_id):
-+                ids.append(vol_id)
-+            else:
-+                LOG.debug("Ignoring malformed image location uri "
-+                          "'%(url)s'", {'url': url})
-+
-+    return ids
-+
-+
- class StorPoolConfigurationInvalid(exception.CinderException):
-     message = _("Invalid parameter %(param)s in the %(section)s section "
-                 "of the /etc/storpool.conf file: %(error)s")
- 
-+    def get_iscsi_config(self):
-+        return self._api_call('GET', '/ctrl/1.0/iSCSIConfig')
-+
-+    def post_iscsi_config(self, data):
-+        return self._api_call('POST', '/ctrl/1.0/iSCSIConfig', data)
-+
- 
- @interface.volumedriver
- class StorPoolDriver(driver.VolumeDriver):
-@@ -89,10 +147,11 @@ class StorPoolDriver(driver.VolumeDriver):
-         2.1.0   - Use the new API client in os-brick to communicate with the
-                   StorPool API instead of packages `storpool` and
-                   `storpool.spopenstack`
-+        2.2.0   - Add iSCSI export support.
- 
+@@ -93,9 +120,10 @@ class StorPoolDriver(driver.VolumeDriver):
+                   add ignore_errors to the internal _detach_volume() method
+         1.2.3   - Advertise some more driver capabilities.
+         2.0.0   - Implement revert_to_snapshot().
++        2.1.0   - Add iSCSI export support.
      """
  
--    VERSION = '2.1.0'
-+    VERSION = '2.2.0'
+-    VERSION = '2.0.0'
++    VERSION = '2.1.0'
      CI_WIKI_NAME = 'StorPool_distributed_storage_CI'
  
      def __init__(self, *args, **kwargs):
-@@ -103,6 +162,7 @@ class StorPoolDriver(driver.VolumeDriver):
+@@ -105,6 +133,7 @@ class StorPoolDriver(driver.VolumeDriver):
+         self._ourId = None
          self._ourIdInt = None
-         self._sp_api = None
-         self._volume_prefix = None
+         self._attach = None
 +        self._use_iscsi = False
  
      @staticmethod
      def get_driver_options():
-@@ -158,10 +218,327 @@ class StorPoolDriver(driver.VolumeDriver):
+@@ -159,10 +188,327 @@ class StorPoolDriver(driver.VolumeDriver):
              raise StorPoolConfigurationInvalid(
                  section=hostname, param='SP_OURID', error=e)
  
@@ -739,11 +762,11 @@
 +        will be needed to create, ensure, or remove the iSCSI export of
 +        the specified volume to the specified initiator.
 +        """
-+        cfg = self._sp_api.get_iscsi_config()
++        cfg = self._attach.api().iSCSIConfig()
 +
 +        pg_name = self.configuration.storpool_iscsi_portal_group
 +        pg_found = [
-+            pg for pg in cfg['iscsi']['portalGroups'].values() if pg['name'] == pg_name
++            pg for pg in cfg.iscsi.portalGroups.values() if pg.name == pg_name
 +        ]
 +        if not pg_found:
 +            raise Exception('StorPool Cinder iSCSI configuration error: '
@@ -752,7 +775,7 @@
 +
 +        # Do we know about this initiator?
 +        i_found = [
-+            init for init in cfg['iscsi']['initiators'].values() if init['name'] == iqn
++            init for init in cfg.iscsi.initiators.values() if init.name == iqn
 +        ]
 +        if i_found:
 +            initiator = i_found[0]
@@ -760,9 +783,9 @@
 +            initiator = None
 +
 +        # Is this volume already being exported?
-+        volname = self._os_to_sp_volume_name(volume_id)
++        volname = self._attach.volumeName(volume_id)
 +        t_found = [
-+            tgt for tgt in cfg['iscsi']['targets'].values() if tgt['volume'] == volname
++            tgt for tgt in cfg.iscsi.targets.values() if tgt.volume == volname
 +        ]
 +        if t_found:
 +            target = t_found[0]
@@ -773,8 +796,8 @@
 +        export = None
 +        if initiator is not None and target is not None:
 +            e_found = [
-+                exp for exp in initiator['exports']
-+                if exp['portalGroup'] == pg['name'] and exp['target'] == target['name']
++                exp for exp in initiator.exports
++                if exp.portalGroup == pg.name and exp.target == target.name
 +            ]
 +            if e_found:
 +                export = e_found[0]
@@ -821,7 +844,7 @@
 +                LOG.info('Creating a StorPool iSCSI initiator '
 +                         'for "{host}s" ({iqn}s)',
 +                         {'host': connector['host'], 'iqn': iqn})
-+                self._sp_api.post_iscsi_config({
++                self._attach.api().iSCSIConfigChange({
 +                    'commands': [
 +                        {
 +                            'createInitiator': {
@@ -848,7 +871,7 @@
 +                    'vol_id': volume['id'],
 +                }
 +            )
-+            self._sp_api.post_iscsi_config({
++            self._attach.api().iSCSIConfigChange({
 +                'commands': [
 +                    {
 +                        'createTarget': {
@@ -869,14 +892,14 @@
 +                         'vol_id': volume['id'],
 +                         'host': connector['host'],
 +                         'iqn': iqn,
-+                         'pg': cfg['pg']['name']
++                         'pg': cfg['pg'].name
 +                     })
-+            self._sp_api.post_iscsi_config({
++            self._attach.api().iSCSIConfigChange({
 +                'commands': [
 +                    {
 +                        'export': {
 +                            'initiator': iqn,
-+                            'portalGroup': cfg['pg']['name'],
++                            'portalGroup': cfg['pg'].name,
 +                            'volumeName': cfg['volume_name'],
 +                        },
 +                    },
@@ -884,10 +907,10 @@
 +            })
 +
 +        target_portals = [
-+            "{addr}:3260".format(addr=net['address'])
-+            for net in cfg['pg']['networks']
++            "{addr}:3260".format(addr=net.address)
++            for net in cfg['pg'].networks
 +        ]
-+        target_iqns = [cfg['target']['name']] * len(target_portals)
++        target_iqns = [cfg['target'].name] * len(target_portals)
 +        target_luns = [0] * len(target_portals)
 +        if connector.get('multipath', False):
 +            multipath_settings = {
@@ -942,32 +965,32 @@
 +                         'vol_id': volume['id'],
 +                         'host': connector['host'],
 +                         'iqn': connector['initiator'],
-+                         'pg': cfg['pg']['name'],
++                         'pg': cfg['pg'].name,
 +                     })
 +            try:
-+                self._sp_api.post_iscsi_config({
++                self._attach.api().iSCSIConfigChange({
 +                    'commands': [
 +                        {
 +                            'exportDelete': {
-+                                'initiator': cfg['initiator']['name'],
-+                                'portalGroup': cfg['pg']['name'],
++                                'initiator': cfg['initiator'].name,
++                                'portalGroup': cfg['pg'].name,
 +                                'volumeName': cfg['volume_name'],
 +                            },
 +                        },
 +                    ]
 +                })
-+            except StorPoolAPIError as e:
++            except spapi.ApiError as e:
 +                if e.name not in ('objectExists', 'objectDoesNotExist'):
 +                    raise
 +                LOG.info('Looks like somebody beat us to it')
 +
 +        if cfg['target'] is not None:
 +            last = True
-+            for initiator in cfg['cfg']['iscsi']['initiators'].values():
-+                if initiator['name'] == cfg['initiator']['name']:
++            for initiator in cfg['cfg'].iscsi.initiators.values():
++                if initiator.name == cfg['initiator'].name:
 +                    continue
-+                for exp in initiator['exports']:
-+                    if exp['target'] == cfg['target']['name']:
++                for exp in initiator.exports:
++                    if exp.target == cfg['target'].name:
 +                        last = False
 +                        break
 +                if not last:
@@ -983,7 +1006,7 @@
 +                    }
 +                )
 +                try:
-+                    self._sp_api.post_iscsi_config({
++                    self._attach.api().iSCSIConfigChange({
 +                        'commands': [
 +                            {
 +                                'deleteTarget': {
@@ -992,7 +1015,7 @@
 +                            },
 +                        ]
 +                    })
-+                except StorPoolAPIError as e:
++                except spapi.ApiError as e:
 +                    if e.name not in ('objectDoesNotExist', 'invalidParam'):
 +                        raise
 +                    LOG.info('Looks like somebody beat us to it')
@@ -1003,7 +1026,7 @@
          return {'driver_volume_type': 'storpool',
                  'data': {
                      'client_id': self._storpool_client_id(connector),
-@@ -170,6 +547,9 @@ class StorPoolDriver(driver.VolumeDriver):
+@@ -171,6 +517,9 @@ class StorPoolDriver(driver.VolumeDriver):
                  }}
  
      def terminate_connection(self, volume, connector, **kwargs):
@@ -1013,7 +1036,7 @@
          pass
  
      def create_snapshot(self, snapshot):
-@@ -278,11 +658,20 @@ class StorPoolDriver(driver.VolumeDriver):
+@@ -272,11 +621,20 @@ class StorPoolDriver(driver.VolumeDriver):
                      )
  
      def create_export(self, context, volume, connector):
@@ -1033,9 +1056,9 @@
 +        return super()._attach_volume(context, volume, properties, remote)
 +
      def delete_volume(self, volume):
-         name = storpool_utils.os_to_sp_volume_name(
-             self._volume_prefix, volume['id'])
-@@ -321,6 +710,17 @@ class StorPoolDriver(driver.VolumeDriver):
+         name = self._attach.volumeName(volume['id'])
+         try:
+@@ -313,6 +671,17 @@ class StorPoolDriver(driver.VolumeDriver):
              LOG.error("StorPoolDriver API initialization failed: %s", e)
              raise
  
@@ -1052,8 +1075,8 @@
 +
      def _update_volume_stats(self):
          try:
-             dl = self._sp_api.disks_list()
-@@ -346,7 +746,7 @@ class StorPoolDriver(driver.VolumeDriver):
+             dl = self._attach.api().disksList()
+@@ -338,7 +707,7 @@ class StorPoolDriver(driver.VolumeDriver):
              'total_capacity_gb': total / units.Gi,
              'free_capacity_gb': free / units.Gi,
              'reserved_percentage': 0,
@@ -1062,7 +1085,7 @@
              'QoS_support': False,
              'thick_provisioning_support': False,
              'thin_provisioning_support': True,
-@@ -365,7 +765,9 @@ class StorPoolDriver(driver.VolumeDriver):
+@@ -357,7 +726,9 @@ class StorPoolDriver(driver.VolumeDriver):
                  'volume_backend_name') or 'storpool',
              'vendor_name': 'StorPool',
              'driver_version': self.VERSION,
@@ -1074,7 +1097,7 @@
              'clone_across_pools': True,
              'sparse_copy_volume': True,
 diff --git a/doc/source/configuration/block-storage/drivers/storpool-volume-driver.rst b/doc/source/configuration/block-storage/drivers/storpool-volume-driver.rst
-index d2c5895a9..1ba0d2862 100644
+index d2c5895a9..936e83675 100644
 --- a/doc/source/configuration/block-storage/drivers/storpool-volume-driver.rst
 +++ b/doc/source/configuration/block-storage/drivers/storpool-volume-driver.rst
 @@ -19,12 +19,15 @@ Prerequisites
@@ -1097,7 +1120,7 @@
  
  * All nodes that need to access the StorPool API (the compute nodes and
    the node running the ``cinder-volume`` service) must have the following
-@@ -34,6 +37,33 @@ Prerequisites
+@@ -34,6 +37,34 @@ Prerequisites
    * the storpool Python bindings package
    * the storpool.spopenstack Python helper package
  
@@ -1114,24 +1137,25 @@
 +using the standard iSCSI protocol that only requires TCP routing and
 +connectivity between the storage servers and the StorPool clients.
 +The StorPool Cinder driver may be configured to export volumes and
-+snapshots via iSCSI using the ``iscsi_export_to`` and ``iscsi_portal_group``
-+configuration options.
++snapshots via iSCSI using the ``storpool_iscsi_export_to`` and
++``storpool_iscsi_portal_group`` configuration options.
 +
 +Additionally, even if e.g. the hypervisor nodes running Nova will use
 +the StorPool network protocol and run the ``storpool_block`` service
-+(so the ``iscsi_export_to`` option has its default empty string value),
-+the ``iscsi_cinder_volume`` option configures the StorPool Cinder driver
-+so that only the ``cinder-volume`` service will use the iSCSI protocol when
-+attaching volumes and snapshots to transfer data to and from Glance images.
++(so the ``storpool_iscsi_export_to`` option has its default empty string
++value), the ``storpool_iscsi_cinder_volume`` option configures the
++StorPool Cinder driver so that only the ``cinder-volume`` service will
++use the iSCSI protocol when attaching volumes and snapshots to transfer
++data to and from Glance images.
 +
 +Multiattach support for StorPool is only enabled if iSCSI is used:
-+``iscsi_export_to`` is set to ``*``, that is, when all StorPool volumes
-+will be exported via iSCSI to all initiators.
++``storpool_iscsi_export_to`` is set to ``*``, that is, when all StorPool
++volumes will be exported via iSCSI to all initiators.
 +
  Configuring the StorPool volume driver
  --------------------------------------
  
-@@ -55,6 +85,32 @@ volume backend definition) and per volume type:
+@@ -55,6 +86,35 @@ volume backend definition) and per volume type:
    with the default placement constraints for the StorPool cluster.
    The default value for the chain replication is 3.
  
@@ -1139,28 +1163,55 @@
 +described in the previous section, the following options may be defined in
 +the ``cinder.conf`` volume backend definition:
 +
-+- ``iscsi_export_to``: if set to the value ``*``, the StorPool Cinder driver
-+  will export volumes and snapshots using the iSCSI protocol instead of
-+  the StorPool network protocol. The ``iscsi_portal_group`` option must also
-+  be specified.
++- ``storpool_iscsi_export_to``: if set to the value ``*``, the StorPool
++  Cinder driver will export volumes and snapshots using the iSCSI
++  protocol instead of the StorPool network protocol. The
++  ``storpool_iscsi_portal_group`` option must also be specified.
 +
-+- ``iscsi_portal_group``: if the ``iscsi_export_to`` option is set to
-+  the value ``*`` or the ``iscsi_cinder_volume`` option is turned on,
-+  this option specifies the name of the iSCSI portal group that Cinder
-+  volumes will be exported to.
++- ``storpool_iscsi_portal_group``: if the ``storpool_iscsi_export_to``
++  option is set to the value ``*`` or the
++  ``storpool_iscsi_cinder_volume`` option is turned on, this option
++  specifies the name of the iSCSI portal group that Cinder volumes will
++  be exported to.
 +
-+- ``iscsi_cinder_volume``: if enabled, even if the ``iscsi_export_to`` option
-+  has its default empty value, the ``cinder-volume`` service will use iSCSI
-+  to attach the volumes and snapshots for transferring data to and from
-+  Glance images if Glance is configured to use the Cinder glance_store.
++- ``storpool_iscsi_cinder_volume``: if enabled, even if the
++  ``storpool_iscsi_export_to`` option has its default empty value, the
++  ``cinder-volume`` service will use iSCSI to attach the volumes and
++  snapshots for transferring data to and from Glance images if Glance is
++  configured to use the Cinder glance_store.
 +
-+- ``iscsi_learn_initiator_iqns``: if enabled, the StorPool Cinder driver will
-+  automatically use the StorPool API to create definitions for new initiators
-+  in the StorPool cluster's configuration. This is the default behavior of
-+  the driver; it may be disabled in the rare case if, e.g. because of site
-+  policy, OpenStack iSCSI initiators (e.g. Nova hypervisors) need to be
-+  explicitly allowed to use the StorPool iSCSI targets.
++- ``storpool_iscsi_learn_initiator_iqns``: if enabled, the StorPool
++  Cinder driver will automatically use the StorPool API to create
++  definitions for new initiators in the StorPool cluster's
++  configuration. This is the default behavior of the driver; it may be
++  disabled in the rare case if, e.g. because of site policy, OpenStack
++  iSCSI initiators (e.g. Nova hypervisors) need to be explicitly allowed
++  to use the StorPool iSCSI targets.
 +
  Using the StorPool volume driver
  --------------------------------
  
+diff --git a/releasenotes/notes/storpool-iscsi-cefcfe590a07c5c7.yaml b/releasenotes/notes/storpool-iscsi-cefcfe590a07c5c7.yaml
+new file mode 100644
+index 000000000..3863e4099
+--- /dev/null
++++ b/releasenotes/notes/storpool-iscsi-cefcfe590a07c5c7.yaml
+@@ -0,0 +1,15 @@
++features:
++  - |
++    StorPool driver: Added support for exporting the StorPool-backed
++    volumes using the iSCSI protocol, so that the Cinder volume service
++    and/or the Nova or Glance consumers do not need to have the StorPool
++    block device third-party service installed. See the StorPool driver
++    section in the Cinder documentation for more information on the
++    ``storpool_iscsi_export_to``, ``storpool_iscsi_portal_group``,
++    ``storpool_iscsi_cinder_volume``, and
++    ``storpool_iscsi_learn_initiator_iqns`` options.
++
++    .. note::
++       Multiattach support for StorPool is now only enabled if
++       ``storpool_iscsi_export_to`` is set to ``*``, that is, when all
++       StorPool volumes will be exported via iSCSI to all initiators.
+-- 
+2.43.0
+