From 1c07f221f22f9ce6e2604efb9ce3ac30a42ff38c Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Thu, 27 Jun 2019 11:19:15 +0200 Subject: [PATCH] iSCSI single path: Don't fail if there's no WWN This patch relaxes the single-pathed connections and allows them to complete even when we cannot detect the WWN on the sysfs, just like multipath connections do. Closes-Bug: #1834443 Change-Id: Iae5a304329a2b172bc6b7f310623fad18956ae45 --- os_brick/initiator/connectors/iscsi.py | 8 ++++--- .../tests/initiator/connectors/test_iscsi.py | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/os_brick/initiator/connectors/iscsi.py b/os_brick/initiator/connectors/iscsi.py index eb1377974..a875b76da 100644 --- a/os_brick/initiator/connectors/iscsi.py +++ b/os_brick/initiator/connectors/iscsi.py @@ -571,10 +571,12 @@ class ISCSIConnector(base.BaseLinuxConnector, base_iscsi.BaseISCSIConnector): for __ in range(10): wwn = self._linuxscsi.get_sysfs_wwn(found_devs) if wwn: - return self._get_connect_result(connection_properties, - wwn, found_devs) + break time.sleep(1) - LOG.debug('Could not find the WWN for %s.', found_devs[0]) + else: + LOG.debug('Could not find the WWN for %s.', found_devs[0]) + return self._get_connect_result(connection_properties, + wwn, found_devs) # If we failed we must cleanup the connection, as we could be # leaving the node entry if it's not being used by another device. diff --git a/os_brick/tests/initiator/connectors/test_iscsi.py b/os_brick/tests/initiator/connectors/test_iscsi.py index 83af738c4..7f0dcc944 100644 --- a/os_brick/tests/initiator/connectors/test_iscsi.py +++ b/os_brick/tests/initiator/connectors/test_iscsi.py @@ -1111,6 +1111,27 @@ Setting up iSCSI targets: unused (('ip1:port1', 'tgt1', 4),), force=True, ignore_errors=True) + @mock.patch.object(linuxscsi.LinuxSCSI, 'get_sysfs_wwn', return_value='') + @mock.patch.object(iscsi.ISCSIConnector, '_connect_vol') + @mock.patch.object(iscsi.ISCSIConnector, '_cleanup_connection') + @mock.patch('time.sleep') + def test_connect_single_volume_no_wwn(self, sleep_mock, cleanup_mock, + connect_mock, get_wwn_mock): + def my_connect(rescans, props, data): + data['found_devices'].append('sdz') + + connect_mock.side_effect = my_connect + + res = self.connector._connect_single_volume(self.CON_PROPS) + + expected = {'type': 'block', 'scsi_wwn': '', 'path': '/dev/sdz'} + self.assertEqual(expected, res) + get_wwn_mock.assert_has_calls([mock.call(['sdz'])] * 10) + self.assertEqual(10, get_wwn_mock.call_count) + sleep_mock.assert_has_calls([mock.call(1)] * 10) + self.assertEqual(10, sleep_mock.call_count) + cleanup_mock.assert_not_called() + @staticmethod def _get_connect_vol_data(): return {'stop_connecting': False, 'num_logins': 0, 'failed_logins': 0,