From c0f342167d037a51f84009725f3351ff5490d001 Mon Sep 17 00:00:00 2001 From: Wilson Liu Date: Wed, 23 Sep 2015 11:43:06 +0800 Subject: [PATCH] Fix URL format in Huawei driver Some of the URL format are not standard, this patch will fix them. Change-Id: I3caf49e6ca7f5f6f2caa1b56ba2dc2af2cafdcea Close-Bug: #1498484 --- cinder/tests/unit/test_huawei_drivers.py | 10 ++- cinder/volume/drivers/huawei/huawei_driver.py | 4 +- cinder/volume/drivers/huawei/huawei_utils.py | 2 +- cinder/volume/drivers/huawei/rest_client.py | 78 ++++++------------- 4 files changed, 35 insertions(+), 59 deletions(-) diff --git a/cinder/tests/unit/test_huawei_drivers.py b/cinder/tests/unit/test_huawei_drivers.py index 9794c4b93..17e919690 100644 --- a/cinder/tests/unit/test_huawei_drivers.py +++ b/cinder/tests/unit/test_huawei_drivers.py @@ -962,6 +962,7 @@ FAKE_GET_FC_PORT_RESPONSE = """ MAP_COMMAND_TO_FAKE_RESPONSE = {} MAP_COMMAND_TO_FAKE_RESPONSE['/xx/sessions'] = ( FAKE_GET_LOGIN_STORAGE_RESPONSE) + MAP_COMMAND_TO_FAKE_RESPONSE['/sessions'] = ( FAKE_LOGIN_OUT_STORAGE_RESPONSE) @@ -1112,8 +1113,8 @@ MAP_COMMAND_TO_FAKE_RESPONSE['/iscsidevicename'] = ( MAP_COMMAND_TO_FAKE_RESPONSE['/iscsi_initiator?range=[0-256]/GET'] = ( FAKE_COMMON_SUCCESS_RESPONSE) -MAP_COMMAND_TO_FAKE_RESPONSE['/iscsi_initiator'] = ( - FAKE_COMMON_SUCCESS_RESPONSE) +MAP_COMMAND_TO_FAKE_RESPONSE['/iscsi_initiator/'] = ( + FAKE_ISCSI_INITIATOR_RESPONSE) MAP_COMMAND_TO_FAKE_RESPONSE['/iscsi_initiator/POST'] = ( FAKE_ISCSI_INITIATOR_RESPONSE) @@ -1257,7 +1258,10 @@ MAP_COMMAND_TO_FAKE_RESPONSE['/fc_initiator/GET'] = ( MAP_COMMAND_TO_FAKE_RESPONSE['/lun/associate/cachepartition/POST'] = ( FAKE_SYSTEM_VERSION_RESPONSE) -MAP_COMMAND_TO_FAKE_RESPONSE['/fc_initiator?range=[0-100]/GET'] = ( +MAP_COMMAND_TO_FAKE_RESPONSE['/fc_initiator?range=[0-100]&PARENTID=1/GET'] = ( + FAKE_GET_FC_PORT_RESPONSE) + +MAP_COMMAND_TO_FAKE_RESPONSE['/fc_initiator?PARENTTYPE=21&PARENTID=1/GET'] = ( FAKE_GET_FC_PORT_RESPONSE) diff --git a/cinder/volume/drivers/huawei/huawei_driver.py b/cinder/volume/drivers/huawei/huawei_driver.py index c0d25b935..2a5d94aa2 100644 --- a/cinder/volume/drivers/huawei/huawei_driver.py +++ b/cinder/volume/drivers/huawei/huawei_driver.py @@ -868,7 +868,7 @@ class Huawei18000ISCSIDriver(HuaweiBaseDriver, driver.ISCSIDriver): lun_id = self.restclient.get_lunid(volume, volume_name) # Mapping lungroup and hostgroup to view. - self.restclient.do_mapping(volume_name, hostgroup_id, + self.restclient.do_mapping(lun_id, hostgroup_id, host_id, portgroup_id) hostlun_id = self.restclient.find_host_lun_id(host_id, lun_id) @@ -1085,7 +1085,7 @@ class Huawei18000FCDriver(HuaweiBaseDriver, driver.FibreChannelDriver): # Add host into hostgroup. hostgroup_id = self.restclient.add_host_into_hostgroup(host_id) - self.restclient.do_mapping(volume_name, hostgroup_id, host_id) + self.restclient.do_mapping(lun_id, hostgroup_id, host_id) host_lun_id = self.restclient.find_host_lun_id(host_id, lun_id) # Return FC properties. diff --git a/cinder/volume/drivers/huawei/huawei_utils.py b/cinder/volume/drivers/huawei/huawei_utils.py index 79b270cbf..a82f7da4e 100644 --- a/cinder/volume/drivers/huawei/huawei_utils.py +++ b/cinder/volume/drivers/huawei/huawei_utils.py @@ -487,7 +487,7 @@ def check_conf_file(xml_file_path): resturl = root.findtext('Storage/RestURL') username = root.findtext('Storage/UserName') pwd = root.findtext('Storage/UserPassword') - pool_node = root.findall('Storage/StoragePool') + pool_node = root.findall('LUN/StoragePool') if (not resturl) or (not username) or (not pwd): err_msg = (_( diff --git a/cinder/volume/drivers/huawei/rest_client.py b/cinder/volume/drivers/huawei/rest_client.py index b8e7ba8a6..f04814806 100644 --- a/cinder/volume/drivers/huawei/rest_client.py +++ b/cinder/volume/drivers/huawei/rest_client.py @@ -177,9 +177,7 @@ class RestClient(object): def check_lun_exist(self, lun_id): url = "/lun/" + lun_id - data = json.dumps({"TYPE": "11", - "ID": lun_id}) - result = self.call(url, data, "GET") + result = self.call(url, None, "GET") error_code = result['error']['code'] if error_code != 0: return False @@ -282,9 +280,7 @@ class RestClient(object): def check_snapshot_exist(self, snapshot_id): url = "/snapshot/%s" % snapshot_id - data = json.dumps({"TYPE": "27", - "ID": snapshot_id}) - result = self.call(url, data, "GET") + result = self.call(url, None, "GET") error_code = result['error']['code'] if error_code != 0: return False @@ -305,8 +301,7 @@ class RestClient(object): def get_snapshotid_by_name(self, name): url = "/snapshot?range=[0-32767]" - data = json.dumps({"TYPE": "27"}) - result = self.call(url, data, "GET") + result = self.call(url, None, "GET") self._assert_rest_result(result, _('Get snapshot id error.')) return self._get_id_from_result(result, name, 'NAME') @@ -368,9 +363,8 @@ class RestClient(object): 'view error.')) def _portgroup_associated(self, view_id, portgroup_id): - url_subfix = ("/mappingview/associate?TYPE=245&" - "ASSOCIATEOBJTYPE=257&ASSOCIATEOBJID=%s" % portgroup_id) - url = url_subfix + url = ("/mappingview/associate?TYPE=245&" + "ASSOCIATEOBJTYPE=257&ASSOCIATEOBJID=%s" % portgroup_id) result = self.call(url, None, "GET") self._assert_rest_result(result, _('Check portgroup associate error.')) @@ -579,8 +573,7 @@ class RestClient(object): def find_host(self, host_name): """Get the given host ID.""" url = "/host?range=[0-65535]" - data = json.dumps({"TYPE": "21"}) - result = self.call(url, data, "GET") + result = self.call(url, None, "GET") self._assert_rest_result(result, _('Find host in hostgroup error.')) return self._get_id_from_result(result, host_name, 'NAME') @@ -725,7 +718,7 @@ class RestClient(object): data = json.dumps({"TYPE": "222", "ID": initiator_name, "USECHAP": "false"}) - result = self.call(url, data) + result = self.call(url, data, "POST") self._assert_rest_result(result, _('Add initiator to array error.')) @@ -829,8 +822,7 @@ class RestClient(object): def find_mapping_view(self, name): """Find mapping view.""" url = "/mappingview?range=[0-8191]" - data = json.dumps({"TYPE": "245"}) - result = self.call(url, data, "GET") + result = self.call(url, None, "GET") msg = _('Find mapping view error.') self._assert_rest_result(result, msg) @@ -969,8 +961,7 @@ class RestClient(object): def get_luncopy_info(self, luncopy_id): """Get LUNcopy information.""" url = "/LUNCOPY?range=[0-1023]" - data = json.dumps({"TYPE": "219", }) - result = self.call(url, data, "GET") + result = self.call(url, None, "GET") self._assert_rest_result(result, _('Get LUNcopy information error.')) luncopyinfo = {} @@ -1099,7 +1090,7 @@ class RestClient(object): def update_volume_stats(self): root = huawei_utils.parse_xml_file(self.xml_file_path) - pool_names = root.findtext('Storage/StoragePool') + pool_names = root.findtext('LUN/StoragePool') if not pool_names: msg = _( 'Invalid resource pool name. ' @@ -1301,9 +1292,7 @@ class RestClient(object): def get_qos_info(self, qos_id): """Get QoS information.""" url = "/ioclass/" + qos_id - data = json.dumps({"TYPE": "230", - "ID": qos_id}) - result = self.call(url, data, "GET") + result = self.call(url, None, "GET") self._assert_rest_result(result, _('Get QoS information error.')) return result['data'] @@ -1357,10 +1346,7 @@ class RestClient(object): def get_qosid_by_lunid(self, lun_id): """Get QoS id by lun id.""" url = "/lun/" + lun_id - data = json.dumps({"TYPE": "11", - "ID": lun_id}) - - result = self.call(url, data, "GET") + result = self.call(url, None, "GET") self._assert_rest_result(result, _('Get QoS id by lun id error.')) return result['data']['IOCLASSID'] @@ -1382,9 +1368,7 @@ class RestClient(object): def get_lun_info(self, lun_id): url = "/lun/" + lun_id - data = json.dumps({"TYPE": "11", - "ID": lun_id}) - result = self.call(url, data, "GET") + result = self.call(url, None, "GET") msg = _('Get volume error.') self._assert_rest_result(result, msg) @@ -1443,10 +1427,7 @@ class RestClient(object): def get_partition_info_by_id(self, partition_id): url = '/cachepartition/' + partition_id - data = json.dumps({"TYPE": '268', - "ID": partition_id}) - - result = self.call(url, data, "GET") + result = self.call(url, None, "GET") self._assert_rest_result(result, _('Get partition by partition id error.')) @@ -1502,7 +1483,7 @@ class RestClient(object): """"Find available QoS on the array.""" qos_id = None lun_list = [] - url = "/ioclass?range=[0-100]" + url = "/ioclass" result = self.call(url, None, "GET") self._assert_rest_result(result, _('Get QoS information error.')) @@ -1584,10 +1565,8 @@ class RestClient(object): self._assert_rest_result(result, _('Remove iscsi from host error.')) def get_host_online_fc_initiators(self, host_id): - url = "/fc_initiator" - data = json.dumps({'PARENTTYPE': 21, - 'PARENTID': host_id}) - result = self.call(url, data, "GET") + url = "/fc_initiator?PARENTTYPE=21&PARENTID=%s" % host_id + result = self.call(url, None, "GET") initiators = [] if 'data' in result: @@ -1599,10 +1578,8 @@ class RestClient(object): return initiators def get_host_fc_initiators(self, host_id): - url = "/fc_initiator" - data = json.dumps({'PARENTTYPE': 21, - 'PARENTID': host_id}) - result = self.call(url, data, "GET") + url = "/fc_initiator?PARENTTYPE=21&PARENTID=%s" % host_id + result = self.call(url, None, "GET") initiators = [] if 'data' in result: @@ -1613,10 +1590,8 @@ class RestClient(object): return initiators def get_host_iscsi_initiators(self, host_id): - url = "/iscsi_initiator" - data = json.dumps({'PARENTTYPE': 21, - 'PARENTID': host_id}) - result = self.call(url, data, "GET") + url = "/iscsi_initiator?PARENTTYPE=21&PARENTID=%s" % host_id + result = self.call(url, None, "GET") initiators = [] if 'data' in result: @@ -1655,9 +1630,8 @@ class RestClient(object): self._assert_rest_result(result, _('Remove fc from host error.')) def check_fc_initiators_exist_in_host(self, host_id): - url = '/fc_initiator?range=[0-256]' - data = json.dumps({"PARENTID": host_id}) - result = self.call(url, data, "GET") + url = "/fc_initiator?range=[0-100]&PARENTID=%s" % host_id + result = self.call(url, None, "GET") self._assert_rest_result(result, _('Get host initiators info failed.')) if 'data' in result: return True @@ -1666,10 +1640,8 @@ class RestClient(object): def _fc_initiator_is_added_to_array(self, ininame): """Check whether the fc initiator is already added on the array.""" - url = '/fc_initiator/' + ininame - data = json.dumps({"TYPE": '223', - "ID": ininame}) - result = self.call(url, data, "GET") + url = "/fc_initiator/" + ininame + result = self.call(url, None, "GET") error_code = result['error']['code'] if error_code != 0: return False -- 2.45.2