Fix iSCSI cleanup fix on discovery backends

On Change-Id Iada5d4fbeb07aeaf3afb953a289b6b89778c382c we tried to fix
an issue with the multipath detach of backends that used discovery on
attach, but contrary to the commit message and the docstrings it didn't
look for ip,port in the discoverydb but ip:port instead, which meant
that it would never find what it was looking for.

This patch fixes that fix to make it search for the right regex.

TrivialFix
Closes-Bug: #1699061

Change-Id: Ibfa1a78a555e984c662f668677451f5a3ed55602
This commit is contained in:
Gorka Eguileor 2017-06-29 13:59:04 +02:00
parent 32ab0d1670
commit be37c2e040
2 changed files with 25 additions and 13 deletions

View File

@ -342,12 +342,18 @@ class ISCSIConnector(base.BaseLinuxConnector, base_iscsi.BaseISCSIConnector):
:type connection_properties: dict
:returns: list of tuples of (ip, iqn, lun)
"""
ip, port = connection_properties['target_portal'].rsplit(':', 1)
# NOTE(geguileo): I don't know if IPv6 will be reported with []
# or not, so we'll make them optional.
ip = ip.replace('[', '\[?').replace(']', '\]?')
out = self._run_iscsiadm_bare(['-m', 'discoverydb',
'-o', 'show',
'-P', 1])[0] or ""
regex = ('^SENDTARGETS:\n.*?^DiscoveryAddress: ' +
connection_properties['target_portal'] +
'.*?\n(.*?)^(?:DiscoveryAddress|iSNS):.*')
regex = ''.join(('^SENDTARGETS:\n.*?^DiscoveryAddress: ',
ip, ',', port,
'.*?\n(.*?)^(?:DiscoveryAddress|iSNS):.*'))
LOG.debug('Regex to get portals from discoverydb: %s', regex)
info = re.search(regex, out, re.DOTALL | re.MULTILINE)
ips = []

View File

@ -539,17 +539,20 @@ class ISCSIConnectorTestCase(test_connector.ConnectorTestCase):
@mock.patch.object(iscsi.ISCSIConnector, '_run_iscsiadm_bare')
def test_get_discoverydb_portals(self, is_iser, iscsiadm_mock,
transport_mock):
params = {'iqn1': self.SINGLE_CON_PROPS['target_iqn'],
'iqn2': 'iqn.2004-04.com.qnap:ts-831x:iscsi.cinder-2017.9ef',
'ip1': self.SINGLE_CON_PROPS['target_portal'],
'ip2': '192.168.1.3:3260',
'transport': 'iser' if is_iser else 'default',
'other_transport': 'default' if is_iser else 'iser'}
params = {
'iqn1': self.SINGLE_CON_PROPS['target_iqn'],
'iqn2': 'iqn.2004-04.com.qnap:ts-831x:iscsi.cinder-2017.9ef',
'addr': self.SINGLE_CON_PROPS['target_portal'].replace(':', ','),
'ip1': self.SINGLE_CON_PROPS['target_portal'],
'ip2': '192.168.1.3:3260',
'transport': 'iser' if is_iser else 'default',
'other_transport': 'default' if is_iser else 'iser',
}
iscsiadm_mock.return_value = (
'SENDTARGETS:\n'
'DiscoveryAddress: 192.168.1.33,3260\n'
'DiscoveryAddress: %(ip1)s\n'
'DiscoveryAddress: %(addr)s\n'
'Target: %(iqn1)s\n'
' Portal: %(ip2)s,1\n'
' Iface Name: %(transport)s\n'
@ -613,12 +616,15 @@ class ISCSIConnectorTestCase(test_connector.ConnectorTestCase):
def test_get_discoverydb_portals_error_is_present(self, iscsiadm_mock,
transport_mock):
"""DiscoveryAddress is present but wrong iterface."""
params = {'iqn': self.SINGLE_CON_PROPS['target_iqn'],
'ip': self.SINGLE_CON_PROPS['target_portal']}
params = {
'iqn': self.SINGLE_CON_PROPS['target_iqn'],
'addr': self.SINGLE_CON_PROPS['target_portal'].replace(':', ','),
'ip': self.SINGLE_CON_PROPS['target_portal'],
}
iscsiadm_mock.return_value = (
'SENDTARGETS:\n'
'DiscoveryAddress: 192.168.1.33,3260\n'
'DiscoveryAddress: %(ip)s\n'
'DiscoveryAddress: %(addr)s\n'
'Target: %(iqn)s\n'
' Portal: %(ip)s,1\n'
' Iface Name: iser\n'