Dell EMC SC: Find volume folder API call fails on root folders

Changes to the SC API have changed how calls are made to the
StorageCenter/ScVolumeFolder/GetList payload filter options. In
the case of a folder under root this call could fail depending on
the API.

Change-Id: I2ab2160478d2163dbb45175aa5f1b884f316db24
This commit is contained in:
Tom Swanson 2018-01-26 11:42:48 -06:00 committed by James E. Blair
parent 976415fbdd
commit c9a7fb8da5
2 changed files with 56 additions and 2 deletions

View File

@ -1924,6 +1924,58 @@ class DellSCSanAPITestCase(test.TestCase):
self.assertTrue(mock_get_result.called)
self.scapi.legacyfoldernames = True
@mock.patch.object(storagecenter_api.SCApi,
'_get_result')
@mock.patch.object(storagecenter_api.HttpClient,
'post',
return_value=RESPONSE_200)
def test_find_folder_legacy_root(self,
mock_post,
mock_get_result,
mock_close_connection,
mock_open_connection,
mock_init):
self.scapi._find_folder('StorageCenter/ScVolumeFolder/GetList',
'devstackvol', 12345)
expected_payload = {'filter': {'filterType': 'AND', 'filters': [
{'filterType': 'Equals', 'attributeName': 'scSerialNumber',
'attributeValue': 12345},
{'filterType': 'Equals', 'attributeName': 'Name',
'attributeValue': 'devstackvol'},
{'filterType': 'Equals', 'attributeName': 'folderPath',
'attributeValue': ''}]}}
mock_post.assert_called_once_with(
'StorageCenter/ScVolumeFolder/GetList',
expected_payload)
self.assertTrue(mock_get_result.called)
@mock.patch.object(storagecenter_api.SCApi,
'_get_result')
@mock.patch.object(storagecenter_api.HttpClient,
'post',
return_value=RESPONSE_200)
def test_find_folder_non_legacy_root(self,
mock_post,
mock_get_result,
mock_close_connection,
mock_open_connection,
mock_init):
self.scapi.legacyfoldernames = False
self.scapi._find_folder('StorageCenter/ScVolumeFolder/GetList',
'devstackvol', 12345)
expected_payload = {'filter': {'filterType': 'AND', 'filters': [
{'filterType': 'Equals', 'attributeName': 'scSerialNumber',
'attributeValue': 12345},
{'filterType': 'Equals', 'attributeName': 'Name',
'attributeValue': 'devstackvol'},
{'filterType': 'Equals', 'attributeName': 'folderPath',
'attributeValue': '/'}]}}
mock_post.assert_called_once_with(
'StorageCenter/ScVolumeFolder/GetList',
expected_payload)
self.assertTrue(mock_get_result.called)
self.scapi.legacyfoldernames = True
@mock.patch.object(storagecenter_api.SCApi,
'_get_result',
return_value=u'devstackvol/fcvm/')

View File

@ -816,14 +816,16 @@ class SCApi(object):
# save the user from themselves.
folderpath = foldername.strip('/')
folderpath = os.path.dirname(folderpath)
# If we have any kind of path we throw it into the filters.
# Put our path into the filters
if folderpath != '':
# Legacy didn't begin with a slash.
if not self.legacyfoldernames:
folderpath = '/' + folderpath
# SC convention is to end with a '/' so make sure we do.
folderpath += '/'
pf.append('folderPath', folderpath)
elif not self.legacyfoldernames:
folderpath = '/'
pf.append('folderPath', folderpath)
folder = None
r = self.client.post(url, pf.payload)
if self._check_result(r):