Skip to content

Commit

Permalink
Improves the parsing way of ssh returns
Browse files Browse the repository at this point in the history
Huawei driver failed to parse ssh result when firstly logging
in storage system on paramiko 1.8.0. The update of paramiko
make the order of ssh returns changed. This patch improves
the parsing way of ssh returns.

This patch also does some changes for log punctuations.

fixes bug 1224499
Change-Id: Ia8761081dff998884f45312355b62aa27ab5417c
  • Loading branch information
zhangchao010 committed Sep 13, 2013
1 parent 6a84a0b commit 39c3002
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 35 deletions.
16 changes: 8 additions & 8 deletions cinder/volume/drivers/huawei/huawei_t.py
Expand Up @@ -95,8 +95,8 @@ def delete_snapshot(self, snapshot):

def initialize_connection(self, volume, connector):
"""Map a volume to a host and return target iSCSI information."""
LOG.debug(_('initialize_connection: volume name: %(vol)s '
'host: %(host)s initiator: %(ini)s')
LOG.debug(_('initialize_connection: volume name: %(vol)s, '
'host: %(host)s, initiator: %(ini)s')
% {'vol': volume['name'],
'host': connector['host'],
'ini': connector['initiator']})
Expand Down Expand Up @@ -227,7 +227,7 @@ def _get_tgt_iqn(self, port_ip):

iqn = iqn_prefix + ':' + iqn_suffix + ':' + port_info[3]

LOG.debug(_('_get_tgt_iqn: iSCSI target iqn is %s') % iqn)
LOG.debug(_('_get_tgt_iqn: iSCSI target iqn is %s.') % iqn)

return (iqn, port_info[0])

Expand Down Expand Up @@ -316,7 +316,7 @@ def _delete_initiator(self, ininame, attempts=2):

def terminate_connection(self, volume, connector, **kwargs):
"""Terminate the map."""
LOG.debug(_('terminate_connection: volume: %(vol)s host: %(host)s '
LOG.debug(_('terminate_connection: volume: %(vol)s, host: %(host)s, '
'connector: %(initiator)s')
% {'vol': volume['name'],
'host': connector['host'],
Expand Down Expand Up @@ -344,7 +344,7 @@ def _remove_iscsi_port(self, hostid, connector):
break
else:
LOG.warn(_('_remove_iscsi_port: iSCSI port was not found '
'on host %(hostid)s') % {'hostid': hostid})
'on host %(hostid)s.') % {'hostid': hostid})

# Delete host if no initiator added to it.
if port_num == 0:
Expand Down Expand Up @@ -431,8 +431,8 @@ def validate_connector(self, connector):

def initialize_connection(self, volume, connector):
"""Create FC connection between a volume and a host."""
LOG.debug(_('initialize_connection: volume name: %(vol)s '
'host: %(host)s initiator: %(wwn)s')
LOG.debug(_('initialize_connection: volume name: %(vol)s, '
'host: %(host)s, initiator: %(wwn)s')
% {'vol': volume['name'],
'host': connector['host'],
'wwn': connector['wwpns']})
Expand Down Expand Up @@ -540,7 +540,7 @@ def _get_fc_port_ctr(self, port_details):

def terminate_connection(self, volume, connector, **kwargs):
"""Terminate the map."""
LOG.debug(_('terminate_connection: volume: %(vol)s host: %(host)s '
LOG.debug(_('terminate_connection: volume: %(vol)s, host: %(host)s, '
'connector: %(initiator)s')
% {'vol': volume['name'],
'host': connector['host'],
Expand Down
57 changes: 30 additions & 27 deletions cinder/volume/drivers/huawei/ssh_common.py
Expand Up @@ -64,23 +64,26 @@ def ssh_read(user, channel, cmd, timeout):
result = result + channel.recv(8192)
except socket.timeout:
raise exception.CinderException(_('ssh_read: Read '
'SSH timeout'))
'SSH timeout.'))
else:
# Complete CLI response starts with CLI cmd and
# ends with "username:/>".
if result.startswith(cmd) and result.endswith(user + ':/>'):
if not re.search('Welcome', result):
# CLI returns welcome information when first log in. So need to
# deal differently.
if not re.search('Welcome', result):
# Complete CLI response starts with CLI cmd and
# ends with "username:/>".
if result.startswith(cmd) and result.endswith(user + ':/>'):
break
# CLI returns welcome information when first log in.
elif re.search(user + ':/>' + cmd, result):
# Some commands need to send 'y'.
elif re.search('(y/n)', result):
break
# Some commands need to send 'y'.
elif re.search('(y/n)', result):
# Reach maximum limit of SSH connection.
elif re.search('No response message', result):
msg = _('No response message. Please check system status.')
raise exception.CinderException(msg)
elif (re.search(user + ':/>' + cmd, result) and
result.endswith(user + ':/>')):
break
# Reach maximum limit of SSH connection.
elif re.search('No response message', result):
msg = _('No response message. Please check system status.')
raise exception.CinderException(msg)

# Filter the last line: username:/> .
result = '\r\n'.join(result.split('\r\n')[:-1])
# Filter welcome information.
Expand All @@ -104,7 +107,7 @@ def __init__(self, configuration=None):

def do_setup(self, context):
"""Check config file."""
LOG.debug(_('do_setup.'))
LOG.debug(_('do_setup'))

self._check_conf_file()
self.login_info = self._get_login_info()
Expand Down Expand Up @@ -208,7 +211,7 @@ def create_volume(self, volume):
"""Create a new volume."""
volume_name = self._name_translate(volume['name'])

LOG.debug(_('create_volume: volume name: %s.') % volume_name)
LOG.debug(_('create_volume: volume name: %s') % volume_name)

self._update_login_info()
if int(volume['size']) == 0:
Expand Down Expand Up @@ -379,7 +382,7 @@ def _parse_conf_lun_params(self):
conf_params['PrefetchTimes'] = prefetch.attrib['Value'].strip()
else:
LOG.debug(_('_parse_conf_lun_params: Use default prefetch type. '
'Prefetch type: Intelligent.'))
'Prefetch type: Intelligent'))

pools_conf = root.findall('LUN/StoragePool')
for pool in pools_conf:
Expand Down Expand Up @@ -492,7 +495,7 @@ def _reset_transport_timeout(self, ssh, time):
def delete_volume(self, volume):
volume_name = self._name_translate(volume['name'])

LOG.debug(_('delete_volume: volume name: %s.') % volume_name)
LOG.debug(_('delete_volume: volume name: %s') % volume_name)

self._update_login_info()
volume_id = volume.get('provider_location', None)
Expand Down Expand Up @@ -530,7 +533,7 @@ def create_volume_from_snapshot(self, volume, snapshot):
volume_name = self._name_translate(volume['name'])

LOG.debug(_('create_volume_from_snapshot: snapshot '
'name: %(snapshot)s, volume name: %(volume)s.')
'name: %(snapshot)s, volume name: %(volume)s')
% {'snapshot': snapshot_name,
'volume': volume_name})

Expand Down Expand Up @@ -647,7 +650,7 @@ def create_cloned_volume(self, tgt_volume, src_volume):
src_vol_name = self._name_translate(src_volume['name'])
tgt_vol_name = self._name_translate(tgt_volume['name'])

LOG.debug(_('create_cloned_volume: src volume: %(src)s '
LOG.debug(_('create_cloned_volume: src volume: %(src)s, '
'tgt volume: %(tgt)s') % {'src': src_vol_name,
'tgt': tgt_vol_name})

Expand Down Expand Up @@ -694,7 +697,7 @@ def create_snapshot(self, snapshot):
snapshot_name = self._name_translate(snapshot['name'])
volume_name = self._name_translate(snapshot['volume_name'])

LOG.debug(_('create_snapshot: snapshot name: %(snapshot)s '
LOG.debug(_('create_snapshot: snapshot name: %(snapshot)s, '
'volume name: %(volume)s')
% {'snapshot': snapshot_name,
'volume': volume_name})
Expand Down Expand Up @@ -770,7 +773,7 @@ def delete_snapshot(self, snapshot):
snapshot_name = self._name_translate(snapshot['name'])
volume_name = self._name_translate(snapshot['volume_name'])

LOG.debug(_('delete_snapshot: snapshot name: %(snapshot)s '
LOG.debug(_('delete_snapshot: snapshot name: %(snapshot)s, '
'volume name: %(volume)s') % {'snapshot': snapshot_name,
'volume': volume_name})

Expand Down Expand Up @@ -873,7 +876,7 @@ def map_volume(self, host_id, volume_id):
'hostlunid': new_hostlun_id})
out = self._execute_cli(cli_cmd)

msg = ('Failed to map lun %s to host %s. host lun ID: %s'
msg = ('Failed to map LUN %s to host %s. host LUN ID: %s'
% (volume_id, host_id, new_hostlun_id))
self._assert_cli_operate_out('map_volume', msg, cli_cmd, out)

Expand Down Expand Up @@ -981,7 +984,7 @@ def get_lun_details(self, lun_id):
return lun_details

def change_lun_ctr(self, lun_id, ctr):
LOG.debug(_('change_lun_ctr: Changing LUN %(lun)s ctr to %(ctr)s')
LOG.debug(_('change_lun_ctr: Changing LUN %(lun)s ctr to %(ctr)s.')
% {'lun': lun_id, 'ctr': ctr})

cli_cmd = 'chglun -lun %s -c %s' % (lun_id, ctr)
Expand Down Expand Up @@ -1080,7 +1083,7 @@ def get_volume_stats(self, refresh=False):
def _update_volume_stats(self):
"""Retrieve stats info from volume group."""

LOG.debug(_("_update_volume_stats: Updating volume stats"))
LOG.debug(_("_update_volume_stats: Updating volume stats."))
data = {}
data['vendor_name'] = 'Huawei'
data['total_capacity_gb'] = 'infinite'
Expand Down Expand Up @@ -1144,7 +1147,7 @@ def __init__(self, configuration=None):

def do_setup(self, context):
"""Check config file."""
LOG.debug(_('do_setup.'))
LOG.debug(_('do_setup'))

self._check_conf_file()
self.lun_distribution = self._get_lun_ctr_info()
Expand Down Expand Up @@ -1192,7 +1195,7 @@ def _get_device_type(self):
elif re.search('Dorado5100$', line):
return 'Dorado5100'
else:
LOG.error(_('_get_device_type: The drivers only support'
LOG.error(_('_get_device_type: The driver only supports '
'Dorado5100 and Dorado 2100 G2 now.'))
raise exception.InvalidResults()

Expand All @@ -1201,7 +1204,7 @@ def _get_lun_ctr_info(self):
ctr_info = [0, 0]
(c, n) = ((2, 4) if self.device_type == 'Dorado2100 G2' else (3, 5))
for lun in luns:
if lun[n].startswith('OpenStack'):
if lun[n].startswith(VOL_AND_SNAP_NAME_PREFIX):
if lun[c] == 'A':
ctr_info[0] += 1
else:
Expand Down

0 comments on commit 39c3002

Please sign in to comment.