]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix Huawei HVS driver attaching volume error
authorzhangchao010 <zhangchao010@huawei.com>
Wed, 25 Sep 2013 15:31:04 +0000 (23:31 +0800)
committerGerrit Code Review <review@openstack.org>
Sun, 29 Sep 2013 17:54:56 +0000 (17:54 +0000)
If iSCSI initiator is not added to host, we will get https errors
for we find the initiator info by sending url with this initiator name.

This patch fixes the way of getting the initiator info.
First, get the all initiator info.
Then, find the one we need by name.

Closes-bug: #1230296
Change-Id: I92620374923fa136ee71fe6eb3af6e4c78a3d66b

cinder/tests/test_huawei_hvs.py
cinder/volume/drivers/huawei/rest_common.py

index 7b1a45c2c9b8502adb31fc567dfc5ddbc4c02372..ad9dcea1a60f69a18b4274e429581a2555bc6afb 100644 (file)
@@ -331,6 +331,9 @@ class FakeHVSCommon(rest_common.HVSCommon):
             if url == "iscsi_initiator/":
                 data = """{"error":{"code":0}}"""
 
+            if url == "iscsi_initiator":
+                data = """{"error":{"code":0}}"""
+
             if url == "mappingview":
                 self.termin_flag = True
                 if method is None:
index 4ef284280f0e54a5d274b4f4da7942b3d1788ab0..b69e4917ab616467d2d16c28b15d9fe6c168066e 100644 (file)
@@ -758,29 +758,31 @@ class HVSCommon():
 
     def _initiator_is_added_to_array(self, ininame):
         """Check whether the initiator is already added in array."""
-        url = self.url + "/iscsi_initiator/" + ininame
+        url = self.url + "/iscsi_initiator"
         data = json.dumps({"TYPE": "222", "ID": ininame})
         result = self.call(url, data, "GET")
         self._assert_rest_result(result,
                                  'Check initiator added to array error.')
 
-        if "data" in result and result['data']['ID']:
-            return True
-        else:
-            return False
+        if "data" in result:
+            for item in result['data']:
+                if item["ID"] == ininame:
+                    return True
+        return False
 
     def _is_initiator_associated_to_host(self, ininame):
         """Check whether the initiator is associated to the host."""
-        url = self.url + "/iscsi_initiator/" + ininame
+        url = self.url + "/iscsi_initiator"
         data = json.dumps({"TYPE": "222", "ID": ininame})
         result = self.call(url, data, "GET")
         self._assert_rest_result(result,
                                  'Check initiator associated to host error.')
 
-        if "data" in result and result['data']['ISFREE'] == "true":
-            return True
-        else:
-            return False
+        if "data" in result:
+            for item in result['data']:
+                if item['ID'] == ininame and item['ISFREE'] == "true":
+                    return False
+        return True
 
     def _add_initiator_to_array(self, ininame):
         """Add a new initiator to storage device."""