diff --git a/os_brick/exception.py b/os_brick/exception.py index 2e4d26280..8c1b112bd 100644 --- a/os_brick/exception.py +++ b/os_brick/exception.py @@ -114,6 +114,10 @@ class TargetPortalNotFound(BrickException): message = _("Unable to find target portal %(target_portal)s.") +class TargetPortalsNotFound(BrickException): + message = _("Unable to find target portal in %(target_portals)s.") + + class FailedISCSITargetPortalLogin(BrickException): message = _("Unable to login to iSCSI Target Portal") diff --git a/os_brick/initiator/connector.py b/os_brick/initiator/connector.py index ba1f63c1a..7d104b066 100644 --- a/os_brick/initiator/connector.py +++ b/os_brick/initiator/connector.py @@ -615,8 +615,14 @@ class ISCSIConnector(InitiatorConnector): try: ips_iqns = self._discover_iscsi_portals(connection_properties) except Exception: - raise exception.TargetPortalNotFound( - target_portal=connection_properties['target_portal']) + if 'target_portals' in connection_properties: + raise exception.TargetPortalsNotFound( + target_portal=connection_properties['target_portals']) + elif 'target_portal' in connection_properties: + raise exception.TargetPortalNotFound( + target_portal=connection_properties['target_portal']) + else: + raise if not connection_properties.get('target_iqns'): # There are two types of iSCSI multipath devices. One which diff --git a/os_brick/tests/initiator/test_connector.py b/os_brick/tests/initiator/test_connector.py index a7c92a6c9..d51980596 100644 --- a/os_brick/tests/initiator/test_connector.py +++ b/os_brick/tests/initiator/test_connector.py @@ -1110,6 +1110,30 @@ Setting up iSCSI targets: unused actual = self.connector.get_all_available_volumes() self.assertItemsEqual(expected, actual) + @mock.patch.object(connector.ISCSIConnector, '_discover_iscsi_portals') + def test_get_potential_paths_failure_mpath_single_target(self, + mock_discover): + connection_properties = { + 'target_portal': '10.0.2.15:3260' + } + self.connector.use_multipath = True + mock_discover.side_effect = exception.BrickException() + self.assertRaises(exception.TargetPortalNotFound, + self.connector._get_potential_volume_paths, + connection_properties) + + @mock.patch.object(connector.ISCSIConnector, '_discover_iscsi_portals') + def test_get_potential_paths_failure_mpath_multi_target(self, + mock_discover): + connection_properties = { + 'target_portals': ['10.0.2.15:3260', '10.0.3.15:3260'] + } + self.connector.use_multipath = True + mock_discover.side_effect = exception.BrickException() + self.assertRaises(exception.TargetPortalsNotFound, + self.connector._get_potential_volume_paths, + connection_properties) + class FibreChannelConnectorTestCase(ConnectorTestCase): def setUp(self):