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