iSCSI: Improve _get_discoverydb_portals
The _get_discoverydb_portals method doesn't support the case where there are no not targets in the discovery db and it results in an exception being raised instead of returning the expected information. This patch adds exit code 21 to the allowed exit codes of the call to iscsiadm on discoverydb mode. The actual stdout on exit code 21 is: SENDTARGETS: No targets found. iSNS: No targets found. STATIC: No targets found. FIRMWARE: No targets found. Related-Bug: #2004555 Change-Id: I7d5d6dfb9cfb35180350e5ec757159bad13dea85
This commit is contained in:
parent
8daafd376b
commit
f724ab722a
|
@ -364,7 +364,8 @@ class ISCSIConnector(base.BaseLinuxConnector, base_iscsi.BaseISCSIConnector):
|
|||
ip = ip.replace('[', r'\[?').replace(']', r'\]?')
|
||||
out = self._run_iscsiadm_bare(['-m', 'discoverydb',
|
||||
'-o', 'show',
|
||||
'-P', 1])[0] or ""
|
||||
'-P', 1],
|
||||
check_exit_code=(0, 21))[0] or ""
|
||||
regex = ''.join(('^SENDTARGETS:\n.*?^DiscoveryAddress: ',
|
||||
ip, ',', port,
|
||||
'.*?\n(.*?)^(?:DiscoveryAddress|iSNS):.*'))
|
||||
|
|
|
@ -618,7 +618,9 @@ class ISCSIConnectorTestCase(test_connector.ConnectorTestCase):
|
|||
self.SINGLE_CON_PROPS['target_lun'])]
|
||||
self.assertListEqual(expected, res)
|
||||
iscsiadm_mock.assert_called_once_with(
|
||||
['-m', 'discoverydb', '-o', 'show', '-P', 1])
|
||||
['-m', 'discoverydb', '-o', 'show', '-P', 1],
|
||||
check_exit_code=(0, 21)
|
||||
)
|
||||
transport_mock.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(iscsi.ISCSIConnector, '_get_transport', return_value='')
|
||||
|
@ -641,7 +643,9 @@ class ISCSIConnectorTestCase(test_connector.ConnectorTestCase):
|
|||
self.connector._get_discoverydb_portals,
|
||||
self.SINGLE_CON_PROPS)
|
||||
iscsiadm_mock.assert_called_once_with(
|
||||
['-m', 'discoverydb', '-o', 'show', '-P', 1])
|
||||
['-m', 'discoverydb', '-o', 'show', '-P', 1],
|
||||
check_exit_code=(0, 21)
|
||||
)
|
||||
transport_mock.assert_not_called()
|
||||
|
||||
@mock.patch.object(iscsi.ISCSIConnector, '_get_transport', return_value='')
|
||||
|
@ -673,9 +677,30 @@ class ISCSIConnectorTestCase(test_connector.ConnectorTestCase):
|
|||
self.connector._get_discoverydb_portals,
|
||||
self.SINGLE_CON_PROPS)
|
||||
iscsiadm_mock.assert_called_once_with(
|
||||
['-m', 'discoverydb', '-o', 'show', '-P', 1])
|
||||
['-m', 'discoverydb', '-o', 'show', '-P', 1],
|
||||
check_exit_code=(0, 21)
|
||||
)
|
||||
transport_mock.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(iscsi.ISCSIConnector, '_get_transport', return_value='')
|
||||
@mock.patch.object(iscsi.ISCSIConnector, '_run_iscsiadm_bare')
|
||||
def test_get_discoverydb_portals_error_nothing(self, iscsiadm_mock,
|
||||
transport_mock):
|
||||
"""There is no information."""
|
||||
iscsiadm_mock.return_value = (
|
||||
'SENDTARGETS:\nNo targets found.\niSNS:\nNo targets found.\n'
|
||||
'STATIC:\nNo targets found.\nFIRMWARE:\nNo targets found.\n',
|
||||
None)
|
||||
|
||||
self.assertRaises(exception.TargetPortalsNotFound,
|
||||
self.connector._get_discoverydb_portals,
|
||||
self.SINGLE_CON_PROPS)
|
||||
iscsiadm_mock.assert_called_once_with(
|
||||
['-m', 'discoverydb', '-o', 'show', '-P', 1],
|
||||
check_exit_code=(0, 21)
|
||||
)
|
||||
transport_mock.assert_not_called()
|
||||
|
||||
@ddt.data(('/dev/sda', False),
|
||||
('/dev/disk/by-id/scsi-WWID', False),
|
||||
('/dev/dm-11', True),
|
||||
|
|
Loading…
Reference in New Issue