From c9a7fb8da533251772b79140c7161b393c52f15b Mon Sep 17 00:00:00 2001 From: Tom Swanson Date: Fri, 26 Jan 2018 11:42:48 -0600 Subject: [PATCH] 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 --- .../volume/drivers/dell_emc/sc/test_scapi.py | 52 +++++++++++++++++++ .../drivers/dell_emc/sc/storagecenter_api.py | 6 ++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/cinder/tests/unit/volume/drivers/dell_emc/sc/test_scapi.py b/cinder/tests/unit/volume/drivers/dell_emc/sc/test_scapi.py index cefa900a97b..c00a6f1389d 100644 --- a/cinder/tests/unit/volume/drivers/dell_emc/sc/test_scapi.py +++ b/cinder/tests/unit/volume/drivers/dell_emc/sc/test_scapi.py @@ -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/') diff --git a/cinder/volume/drivers/dell_emc/sc/storagecenter_api.py b/cinder/volume/drivers/dell_emc/sc/storagecenter_api.py index 859a7021bb5..547757df2ca 100644 --- a/cinder/volume/drivers/dell_emc/sc/storagecenter_api.py +++ b/cinder/volume/drivers/dell_emc/sc/storagecenter_api.py @@ -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):