From 63f52be546b4bb4689e400521bea48ce25daa703 Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Mon, 1 Jun 2020 18:38:45 +0200 Subject: [PATCH] iSCSI detect multipath DM with no WWN If udev rules are slow (or don't happen) and they don't generate the symlinks we use to detect the WWN, or if we just fail to find the WWN we end up not detecting the iSCSI multipath even if it is present in the system. With this patch we no longer wait to find the WWN before trying to locate the multipath device. This means that as long as the multipath daemon is able to generate the multipath we will be able to return a multipath device path to the caller. Closes-Bug: 1881619 Change-Id: Ic48bd9ac408c56073e58168df7e74e4b949ac2f2 --- os_brick/initiator/connectors/iscsi.py | 6 ++-- .../tests/initiator/connectors/test_iscsi.py | 36 +++++++++++++++++++ ...-multipath-detection-f36f28a993f61936.yaml | 6 ++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/improve-iscsi-multipath-detection-f36f28a993f61936.yaml diff --git a/os_brick/initiator/connectors/iscsi.py b/os_brick/initiator/connectors/iscsi.py index 336679c52..f497e5da4 100644 --- a/os_brick/initiator/connectors/iscsi.py +++ b/os_brick/initiator/connectors/iscsi.py @@ -738,10 +738,10 @@ class ISCSIConnector(base.BaseLinuxConnector, base_iscsi.BaseISCSIConnector): # We have devices but we don't know the wwn yet if not wwn and found: wwn = self._linuxscsi.get_sysfs_wwn(found) - # We have the wwn but not a multipath - if wwn and not mpath: + if not mpath and found: mpath = self._linuxscsi.find_sysfs_multipath_dm(found) - if not (mpath or wwn_added): + # We have the wwn but not a multipath + if wwn and not(mpath or wwn_added): # Tell multipathd that this wwn is a multipath and hint # multipathd to recheck all the devices we have just # connected. We only do this once, since for any new diff --git a/os_brick/tests/initiator/connectors/test_iscsi.py b/os_brick/tests/initiator/connectors/test_iscsi.py index 5bb76c019..d9e2c7908 100644 --- a/os_brick/tests/initiator/connectors/test_iscsi.py +++ b/os_brick/tests/initiator/connectors/test_iscsi.py @@ -1211,6 +1211,42 @@ Setting up iSCSI targets: unused self.assertGreaterEqual(find_dm_mock.call_count, 2) self.assertEqual(4, connect_mock.call_count) + @mock.patch.object(linuxscsi.LinuxSCSI, 'find_sysfs_multipath_dm', + side_effect=[None, 'dm-0']) + @mock.patch.object(linuxscsi.LinuxSCSI, 'get_sysfs_wwn', return_value='') + @mock.patch.object(linuxscsi.LinuxSCSI, 'multipath_add_path') + @mock.patch.object(linuxscsi.LinuxSCSI, 'multipath_add_wwid') + @mock.patch.object(iscsi.ISCSIConnector, '_connect_vol') + @mock.patch('os_brick.utils._time_sleep') + def test_connect_multipath_volume_no_wwid(self, sleep_mock, connect_mock, + add_wwid_mock, add_path_mock, + get_wwn_mock, find_dm_mock): + # Even if we don't have the wwn we'll be able to find the multipath + def my_connect(rescans, props, data): + devs = {'tgt1': 'sda', 'tgt2': 'sdb', 'tgt3': 'sdc', 'tgt4': 'sdd'} + data['stopped_threads'] += 1 + data['num_logins'] += 1 + dev = devs[props['target_iqn']] + data['found_devices'].append(dev) + data['just_added_devices'].append(dev) + + connect_mock.side_effect = my_connect + + res = self.connector._connect_multipath_volume(self.CON_PROPS) + + expected = {'type': 'block', 'scsi_wwn': '', 'multipath_id': '', + 'path': '/dev/dm-0'} + self.assertEqual(expected, res) + + self.assertEqual(2, get_wwn_mock.call_count) + result = list(get_wwn_mock.call_args[0][0]) + result.sort() + self.assertEqual(['sda', 'sdb', 'sdc', 'sdd'], result) + add_wwid_mock.assert_not_called() + add_path_mock.assert_not_called() + self.assertGreaterEqual(find_dm_mock.call_count, 2) + self.assertEqual(4, connect_mock.call_count) + @mock.patch.object(linuxscsi.LinuxSCSI, 'find_sysfs_multipath_dm', side_effect=[None, 'dm-0']) @mock.patch.object(linuxscsi.LinuxSCSI, 'get_sysfs_wwn', diff --git a/releasenotes/notes/improve-iscsi-multipath-detection-f36f28a993f61936.yaml b/releasenotes/notes/improve-iscsi-multipath-detection-f36f28a993f61936.yaml new file mode 100644 index 000000000..f67bd0f23 --- /dev/null +++ b/releasenotes/notes/improve-iscsi-multipath-detection-f36f28a993f61936.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Improve iSCSI multipath detection to work even if we cannot find the + volume's WWN in sysfs. + (bug 1881619).