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 858d0c877a8..7adef002d87 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 @@ -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', diff --git a/cinder/volume/drivers/dell_emc/sc/storagecenter_api.py b/cinder/volume/drivers/dell_emc/sc/storagecenter_api.py index 371955c7bac..07fb8c72001 100644 --- a/cinder/volume/drivers/dell_emc/sc/storagecenter_api.py +++ b/cinder/volume/drivers/dell_emc/sc/storagecenter_api.py @@ -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: