From 36f12c05a75950f8214b5504c972b98edc63cdd7 Mon Sep 17 00:00:00 2001 From: Vladislav Belogrudov Date: Thu, 30 Sep 2021 12:40:25 +0300 Subject: [PATCH] Fix paths for NVMe devices (non-nguid) Fixed regression introduced by https://review.opendev.org/c/openstack/os-brick/+/800014, where connect_volume method returned a list with a single path instead of just the path. Closes-Bug: #1945323 Change-Id: I5e5b13dd73ab8d30439de76dd73eb41b763e7f05 (cherry picked from commit dd90bb6356d05a7b12198e77418befc1acc87c11) --- os_brick/initiator/connectors/nvmeof.py | 16 ++++++++-------- .../tests/initiator/connectors/test_nvmeof.py | 17 +++++++++++++++++ .../notes/bug-1945323-4140f5aff3558082.yaml | 6 ++++++ 3 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 releasenotes/notes/bug-1945323-4140f5aff3558082.yaml diff --git a/os_brick/initiator/connectors/nvmeof.py b/os_brick/initiator/connectors/nvmeof.py index 154b42337..26a885c17 100644 --- a/os_brick/initiator/connectors/nvmeof.py +++ b/os_brick/initiator/connectors/nvmeof.py @@ -194,7 +194,7 @@ class NVMeOFConnector(base.BaseLinuxConnector): path = set(all_nvme_devices) - set(current_nvme_devices) if not path: raise exception.VolumePathsNotFound() - return list(path) + return list(path)[0] @utils.retry(exception.VolumeDeviceNotFound) def _get_device_path_by_nguid(self, nguid): @@ -205,14 +205,14 @@ class NVMeOFConnector(base.BaseLinuxConnector): LOG.debug("Try to retrieve symlink to %(device_path)s.", {"device_path": device_path}) try: - paths, _err = self._execute('readlink', - '-e', - device_path, - run_as_root=True, - root_helper=self._root_helper) - if not paths: + path, _err = self._execute('readlink', + '-e', + device_path, + run_as_root=True, + root_helper=self._root_helper) + if not path: raise exception.VolumePathsNotFound() - return paths.split()[0] + return path.rstrip() except putils.ProcessExecutionError as e: LOG.exception(e) raise exception.VolumeDeviceNotFound(device=device_path) diff --git a/os_brick/tests/initiator/connectors/test_nvmeof.py b/os_brick/tests/initiator/connectors/test_nvmeof.py index 8731b897c..4ddd2208d 100644 --- a/os_brick/tests/initiator/connectors/test_nvmeof.py +++ b/os_brick/tests/initiator/connectors/test_nvmeof.py @@ -214,6 +214,23 @@ class NVMeOFConnectorTestCase(test_connector.ConnectorTestCase): root_helper=None, run_as_root=True) + @mock.patch.object(nvmeof.NVMeOFConnector, '_get_nvme_devices') + def test__get_device_path(self, mock_nvme_devices): + mock_nvme_devices.return_value = ['/dev/nvme0n1', + '/dev/nvme1n1', + '/dev/nvme0n2'] + current_devices = ['/dev/nvme0n1', '/dev/nvme0n2'] + self.assertEqual(self.connector._get_device_path(current_devices), + '/dev/nvme1n1') + + @mock.patch.object(nvmeof.NVMeOFConnector, '_get_nvme_devices') + def test__get_device_path_no_new_device(self, mock_nvme_devices): + current_devices = ['/dev/nvme0n1', '/dev/nvme0n2'] + mock_nvme_devices.return_value = current_devices + self.assertRaises(exception.VolumePathsNotFound, + self.connector._get_device_path, + current_devices) + @mock.patch.object(nvmeof.NVMeOFConnector, '_execute', autospec=True) def test__get_device_path_by_nguid(self, mock_execute): mock_execute.return_value = '/dev/nvme0n1\n', None diff --git a/releasenotes/notes/bug-1945323-4140f5aff3558082.yaml b/releasenotes/notes/bug-1945323-4140f5aff3558082.yaml new file mode 100644 index 000000000..d59305671 --- /dev/null +++ b/releasenotes/notes/bug-1945323-4140f5aff3558082.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + NVMe-oF connector `bug #1945323 + `_ [bugs.launchpad.net]: Fixed a regression + where connect_volume returned a list with a single path instead of just the path