Dell EMC SC: Added retry to _init_volume

To initialize a SC volume we quickly map and unmap the volume to
a scserver object. _init_volume currently tries to activate a
volume one time. If this fails we should retry until it works or
we run out of scserver objects to try.

Closes-Bug: #1672768
Change-Id: I383980a8241ec871313e6e7d7157f7af264fc5b6
This commit is contained in:
Tom Swanson 2017-03-09 11:50:06 -06:00
parent 7e846f1bac
commit 7a2f920f7d
2 changed files with 46 additions and 9 deletions

View File

@ -2054,6 +2054,40 @@ class DellSCSanAPITestCase(test.TestCase):
self.assertTrue(mock_map_volume.called)
self.assertTrue(mock_unmap_volume.called)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'get_volume')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'unmap_volume')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'map_volume',
return_value=MAPPINGS)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_get_json')
@mock.patch.object(dell_storagecenter_api.HttpClient,
'post',
return_value=RESPONSE_200)
def test_init_volume_retry(self,
mock_post,
mock_get_json,
mock_map_volume,
mock_unmap_volume,
mock_get_volume,
mock_close_connection,
mock_open_connection,
mock_init):
mock_get_json.return_value = [{'name': 'srv1', 'status': 'up',
'type': 'physical'},
{'name': 'srv2', 'status': 'up',
'type': 'physical'}]
mock_get_volume.side_effect = [{'name': 'guid', 'active': False,
'instanceId': '12345.1'},
{'name': 'guid', 'active': True,
'instanceId': '12345.1'}]
self.scapi._init_volume(self.VOLUME)
# First return wasn't active. So try second.
self.assertEqual(2, mock_map_volume.call_count)
self.assertEqual(2, mock_unmap_volume.call_count)
@mock.patch.object(dell_storagecenter_api.HttpClient,
'post',
return_value=RESPONSE_400)

View File

@ -862,14 +862,15 @@ class StorageCenterApi(object):
self.map_volume(scvolume, scserver)
# We have changed the volume so grab a new copy of it.
scvolume = self.get_volume(self._get_id(scvolume))
if not scvolume.get('active', False):
LOG.info(_LI('Failed to activate volume %(name)s, '
'operations such as snapshot and clone '
'may fail due to inactive volume. '
'(%(obj)r)'),
{'name': scvolume['name'],
'obj': scvolume})
# Unmap
self.unmap_volume(scvolume, scserver)
# Did it work?
if not scvolume.get('active', False):
LOG.debug('Failed to activate volume %(name)s via '
'server %(srvr)s)',
{'name': scvolume['name'],
'srvr': scserver['name']})
else:
return
# We didn't map/unmap the volume. So no initialization done.
# Warn the user before we leave. Note that this is almost certainly
@ -877,7 +878,9 @@ class StorageCenterApi(object):
# has likely been attempted before the volume has been instantiated
# on the Storage Center. In the real world no one will snapshot
# a volume without first putting some data in that volume.
LOG.warning(_LW('Volume %s initialization failure.'), scvolume['name'])
LOG.warning(_LW('Volume %(name)s initialization failure. '
'Operations such as snapshot and clone may fail due '
'to inactive volume.)'), {'name': scvolume['name']})
def _find_storage_profile(self, storage_profile):
"""Looks for a Storage Profile on the array.