Merge "StorageCenter: Fix volume mapping for API v3.1"

This commit is contained in:
Zuul 2017-12-23 18:26:26 +00:00 committed by Gerrit Code Review
commit 016431808c
2 changed files with 32 additions and 14 deletions

View File

@ -1322,7 +1322,7 @@ class DellSCSanAPITestCase(test.TestCase):
u'objectType': u'ScControllerPort'},
u'status': u'Up',
u'iscsiIpAddress': u'0.0.0.0',
u'Wwn': u'5000D31000FCBE36',
u'wWN': u'5000D31000FCBE36',
u'name': u'5000D31000FCBE36',
u'parent':
{u'instanceId': u'64702.5764839588723736093.57',
@ -3413,24 +3413,29 @@ class DellSCSanAPITestCase(test.TestCase):
@mock.patch.object(storagecenter_api.SCApi,
'_find_initiators',
return_value=WWNS)
def test_find_wwns_wwn_error(self,
mock_find_initiators,
mock_find_mappings,
mock_find_controller_port,
mock_close_connection,
mock_open_connection,
mock_init):
# Test case where ScControllerPort object has WWn instead of wwn for a
# property
def test_find_wwns_wwn_resilient(self,
mock_find_initiators,
mock_find_mappings,
mock_find_controller_port,
mock_close_connection,
mock_open_connection,
mock_init):
# Test case where ScControllerPort object has wWN instead of wwn (as
# seen in some cases) for a property but we are still able to find it.
lun, wwns, itmap = self.scapi.find_wwns(self.VOLUME,
self.SCSERVER)
self.assertTrue(mock_find_initiators.called)
self.assertTrue(mock_find_mappings.called)
self.assertTrue(mock_find_controller_port.called)
self.assertIsNone(lun, 'Incorrect LUN')
self.assertEqual([], wwns, 'WWNs is not empty')
self.assertEqual({}, itmap, 'WWN mapping not empty')
self.assertEqual(1, lun, 'Incorrect LUN')
expected_wwn = ['5000D31000FCBE36', '5000D31000FCBE36',
'5000D31000FCBE36']
self.assertEqual(expected_wwn, wwns, 'WWNs incorrect')
expected_itmap = {'21000024FF30441C': ['5000D31000FCBE36'],
'21000024FF30441D': ['5000D31000FCBE36',
'5000D31000FCBE36']}
self.assertEqual(expected_itmap, itmap, 'WWN mapping incorrect')
@mock.patch.object(storagecenter_api.SCApi,
'_find_controller_port',

View File

@ -1618,6 +1618,19 @@ class SCApi(object):
LOG.debug('_find_controller_port: %s', controllerport)
return controllerport
@staticmethod
def _get_wwn(controllerport):
"""Return the WWN value of the controller port.
Usually the WWN key in the controller port is wwn or WWN, but there
are cases where the backend returns wWW, so we have to check all the
keys.
"""
for key, value in controllerport.items():
if key.lower() == 'wwn':
return value
return None
def find_wwns(self, scvolume, scserver):
"""Finds the lun and wwns of the mapped volume.
@ -1643,7 +1656,7 @@ class SCApi(object):
if controllerport is not None:
# This changed case at one point or another.
# Look for both keys.
wwn = controllerport.get('wwn', controllerport.get('WWN'))
wwn = self._get_wwn(controllerport)
if wwn:
serverhba = mapping.get('serverHba')
if serverhba: