Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add alert_fix fouction and change alerts filter #449

Merged
merged 8 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions delfin/drivers/ibm/storwize_svc/ssh_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class SSHHandler(object):
}

SECONDS_TO_MS = 1000
ALERT_NOT_FOUND_CODE = 'CMMVC8275E'

def __init__(self, **kwargs):
self.ssh_pool = SSHPool(**kwargs)
Expand Down Expand Up @@ -175,13 +176,9 @@ def parse_string(self, value):
def get_storage(self):
try:
system_info = self.exec_ssh_command('lssystem')
enclosure_info = self.exec_ssh_command('lsenclosure -delim :')
enclosure_res = enclosure_info.split('\n')
enclosure = enclosure_res[1].split(':')
serial_number = enclosure[7]
storage_map = {}
self.handle_detail(system_info, storage_map, split=' ')

serial_number = storage_map.get('id')
status = 'normal' if storage_map.get('statistics_status') == 'on' \
else 'offline'
location = storage_map.get('location')
Expand Down Expand Up @@ -338,7 +335,8 @@ def list_volumes(self, storage_id):
def list_alerts(self, query_para):
try:
alert_list = []
alert_info = self.exec_ssh_command('lseventlog -monitoring yes')
alert_info = self.exec_ssh_command('lseventlog -monitoring yes '
'-message no')
alert_res = alert_info.split('\n')
for i in range(1, len(alert_res)):
if alert_res[i] is None or alert_res[i] == '':
Expand All @@ -360,7 +358,8 @@ def list_alerts(self, query_para):
resource_type = alert_map.get('object_type', '')
severity = self.SEVERITY_MAP.get(alert_map.
get('notification_type'))

if severity == 'Informational' or severity is None:
continue
alert_model = {
'alert_id': event_id,
'alert_name': alert_name,
Expand All @@ -384,3 +383,11 @@ def list_alerts(self, query_para):
err_msg = "Failed to get storage alert: %s" % (six.text_type(err))
LOG.error(err_msg)
raise exception.InvalidResults(err_msg)

def fix_alert(self, alert):
command_line = 'cheventlog -fix %s' % alert
result = self.exec_ssh_command(command_line)
if result:
if self.ALERT_NOT_FOUND_CODE not in result:
raise exception.InvalidResults(six.text_type(result))
LOG.warning("Alert %s doesn't exist.", alert)
2 changes: 1 addition & 1 deletion delfin/drivers/ibm/storwize_svc/storwize_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ def parse_alert(context, alert):
return SSHHandler.parse_alert(alert)

def clear_alert(self, context, alert):
pass
return self.ssh_hanlder.fix_alert(alert)
127 changes: 108 additions & 19 deletions delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def __init__(self):
status message
fixed no
auto_fixed no
notification_type informational
notification_type warning
event_id 980221
event_id_text Error log cleared
error_code
Expand Down Expand Up @@ -317,6 +317,84 @@ def __init__(self):
'storage_id': '4992d7f5-4f73-4123-a27b-6e27889f3852'
}

storage_result = {
'name': 'Cluster_192.168.70.125',
'vendor': 'IBM',
'model': 'IBM Storwize V7000',
'status': 'normal',
'serial_number': '00000200A1207E1F',
'firmware_version': '7.4.0.11',
'location': 'local',
'total_capacity': 8961019766374,
'raw_capacity': 12006666975313,
'subscribed_capacity': 0,
'used_capacity': 5552533720268,
'free_capacity': 3408486046105
}

pool_result = [
{
'name': 'mdiskgrp0',
'storage_id': '12345',
'native_storage_pool_id': '1',
'description': '',
'status': 'normal',
'storage_type': 'block',
'subscribed_capacity': 6058309069045,
'total_capacity': 8939029533818,
'used_capacity': 5552533720268,
'free_capacity': 3364505580994
}
]

volume_result = [
{
'description': '',
'status': 'normal',
'total_capacity': 53687091200,
'used_capacity': 53687091200,
'type': 'thick',
'free_capacity': 0,
'native_volume_id': '0',
'deduplicated': True,
'native_storage_pool_id': '1',
'wwn': '60050768028401F87C00000000000000',
'compressed': False,
'name': 'V7000LUN_Mig',
'storage_id': '12345'
}
]

