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
This commit is contained in:
Anthony Lee 2016-03-04 20:19:18 -08:00
parent cdc25318a8
commit 071b541efd
2 changed files with 18 additions and 3 deletions
os_brick
initiator
tests/initiator

@ -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."""

@ -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):