Merge "Huawei driver handle volume exists error"
This commit is contained in:
commit
a2259f7c6c
@ -230,7 +230,7 @@ FAKE_LUN_INFO_RESPONSE = """
|
||||
}
|
||||
"""
|
||||
|
||||
FAKE_LUN_DELETE_SUCCESS_RESPONSE = """
|
||||
FAKE_LUN_GET_SUCCESS_RESPONSE = """
|
||||
{
|
||||
"error": {
|
||||
"code": 0
|
||||
@ -265,7 +265,7 @@ FAKE_QUERY_ALL_LUN_RESPONSE = """
|
||||
"code": 0
|
||||
},
|
||||
"data": [{
|
||||
"ID": "1",
|
||||
"ID": "11",
|
||||
"NAME": "IexzQZJWSXuX2e9I7c8GNQ"
|
||||
}]
|
||||
}
|
||||
@ -970,10 +970,10 @@ MAP_COMMAND_TO_FAKE_RESPONSE['/lun'] = (
|
||||
FAKE_LUN_INFO_RESPONSE)
|
||||
|
||||
MAP_COMMAND_TO_FAKE_RESPONSE['/lun/11/GET'] = (
|
||||
FAKE_LUN_DELETE_SUCCESS_RESPONSE)
|
||||
FAKE_LUN_GET_SUCCESS_RESPONSE)
|
||||
|
||||
MAP_COMMAND_TO_FAKE_RESPONSE['/lun/1/GET'] = (
|
||||
FAKE_LUN_DELETE_SUCCESS_RESPONSE)
|
||||
FAKE_LUN_GET_SUCCESS_RESPONSE)
|
||||
|
||||
MAP_COMMAND_TO_FAKE_RESPONSE['/lun/11/DELETE'] = (
|
||||
FAKE_COMMON_SUCCESS_RESPONSE)
|
||||
@ -1072,7 +1072,7 @@ MAP_COMMAND_TO_FAKE_RESPONSE['/snapshot?range=[0-32767]/GET'] = (
|
||||
|
||||
# mock QoS info map
|
||||
MAP_COMMAND_TO_FAKE_RESPONSE['/ioclass/11/GET'] = (
|
||||
FAKE_LUN_DELETE_SUCCESS_RESPONSE)
|
||||
FAKE_LUN_GET_SUCCESS_RESPONSE)
|
||||
|
||||
MAP_COMMAND_TO_FAKE_RESPONSE['/ioclass/11/DELETE'] = (
|
||||
FAKE_COMMON_SUCCESS_RESPONSE)
|
||||
@ -1722,6 +1722,27 @@ class Huawei18000ISCSIDriverTestCase(test.TestCase):
|
||||
(qos_id, lun_list) = self.driver.restclient.find_available_qos(qos)
|
||||
self.assertEqual(("11", u'["0", "1", "2"]'), (qos_id, lun_list))
|
||||
|
||||
@mock.patch.object(rest_client.RestClient, 'get_volume_by_name',
|
||||
return_value='11')
|
||||
@mock.patch.object(rest_client.RestClient, 'get_lun_info',
|
||||
return_value={'ID': '11'})
|
||||
def test_create_volume_exist(self, mock_lun_info, mock_volume_info):
|
||||
self.driver.restclient.login()
|
||||
lun_param = {'NAME': 'IexzQZJWSXuX2e9I7c8GNQ'}
|
||||
|
||||
fack_error_volume_exist = {"error": {"code": 1077948993}}
|
||||
with mock.patch.object(rest_client.RestClient, 'call',
|
||||
return_value=fack_error_volume_exist):
|
||||
lun_info = self.driver.restclient.create_volume(lun_param)
|
||||
self.assertEqual('11', lun_info['ID'])
|
||||
|
||||
fack_error_volume_exist = {"error": {"code": 123456789}}
|
||||
with mock.patch.object(rest_client.RestClient, 'call',
|
||||
return_value=fack_error_volume_exist):
|
||||
self.assertRaises(exception.VolumeBackendAPIException,
|
||||
self.driver.restclient.create_volume,
|
||||
lun_param)
|
||||
|
||||
def create_fake_conf_file(self):
|
||||
"""Create a fake Config file.
|
||||
|
||||
|
@ -40,6 +40,7 @@ MIGRATION_COMPLETE = '76'
|
||||
ERROR_CONNECT_TO_SERVER = -403
|
||||
ERROR_UNAUTHORIZED_TO_SERVER = -401
|
||||
SOCKET_TIMEOUT = 52
|
||||
ERROR_VOLUME_ALREADY_EXIST = 1077948993
|
||||
LOGIN_SOCKET_TIMEOUT = 4
|
||||
|
||||
THICK_LUNTYPE = 0
|
||||
|
@ -168,6 +168,10 @@ class RestClient(object):
|
||||
url = "/lun"
|
||||
data = json.dumps(lun_param)
|
||||
result = self.call(url, data)
|
||||
if result['error']['code'] == constants.ERROR_VOLUME_ALREADY_EXIST:
|
||||
lun_id = self.get_volume_by_name(lun_param["NAME"])
|
||||
if lun_id:
|
||||
return self.get_lun_info(lun_id)
|
||||
|
||||
msg = _('Create volume error.')
|
||||
self._assert_rest_result(result, msg)
|
||||
|
Loading…
Reference in New Issue
Block a user