alert_result = [
{
'type': 'EquipmentAlarm',
'location': 'node1',
'category': 'Fault',
'occur_time': 1605085070000,
'sequence_number': '101',
'resource_type': 'node',
'alert_name': 'Error log cleared',
'severity': 'warning',
'alert_id': '980221',
'description': 'Error log cleared'
}
]

trap_alert_result = {
'alert_id': '981004',
'type': 'EquipmentAlarm',
'severity': 'Informational',
'sequence_number': '165',
'description': 'FC discovery occurred, no configuration changes '
'were detected',
'occur_time': 1604970507000,
'alert_name': 'FC discovery occurred, no configuration changes '
'were detected',
'resource_type': 'cluster',
'location': 'Cluster_192.168.70.125',
'category': 'Fault'
}


def create_driver():

Expand All @@ -338,33 +416,38 @@ def test_list_storage(self):
SSHPool.get = mock.Mock(
return_value={paramiko.SSHClient()})
SSHHandler.do_exec = mock.Mock(
side_effect=[system_info, enclosure_info])
self.driver.get_storage(context)
side_effect=[system_info])
storage = self.driver.get_storage(context)
self.assertDictEqual(storage, storage_result)

def test_list_storage_pools(self):
SSHPool.get = mock.Mock(
return_value={paramiko.SSHClient()})
SSHHandler.do_exec = mock.Mock(
side_effect=[pools_info, pool_info])
self.driver.list_storage_pools(context)
pool = self.driver.list_storage_pools(context)
self.assertDictEqual(pool[0], pool_result[0])

def test_list_volumes(self):
SSHPool.get = mock.Mock(
return_value={paramiko.SSHClient()})
SSHHandler.do_exec = mock.Mock(
side_effect=[volumes_info, volume_info])
self.driver.list_volumes(context)
volume = self.driver.list_volumes(context)
self.assertDictEqual(volume[0], volume_result[0])

def test_list_alerts(self):
query_para = {
"begin_time": 160508506000,
"end_time": 160508507000
"begin_time": 1605085070000,
"end_time": 1605085070000
}
SSHPool.get = mock.Mock(
return_value={paramiko.SSHClient()})
SSHHandler.do_exec = mock.Mock(
side_effect=[alerts_info, alert_info])
self.driver.list_alerts(context, query_para)
alert = self.driver.list_alerts(context, query_para)
self.assertEqual(alert[0].get('alert_id'),
alert_result[0].get('alert_id'))

def test_list_storage_with_error(self):
with self.assertRaises(Exception) as exc:
Expand Down Expand Up @@ -405,19 +488,25 @@ def test_ssh_pool_put(self):
ssh_pool.remove(ssh)

def test_parse_alert(self):
self.driver.parse_alert(context, trap_info)
alert = self.driver.parse_alert(context, trap_info)
self.assertEqual(alert.get('alert_id'),
trap_alert_result.get('alert_id'))

def test_reset_connection(self):
self.driver.reset_connection(context, **ACCESS_INFO)

def test_add_trap_config(self):
trap_config = ''
self.driver.add_trap_config(context, trap_config)

def test_remove_trap_config(self):
trap_config = ''
self.driver.remove_trap_config(context, trap_config)

def test_clear_alert(self):
alert = ''
self.driver.clear_alert(context, alert)
alert_id = 101
SSHPool.get = mock.Mock(
return_value={paramiko.SSHClient()})
SSHHandler.do_exec = mock.Mock(
side_effect=['CMMVC8275E'])
self.driver.clear_alert(context, alert_id)
with self.assertRaises(Exception) as exc:
SSHPool.get = mock.Mock(
return_value={paramiko.SSHClient()})
SSHHandler.do_exec = mock.Mock(
side_effect=['can not find alert'])
self.driver.clear_alert(context, alert_id)
self.assertIn('The results are invalid. can not find alert',
str(exc.exception))