]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Huawei driver handle volume exists error
authorWilson Liu <liuxinguo@huawei.com>
Sat, 10 Oct 2015 03:37:04 +0000 (11:37 +0800)
committerWilson Liu <liuxinguo@huawei.com>
Tue, 13 Oct 2015 08:09:05 +0000 (16:09 +0800)
Currently when we create a volume on an array
where that volume already exists,
there will be an exception. But in fact it should
just go on and doesn't need an exception.

Closes-Bug: #1504718
Change-Id: I13a52e81c1c271ea6728cb4a23717609d95bae69

cinder/tests/unit/test_huawei_drivers.py
cinder/volume/drivers/huawei/constants.py
cinder/volume/drivers/huawei/rest_client.py

index 4a53a3913b54e09aab6ead806f03cc63023b21f2..e79426891736c2d95c5772eb7ee8db4556c2d5df 100644 (file)
@@ -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.
 
index 4e3eb5cd78d3ae814b319adffe24d2dbed864e37..47f59a566b943dd7456dda23a145ad86f2e32727 100644 (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
index 6a94a77995c8eadd896e15bbe5ee9221bc674275..c956e1c07caeb6e50075d81b8369776264cd3aec 100644 (file)
@@ -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)