From 3be220539a529572f30f3345fe80f2aa572730a3 Mon Sep 17 00:00:00 2001 From: zhangchao010 Date: Wed, 25 Sep 2013 23:31:04 +0800 Subject: [PATCH] Fix Huawei HVS driver attaching volume error 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 | 3 +++ cinder/volume/drivers/huawei/rest_common.py | 22 +++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/cinder/tests/test_huawei_hvs.py b/cinder/tests/test_huawei_hvs.py index 7b1a45c2c..ad9dcea1a 100644 --- a/cinder/tests/test_huawei_hvs.py +++ b/cinder/tests/test_huawei_hvs.py @@ -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: diff --git a/cinder/volume/drivers/huawei/rest_common.py b/cinder/volume/drivers/huawei/rest_common.py index 4ef284280..b69e4917a 100644 --- a/cinder/volume/drivers/huawei/rest_common.py +++ b/cinder/volume/drivers/huawei/rest_common.py @@ -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.""" -- 2.45.2