From 071b541efd2287ef2c88d37126c1a6fe6b79e84b Mon Sep 17 00:00:00 2001 From: Anthony Lee <anthony.mic.lee@hpe.com> Date: Fri, 4 Mar 2016 20:19:18 -0800 Subject: [PATCH] Fixes get_all_available_volumes return value There was a case where the InitiatorConnector's get_all_available_volumes function was returning None instead of an empty list. It was happening when the search path did not exist on the system. This patch changes the logic so that by default an empty list is always returned. Closes-Bug: #1553445 Change-Id: I180a9280d3b1f2f645d7240129f00755d17958a2 --- os_brick/initiator/connector.py | 7 ++++--- os_brick/tests/initiator/test_connector.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/os_brick/initiator/connector.py b/os_brick/initiator/connector.py index 5a96a7187..84c8f807c 100644 --- a/os_brick/initiator/connector.py +++ b/os_brick/initiator/connector.py @@ -464,15 +464,16 @@ class InitiatorConnector(executor.Executor): of the target volume attributes. :type connection_properties: dict """ + volumes = [] path = self.get_search_path() if path: # now find all entries in the search path if os.path.isdir(path): path_items = [path, '/*'] file_filter = ''.join(path_items) - return glob.glob(file_filter) - else: - return [] + volumes = glob.glob(file_filter) + + return volumes def check_IO_handle_valid(self, handle, data_type, protocol): """Check IO handle has correct data type.""" diff --git a/os_brick/tests/initiator/test_connector.py b/os_brick/tests/initiator/test_connector.py index 8ce1a40df..0b2f8551f 100644 --- a/os_brick/tests/initiator/test_connector.py +++ b/os_brick/tests/initiator/test_connector.py @@ -1143,6 +1143,13 @@ Setting up iSCSI targets: unused new_size = self.connector.extend_volume(connection_info['data']) self.assertEqual(fake_new_size, new_size) + @mock.patch.object(os.path, 'isdir') + def test_get_all_available_volumes_path_not_dir(self, mock_isdir): + mock_isdir.return_value = False + expected = [] + actual = self.connector.get_all_available_volumes() + self.assertItemsEqual(expected, actual) + class FibreChannelConnectorTestCase(ConnectorTestCase): def setUp(self): @@ -1494,6 +1501,13 @@ class FibreChannelConnectorTestCase(ConnectorTestCase): new_size = self.connector.extend_volume(connection_info['data']) self.assertEqual(fake_new_size, new_size) + @mock.patch.object(os.path, 'isdir') + def test_get_all_available_volumes_path_not_dir(self, mock_isdir): + mock_isdir.return_value = False + expected = [] + actual = self.connector.get_all_available_volumes() + self.assertItemsEqual(expected, actual) + class FibreChannelConnectorS390XTestCase(ConnectorTestCase):