From: zhangchao010 Date: Tue, 24 Sep 2013 18:07:05 +0000 (+0800) Subject: Add error logs for Huawei driver X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=59cb2be6135096487f975924b93b6b8e8adc0dd0;p=openstack-build%2Fcinder-build.git Add error logs for Huawei driver Log some errors to avoid losing the exception messages. HVS driver do repeated judgements for JSON results, here add error logs and replace these judgement codes with a assertion function. fixes bug 1229877 Change-Id: Icd1e859566e07c0f02aa0b2d5c136a2048524527 --- diff --git a/cinder/tests/test_huawei_t_dorado.py b/cinder/tests/test_huawei_t_dorado.py index b9838378e..301584f44 100644 --- a/cinder/tests/test_huawei_t_dorado.py +++ b/cinder/tests/test_huawei_t_dorado.py @@ -1044,7 +1044,7 @@ class HuaweiTISCSIDriverTestCase(test.TestCase): tmp_configuration = mox.MockObject(conf.Configuration) tmp_configuration.cinder_huawei_conf_file = tmp_fonf_file tmp_configuration.append_config_values(mox.IgnoreArg()) - self.assertRaises(exception.ConfigNotFound, + self.assertRaises(IOError, HuaweiVolumeDriver, configuration=tmp_configuration) # Test Product and Protocol invalid @@ -1635,7 +1635,7 @@ class SSHMethodTestCase(test.TestCase): def test_socket_timeout(self): self.stubs.Set(FakeChannel, 'recv', self._fake_recv2) - self.assertRaises(exception.CinderException, + self.assertRaises(socket.timeout, self.driver.create_volume, FAKE_VOLUME) def _fake_recv1(self, nbytes): diff --git a/cinder/volume/drivers/huawei/__init__.py b/cinder/volume/drivers/huawei/__init__.py index 37948aa47..4bbd163de 100644 --- a/cinder/volume/drivers/huawei/__init__.py +++ b/cinder/volume/drivers/huawei/__init__.py @@ -18,7 +18,7 @@ """ Provide a unified driver class for users. -The product type and the protocol should be specified in confige file before. +The product type and the protocol should be specified in config file before. """ from oslo.config import cfg diff --git a/cinder/volume/drivers/huawei/rest_common.py b/cinder/volume/drivers/huawei/rest_common.py index 8d46d48e7..4ef284280 100644 --- a/cinder/volume/drivers/huawei/rest_common.py +++ b/cinder/volume/drivers/huawei/rest_common.py @@ -78,8 +78,9 @@ class HVSCommon(): try: res_json = json.loads(res) - except Exception: - raise exception.CinderException(_('JSON transfer Error')) + except Exception as err: + LOG.error(_('JSON transfer error')) + raise err return res_json @@ -99,6 +100,7 @@ class HVSCommon(): if (result['error']['code'] != 0) or ("data" not in result): time.sleep(30) msg = _("Login error, reason is %s") % result + LOG.error(msg) raise exception.CinderException(msg) deviceid = result['data']['deviceid'] @@ -166,17 +168,22 @@ class HVSCommon(): LOG.error(msg) raise exception.CinderException(msg) + def _assert_data_in_result(self, result, msg): + if "data" not in result: + msg = _('%s "data" was not in result.') % msg + LOG.error(msg) + raise exception.CinderException(msg) + def _create_volume(self, lun_param): url = self.url + "/lun" data = json.dumps(lun_param) result = self.call(url, data) - self._assert_rest_result(result, 'create volume error') - if "data" in result: - return result['data']['ID'] - else: - msg = _('create volume error: %(err)s') % {'err': result} - raise exception.CinderException(msg) + msg = 'Create volume error.' + self._assert_rest_result(result, msg) + self._assert_data_in_result(result, msg) + + return result['data']['ID'] def create_volume(self, volume): volume_name = self._encode_name(volume['id']) @@ -267,7 +274,7 @@ class HVSCommon(): root = tree.getroot() except Exception as err: LOG.error(_('_read_xml:%s') % err) - raise exception.VolumeBackendAPIException(data=err) + raise err return root def _encode_name(self, name): @@ -282,6 +289,7 @@ class HVSCommon(): pool_name = root.findtext('LUN/StoragePool') if not pool_name: err_msg = _("Invalid resource pool: %s") % pool_name + LOG.error(err_msg) raise exception.InvalidInput(err_msg) url = self.url + "/storagepool" @@ -299,6 +307,7 @@ class HVSCommon(): if not poolinfo: msg = (_('Get pool info error, pool name is:%s') % pool_name) + LOG.error(msg) raise exception.CinderException(msg) return poolinfo @@ -338,10 +347,10 @@ class HVSCommon(): "PARENTTYPE": "11", "PARENTID": lun_id}) result = self.call(url, data) - self._assert_rest_result(result, 'Create snapshot error.') - if 'data' not in result: - raise exception.CinderException(_('Create snapshot error.')) + msg = 'Create snapshot error.' + self._assert_rest_result(result, msg) + self._assert_data_in_result(result, msg) return result['data']['ID'] @@ -439,10 +448,10 @@ class HVSCommon(): "TARGETLUN": ("INVALID;%s;INVALID;INVALID;INVALID" % tgtlunid)}) result = self.call(url, data) - self._assert_rest_result(result, 'Create lun copy error.') - if "data" not in result: - raise exception.CinderException(_('Create luncopy error.')) + msg = 'Create lun copy error.' + self._assert_rest_result(result, msg) + self._assert_data_in_result(result, msg) return result['data']['ID'] @@ -578,11 +587,10 @@ class HVSCommon(): def _get_iscsi_tgt_port(self): url = self.url + "/iscsidevicename" result = self.call(url, None) + msg = 'Get iSCSI target port error.' self._assert_rest_result(result, msg) - - if "data" not in result: - raise exception.CinderException(_('%s') % msg) + self._assert_data_in_result(result, msg) return result['data'][0]['CMO_ISCSI_DEVICE_NAME'] @@ -618,11 +626,10 @@ class HVSCommon(): url = self.url + "/hostgroup" data = json.dumps({"TYPE": "14", "NAME": hostgroupname}) result = self.call(url, data) + msg = 'Create host group error.' self._assert_rest_result(result, msg) - - if "data" not in result: - raise exception.CinderException(_('%s') % msg) + self._assert_data_in_result(result, msg) return result['data']['ID'] @@ -631,11 +638,10 @@ class HVSCommon(): data = json.dumps({"DESCRIPTION": lungroupname, "NAME": lungroupname}) result = self.call(url, data) + msg = 'Create lun group error.' self._assert_rest_result(result, msg) - - if "data" not in result: - raise exception.CinderException(_('%s') % msg) + self._assert_data_in_result(result, msg) return result['data']['ID'] @@ -686,9 +692,10 @@ class HVSCommon(): hostassoinfo = json.loads(associate_data) host_lun_id = hostassoinfo['HostLUNID'] break - except Exception: - msg = _("_find_host_lun_id transfer data error! ") - raise exception.CinderException(msg) + except Exception as err: + msg = _("JSON transfer data error. %s") % err + LOG.error(msg) + raise err return host_lun_id def _find_host(self, hostname): @@ -800,11 +807,10 @@ class HVSCommon(): url = self.url + "/mappingview" data = json.dumps({"TYPE": "245"}) result = self.call(url, data, "GET") + msg = 'Find map view error.' self._assert_rest_result(result, msg) - - if "data" not in result: - raise exception.CinderException(_('%s') % msg) + self._assert_data_in_result(result, msg) viewid = None for item in result['data']: @@ -937,6 +943,7 @@ class HVSCommon(): err_msg = (_('Config file is wrong. LUNType must be "Thin"' ' or "Thick". LUNType:%(fetchtype)s') % {'fetchtype': luntype}) + LOG.error(err_msg) raise exception.VolumeBackendAPIException(data=err_msg) stripunitsize = root.findtext('LUN/StripUnitSize') @@ -963,6 +970,7 @@ class HVSCommon(): err_msg = (_('PrefetchType config is wrong. PrefetchType' ' must in 1,2,3,4. fetchtype is:%(fetchtype)s') % {'fetchtype': fetchtype}) + LOG.error(err_msg) raise exception.CinderException(err_msg) else: LOG.debug(_('Use default prefetch fetchtype. ' @@ -980,6 +988,7 @@ class HVSCommon(): err_msg = (_('_wait_for_luncopy:LUNcopy status is not normal.' 'LUNcopy name: %(luncopyname)s') % {'luncopyname': luncopyid}) + LOG.error(err_msg) raise exception.VolumeBackendAPIException(data=err_msg) time.sleep(10) @@ -1014,11 +1023,10 @@ class HVSCommon(): """ url = self.url + "/fc_initiator?ISFREE=true&range=[0-1000]" result = self.call(url, None, "GET") + msg = 'Get connected free FC wwn error.' self._assert_rest_result(result, msg) - - if "data" not in result: - raise exception.CinderException(_('%s') % msg) + self._assert_data_in_result(result, msg) wwns = [] for item in result['data']: @@ -1039,11 +1047,10 @@ class HVSCommon(): """Get iscsi port info in order to build the iscsi target iqn.""" url = self.url + "/eth_port" result = self.call(url, None, "GET") + msg = 'Get iSCSI port information error.' self._assert_rest_result(result, msg) - - if "data" not in result: - raise exception.CinderException(_('%s') % msg) + self._assert_data_in_result(result, msg) iscsi_port_info = None for item in result['data']: @@ -1102,11 +1109,10 @@ class HVSCommon(): url = (self.url + "/host_link?INITIATOR_TYPE=223&INITIATOR_PORT_WWN=" + wwn) result = self.call(url, None, "GET") + msg = 'Get FC target wwpn error.' self._assert_rest_result(result, msg) - - if "data" not in result: - raise exception.CinderException(_('%s') % msg) + self._assert_data_in_result(result, msg) fc_wwpns = None for item in result['data']: @@ -1174,11 +1180,10 @@ class HVSCommon(): def _find_qos_policy_info(self, policy_name): url = self.url + "/ioclass" result = self.call(url, None, "GET") + msg = 'Get qos policy error.' self._assert_rest_result(result, msg) - - if "data" not in result: - raise exception.CinderException(_('%s') % msg) + self._assert_data_in_result(result, msg) qos_info = {} for item in result['data']: @@ -1245,6 +1250,7 @@ class HVSCommon(): if not pool_node: err_msg = (_('_check_conf_file: Config file invalid. ' 'StoragePool must be set.')) + LOG.error(err_msg) raise exception.InvalidInput(reason=err_msg) def _get_iscsi_params(self, connector): diff --git a/cinder/volume/drivers/huawei/ssh_common.py b/cinder/volume/drivers/huawei/ssh_common.py index e4dae758d..0b10e1aa2 100644 --- a/cinder/volume/drivers/huawei/ssh_common.py +++ b/cinder/volume/drivers/huawei/ssh_common.py @@ -52,7 +52,7 @@ def parse_xml_file(filepath): return root except IOError as err: LOG.error(_('parse_xml_file: %s') % err) - raise exception.ConfigNotFound(path=err) + raise err def ssh_read(user, channel, cmd, timeout): @@ -62,9 +62,10 @@ def ssh_read(user, channel, cmd, timeout): while True: try: result = result + channel.recv(8192) - except socket.timeout: - raise exception.CinderException(_('ssh_read: Read ' - 'SSH timeout.')) + except socket.timeout as err: + msg = _('ssh_read: Read SSH timeout. %s') % err + LOG.error(msg) + raise err else: # CLI returns welcome information when first log in. So need to # deal differently. @@ -79,6 +80,7 @@ def ssh_read(user, channel, cmd, timeout): # Reach maximum limit of SSH connection. elif re.search('No response message', result): msg = _('No response message. Please check system status.') + LOG.error(msg) raise exception.CinderException(msg) elif (re.search(user + ':/>' + cmd, result) and result.endswith(user + ':/>')): @@ -362,6 +364,7 @@ class TseriesCommon(): else: err_msg = (_('LUNType must be "Thin" or "Thick". ' 'LUNType:%(type)s') % {'type': luntype}) + LOG.error(err_msg) raise exception.InvalidInput(reason=err_msg) stripunitsize = root.findtext('LUN/StripUnitSize') @@ -411,6 +414,7 @@ class TseriesCommon(): 'id. Please check config file and make sure ' 'the StoragePool %s is created in storage ' 'array.') % pools_conf) + LOG.error(err_msg) raise exception.InvalidInput(reason=err_msg) def _execute_cli(self, cmd): @@ -486,6 +490,7 @@ class TseriesCommon(): else: if ssh_client: self.ssh_pool.remove(ssh_client) + LOG.error(_('_execute_cli: %s') % err) raise err def _reset_transport_timeout(self, ssh, time): @@ -839,6 +844,7 @@ class TseriesCommon(): 'msg': msg, 'cmd': cmd, 'out': cliout}) + LOG.error(err_msg) raise exception.VolumeBackendAPIException(data=err_msg) def _assert_cli_operate_out(self, func, msg, cmd, cliout): @@ -850,6 +856,7 @@ class TseriesCommon(): """Map a volume to a host.""" # Map a LUN to a host if not mapped. if not self._check_volume_created(volume_id): + LOG.error(_('map_volume: Volume %s was not found.') % volume_id) raise exception.VolumeNotFound(volume_id=volume_id) hostlun_id = None @@ -1318,6 +1325,7 @@ class DoradoCommon(TseriesCommon): else: err_msg = (_('LUNType must be "Thin" or "Thick". ' 'LUNType:%(type)s') % {'type': luntype}) + LOG.error(err_msg) raise exception.InvalidInput(reason=err_msg) # Here we do not judge whether the parameters are set correct.