Merge "Dell EMC SC: Delete doesn't account for migration"

This commit is contained in:
Jenkins 2017-01-31 04:06:15 +00:00 committed by Gerrit Code Review
commit 33e745d49c
4 changed files with 46 additions and 11 deletions

View File

@ -768,6 +768,27 @@ class DellSCSanISCSIDriverTestCase(test.TestCase):
self.assertTrue(mock_delete_replications.called)
self.assertEqual(2, mock_delete_replications.call_count)
@mock.patch.object(dell_storagecenter_iscsi.DellStorageCenterISCSIDriver,
'_delete_replications')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'delete_volume',
return_value=True)
@mock.patch.object(dell_storagecenter_iscsi.DellStorageCenterISCSIDriver,
'_get_replication_specs',
return_value={'enabled': True,
'live': False})
def test_delete_volume_migrating(self,
mock_get_replication_specs,
mock_delete_volume,
mock_delete_replications,
mock_close_connection,
mock_open_connection,
mock_init):
volume = {'id': fake.VOLUME_ID, '_name_id': fake.VOLUME2_ID,
'provider_id': '12345.100', 'migration_status': 'deleting'}
self.driver.delete_volume(volume)
mock_delete_volume.assert_called_once_with(fake.VOLUME2_ID, None)
@mock.patch.object(dell_storagecenter_iscsi.DellStorageCenterISCSIDriver,
'_delete_live_volume')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,

View File

@ -2564,10 +2564,10 @@ class DellSCSanAPITestCase(test.TestCase):
'delete',
return_value=RESPONSE_200)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_search_for_volume',
'find_volume',
return_value=VOLUME)
def test_delete_volume(self,
mock_search_for_volume,
mock_find_volume,
mock_delete,
mock_get_json,
mock_close_connection,
@ -2575,7 +2575,7 @@ class DellSCSanAPITestCase(test.TestCase):
mock_init):
res = self.scapi.delete_volume(self.volume_name)
self.assertTrue(mock_delete.called)
mock_search_for_volume.assert_called_once_with(self.volume_name)
mock_find_volume.assert_called_once_with(self.volume_name, None)
self.assertTrue(mock_get_json.called)
self.assertTrue(res)
@ -2585,7 +2585,11 @@ class DellSCSanAPITestCase(test.TestCase):
@mock.patch.object(dell_storagecenter_api.HttpClient,
'delete',
return_value=RESPONSE_200)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'find_volume',
return_value=VOLUME)
def test_delete_volume_with_provider_id(self,
mock_find_volume,
mock_delete,
mock_get_json,
mock_close_connection,
@ -2593,6 +2597,7 @@ class DellSCSanAPITestCase(test.TestCase):
mock_init):
provider_id = str(self.scapi.ssn) + '.1'
res = self.scapi.delete_volume(self.volume_name, provider_id)
mock_find_volume.assert_called_once_with(self.volume_name, provider_id)
self.assertTrue(mock_delete.called)
self.assertTrue(mock_get_json.called)
self.assertTrue(res)
@ -2600,7 +2605,11 @@ class DellSCSanAPITestCase(test.TestCase):
@mock.patch.object(dell_storagecenter_api.HttpClient,
'delete',
return_value=RESPONSE_400)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'find_volume',
return_value=VOLUME)
def test_delete_volume_failure(self,
mock_find_volume,
mock_delete,
mock_close_connection,
mock_open_connection,
@ -2609,18 +2618,19 @@ class DellSCSanAPITestCase(test.TestCase):
self.assertRaises(exception.VolumeBackendAPIException,
self.scapi.delete_volume, self.volume_name,
provider_id)
mock_find_volume.assert_called_once_with(self.volume_name, provider_id)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_search_for_volume',
'find_volume',
return_value=None)
def test_delete_volume_no_vol_found(self,
mock_search_for_volume,
mock_find_volume,
mock_close_connection,
mock_open_connection,
mock_init):
# Test case where volume to be deleted does not exist
res = self.scapi.delete_volume(self.volume_name, None)
mock_search_for_volume.assert_called_once_with(self.volume_name)
mock_find_volume.assert_called_once_with(self.volume_name, None)
self.assertTrue(res, 'Expected True')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,

View File

@ -1292,11 +1292,8 @@ class StorageCenterApi(object):
:param provider_id: This is the instanceId
:returns: Boolean indicating success or failure.
"""
# No provider id? Then do a search.
if not provider_id:
vol = self._search_for_volume(name)
if vol:
provider_id = self._get_id(vol)
vol = self.find_volume(name, provider_id)
provider_id = None if not vol else self._get_id(vol)
# If we have an id then delete the volume.
if provider_id:

View File

@ -421,6 +421,11 @@ class DellCommonDriver(driver.ManageableVD,
# We use id as our name as it is unique.
volume_name = volume.get('id')
provider_id = volume.get('provider_id')
# Unless we are migrating.
if volume.get('migration_status') == 'deleting':
volume_name = volume.get('_name_id')
provider_id = None
LOG.debug('Deleting volume %s', volume_name)
with self._client.open_connection() as api:
try:
@ -762,6 +767,8 @@ class DellCommonDriver(driver.ManageableVD,
'original': original_volume_name})
if original_volume_name:
with self._client.open_connection() as api:
# todo(tswanson): Delete old volume repliations/live volumes
# todo(tswanson): delete old volume?
scvolume = api.find_volume(current_name, provider_id)
if (scvolume and
api.rename_volume(scvolume, original_volume_name)):