Skip to content

Commit

Permalink
fix ssh excption error when the port is wrong and do some optimize (#402
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jiangyutan authored Dec 1, 2020
1 parent 7be276d commit 2bbaeb7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
40 changes: 14 additions & 26 deletions delfin/drivers/ibm/storwize_svc/ssh_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from oslo_utils import units

from delfin import exception, utils
from delfin.common import constants
from delfin.common import constants, alert_util
from delfin.drivers.utils.ssh_client import SSHPool

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -193,13 +193,16 @@ def get_storage(self):
'total_drive_raw_capacity'))
subscribed_capacity = self.parse_string(storage_map.get(
'virtual_capacity'))
firmware_version = ''
if storage_map.get('code_level') is not None:
firmware_version = storage_map.get('code_level').split(' ')[0]
s = {
'name': storage_map.get('name'),
'vendor': 'IBM',
'model': storage_map.get('product_name'),
'status': status,
'serial_number': serial_number,
'firmware_version': storage_map.get('code_level'),
'firmware_version': firmware_version,
'location': location,
'total_capacity': int(free_capacity + used_capacity),
'raw_capacity': int(raw_capacity),
Expand Down Expand Up @@ -248,13 +251,16 @@ def list_storage_pools(self, storage_id):
total_cap = self.parse_string(pool_map.get('capacity'))
free_cap = self.parse_string(pool_map.get('free_capacity'))
used_cap = self.parse_string(pool_map.get('used_capacity'))
subscribed_capacity = self.parse_string(pool_map.get(
'virtual_capacity'))
p = {
'name': pool_map.get('name'),
'storage_id': storage_id,
'native_storage_pool_id': pool_map.get('id'),
'description': '',
'status': status,
'storage_type': constants.StorageType.BLOCK,
'subscribed_capacity': int(subscribed_capacity),
'total_capacity': int(total_cap),
'used_capacity': int(used_cap),
'free_capacity': int(free_cap)
Expand Down Expand Up @@ -329,25 +335,6 @@ def list_volumes(self, storage_id):
LOG.error(err_msg)
raise exception.InvalidResults(err_msg)

def judge_alert_time(self, alert_map, query_para):
if len(alert_map) <= 1:
return False
if query_para is None and len(alert_map) > 1:
return True
occur_time = int(alert_map.get('last_timestamp_epoch')) * \
self.SECONDS_TO_MS
if query_para.get('begin_time') and query_para.get('end_time'):
if occur_time >= int(query_para.get('begin_time')) and \
occur_time <= int(query_para.get('end_time')):
return True
if query_para.get('begin_time'):
if occur_time >= int(query_para.get('begin_time')):
return True
if query_para.get('end_time'):
if occur_time <= int(query_para.get('end_time')):
return True
return False

def list_alerts(self, query_para):
try:
alert_list = []
Expand All @@ -357,15 +344,16 @@ def list_alerts(self, query_para):
if alert_res[i] is None or alert_res[i] == '':
continue
alert_str = ' '.join(alert_res[i].split())
strinfo = alert_str.split(' ', 9)
strinfo = alert_str.split(' ', 1)
detail_command = 'lseventlog %s' % strinfo[0]
deltail_info = self.exec_ssh_command(detail_command)
alert_map = {}
self.handle_detail(deltail_info, alert_map, split=' ')
if self.judge_alert_time(alert_map, query_para) is False:
continue
time_stamp = int(alert_map.get('last_timestamp_epoch')) * \
occur_time = int(alert_map.get('last_timestamp_epoch')) * \
self.SECONDS_TO_MS
if not alert_util.is_alert_in_time_range(query_para,
occur_time):
continue
alert_name = alert_map.get('event_id_text', '')
event_id = alert_map.get('event_id')
location = alert_map.get('object_name', '')
Expand All @@ -380,7 +368,7 @@ def list_alerts(self, query_para):
'category': constants.Category.FAULT,
'type': 'EquipmentAlarm',
'sequence_number': alert_map.get('sequence_number'),
'occur_time': time_stamp,
'occur_time': occur_time,
'description': alert_name,
'resource_type': resource_type,
'location': location
Expand Down
2 changes: 1 addition & 1 deletion delfin/drivers/utils/ssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def create(self):
err = six.text_type(e)
LOG.error('doexec InvalidUsernameOrPassword error')
if 'timed out' in err:
raise exception.SSHConnectTimeout()
raise exception.InvalidIpOrPort()
elif 'No authentication methods available' in err \
or 'Authentication failed' in err:
raise exception.InvalidUsernameOrPassword()
Expand Down

0 comments on commit 2bbaeb7

Please sign in to comment.