Skip to content

Commit

Permalink
Fix Huawei HVS driver attaching volume error
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zhangchao010 authored and openstack-gerrit committed Sep 29, 2013
1 parent 59cb2be commit 3be2205
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
3 changes: 3 additions & 0 deletions cinder/tests/test_huawei_hvs.py
Expand Up @@ -331,6 +331,9 @@ def call(self, url=False, data=None, method=None):
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:
Expand Down
22 changes: 12 additions & 10 deletions cinder/volume/drivers/huawei/rest_common.py
Expand Up @@ -758,29 +758,31 @@ def _delete_associated_lun_from_lungroup(self, lungroupid, lunid):

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."""
Expand Down

0 comments on commit 3be2205

Please sign in to comment.