From 224b6c2e29e674de721f7b177f976e5a7fb76464 Mon Sep 17 00:00:00 2001 From: tanjy <306848916@qq.com> Date: Mon, 7 Dec 2020 12:16:41 +0800 Subject: [PATCH 1/6] change ibm storwize_svc test --- .../ibm/storwize_svc/test_ibm_storwize_svc.py | 107 ++++++++++++++---- 1 file changed, 88 insertions(+), 19 deletions(-) diff --git a/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py b/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py index 864721450..8935bd2be 100644 --- a/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py +++ b/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py @@ -317,6 +317,82 @@ 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': '78N16G4', + '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': 'Informational', + '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(): @@ -339,32 +415,36 @@ def test_list_storage(self): return_value={paramiko.SSHClient()}) SSHHandler.do_exec = mock.Mock( side_effect=[system_info, enclosure_info]) - self.driver.get_storage(context) + 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.assertDictEqual(alert[0], alert_result[0]) def test_list_storage_with_error(self): with self.assertRaises(Exception) as exc: @@ -405,19 +485,8 @@ 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.assertDictEqual(alert, trap_alert_result) 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) From 64cb75ad5ea57403ef497dff919e352b8e726d21 Mon Sep 17 00:00:00 2001 From: tanjy <306848916@qq.com> Date: Wed, 16 Dec 2020 17:43:43 +0800 Subject: [PATCH 2/6] edit test --- .../unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py b/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py index 8935bd2be..cf1050adc 100644 --- a/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py +++ b/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py @@ -444,7 +444,8 @@ def test_list_alerts(self): SSHHandler.do_exec = mock.Mock( side_effect=[alerts_info, alert_info]) alert = self.driver.list_alerts(context, query_para) - self.assertDictEqual(alert[0], alert_result[0]) + 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: @@ -486,7 +487,8 @@ def test_ssh_pool_put(self): def test_parse_alert(self): alert = self.driver.parse_alert(context, trap_info) - self.assertDictEqual(alert, trap_alert_result) + self.assertEqual(alert.get('alert_id'), + trap_alert_result.get('alert_id')) def test_reset_connection(self): self.driver.reset_connection(context, **ACCESS_INFO) From 2a385a8942eba05da49ade8dd71fe23b0df2db72 Mon Sep 17 00:00:00 2001 From: tanjy <306848916@qq.com> Date: Wed, 16 Dec 2020 18:08:07 +0800 Subject: [PATCH 3/6] edit test --- .../unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py b/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py index cf1050adc..9ea9cd585 100644 --- a/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py +++ b/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py @@ -385,9 +385,11 @@ def __init__(self): 'type': 'EquipmentAlarm', 'severity': 'Informational', 'sequence_number': '165', - 'description': 'FC discovery occurred, no configuration changes were detected', + 'description': 'FC discovery occurred, no configuration changes ' + 'were detected', 'occur_time': 1604970507000, - 'alert_name': 'FC discovery occurred, no configuration changes were detected', + 'alert_name': 'FC discovery occurred, no configuration changes ' + 'were detected', 'resource_type': 'cluster', 'location': 'Cluster_192.168.70.125', 'category': 'Fault' From 2ab0548b4bd4ecdbaf735adef64ce24ff1361210 Mon Sep 17 00:00:00 2001 From: tanjy <306848916@qq.com> Date: Tue, 5 Jan 2021 15:05:34 +0800 Subject: [PATCH 4/6] add alert_fix fouction and change alerts filter --- .../drivers/ibm/storwize_svc/ssh_handler.py | 21 ++++++++++++------- .../drivers/ibm/storwize_svc/storwize_svc.py | 2 +- .../ibm/storwize_svc/test_ibm_storwize_svc.py | 10 ++++----- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/delfin/drivers/ibm/storwize_svc/ssh_handler.py b/delfin/drivers/ibm/storwize_svc/ssh_handler.py index 1be7f71f6..c97fad797 100644 --- a/delfin/drivers/ibm/storwize_svc/ssh_handler.py +++ b/delfin/drivers/ibm/storwize_svc/ssh_handler.py @@ -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) @@ -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') @@ -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] == '': @@ -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, @@ -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) diff --git a/delfin/drivers/ibm/storwize_svc/storwize_svc.py b/delfin/drivers/ibm/storwize_svc/storwize_svc.py index 98ed7b5e7..55963039f 100644 --- a/delfin/drivers/ibm/storwize_svc/storwize_svc.py +++ b/delfin/drivers/ibm/storwize_svc/storwize_svc.py @@ -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) diff --git a/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py b/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py index 9ea9cd585..39fd02351 100644 --- a/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py +++ b/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py @@ -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 @@ -322,7 +322,7 @@ def __init__(self): 'vendor': 'IBM', 'model': 'IBM Storwize V7000', 'status': 'normal', - 'serial_number': '78N16G4', + 'serial_number': '00000200A1207E1F', 'firmware_version': '7.4.0.11', 'location': 'local', 'total_capacity': 8961019766374, @@ -374,7 +374,7 @@ def __init__(self): 'sequence_number': '101', 'resource_type': 'node', 'alert_name': 'Error log cleared', - 'severity': 'Informational', + 'severity': 'warning', 'alert_id': '980221', 'description': 'Error log cleared' } @@ -416,7 +416,7 @@ def test_list_storage(self): SSHPool.get = mock.Mock( return_value={paramiko.SSHClient()}) SSHHandler.do_exec = mock.Mock( - side_effect=[system_info, enclosure_info]) + side_effect=[system_info]) storage = self.driver.get_storage(context) self.assertDictEqual(storage, storage_result) @@ -478,7 +478,7 @@ def test_ssh_pool_create(self): kwargs = ACCESS_INFO ssh_pool = SSHPool(**kwargs) ssh_pool.create() - self.assertIn('Exception in SSH protocol negotiation or logic', + self.assertIn('Invalid ip or port', str(exc.exception)) def test_ssh_pool_put(self): From 495a487ed883c6635871e68dbdb436497cb414db Mon Sep 17 00:00:00 2001 From: tanjy <306848916@qq.com> Date: Tue, 5 Jan 2021 15:29:33 +0800 Subject: [PATCH 5/6] add alert_fix fouction and change alerts filter --- .../unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py b/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py index 39fd02351..c11c616ab 100644 --- a/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py +++ b/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py @@ -478,7 +478,7 @@ def test_ssh_pool_create(self): kwargs = ACCESS_INFO ssh_pool = SSHPool(**kwargs) ssh_pool.create() - self.assertIn('Invalid ip or port', + self.assertIn('Exception in SSH protocol negotiation or logic', str(exc.exception)) def test_ssh_pool_put(self): From 0fc7efdde658b8152f3dbdb4e242f2bef50c213e Mon Sep 17 00:00:00 2001 From: tanjy <306848916@qq.com> Date: Tue, 5 Jan 2021 15:48:22 +0800 Subject: [PATCH 6/6] add alert_clear test --- .../ibm/storwize_svc/test_ibm_storwize_svc.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py b/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py index c11c616ab..365b7e26a 100644 --- a/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py +++ b/delfin/tests/unit/drivers/ibm/storwize_svc/test_ibm_storwize_svc.py @@ -494,3 +494,19 @@ def test_parse_alert(self): def test_reset_connection(self): self.driver.reset_connection(context, **ACCESS_INFO) + + def test_clear_alert(self): + 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))