StorageCenter: Fix volume mapping for API v3.1

Volume attachment fails on StorageCenter API v3.1 because the backend
instead of returning wwn or WWN as the key in the controller port it
returns wWN, thus preventing the driver from finding the mapping.

This patch adds support to any combination of upper and lower case of
the WWN key.

Closes-Bug: #1739651
Change-Id: Ie6ec59b4f6d31cb72e37f25f5347c815fee5af48
This commit is contained in:
Gorka Eguileor 2017-12-21 18:39:35 +01:00
parent 7bbc95344d
commit b50e08bcd8
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: