Skip to content

Commit

Permalink
pure codeview-test parse_alert
Browse files Browse the repository at this point in the history
  • Loading branch information
zhilong-xu committed Nov 22, 2021
1 parent 8bcc1f4 commit d09a9dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
11 changes: 4 additions & 7 deletions delfin/drivers/pure/flasharray/pure_flasharray.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
import hashlib
import json

from oslo_log import log

Expand Down Expand Up @@ -114,7 +113,7 @@ def list_alerts(self, context, query_para=None):
time = alert.get('opened')
alerts_model['occur_time'] = int(datetime.datetime.strptime(
time, '%Y-%m-%dT%H:%M:%SZ').timestamp()
* consts.DEFAULT_LIST_ALERTS_TIME_CONVERSION) \
* consts.DEFAULT_LIST_ALERTS_TIME_CONVERSION) \
if time is not None else None
alerts_model['description'] = alert.get('details')
alerts_model['location'] = alert.get('component_name')
Expand All @@ -130,8 +129,6 @@ def list_alerts(self, context, query_para=None):
@staticmethod
def parse_alert(context, alert):
try:
LOG.info(
"parse_alert:%s" % (json.dumps(alert, ensure_ascii=False)))
alert_model = dict()
alert_model['alert_id'] = alert.get(consts.PARSE_ALERT_ALERT_ID)
alert_model['severity'] = consts.PARSE_ALERT_SEVERITY_MAP.get(
Expand Down Expand Up @@ -250,18 +247,18 @@ def list_ports(self, context):
if speed is None:
hardware_result['connection_status'] = \
constants.PortConnectionStatus.UNKNOWN
hardware_result['health_status'] = constants.PortHealthStatus. \
hardware_result['health_status'] = constants.PortHealthStatus.\
UNKNOWN
elif speed == consts.CONSTANT_ZERO:
hardware_result['connection_status'] = \
constants.PortConnectionStatus.DISCONNECTED
hardware_result['health_status'] = constants.PortHealthStatus. \
hardware_result['health_status'] = constants.PortHealthStatus.\
ABNORMAL
hardware_result['speed'] = speed
else:
hardware_result['connection_status'] = \
constants.PortConnectionStatus.CONNECTED
hardware_result['health_status'] = constants.PortHealthStatus. \
hardware_result['health_status'] = constants.PortHealthStatus.\
NORMAL
hardware_result['speed'] = int(speed)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@
"component_name": "ct1.ntpd"
}
]
parse_alert_info = {
'1.3.6.1.2.1.1.3.0': '30007589',
'1.3.6.1.4.1.40482.3.7': '2',
'1.3.6.1.4.1.40482.3.6': 'server error',
'1.3.6.1.4.1.40482.3.3': 'cto',
'1.3.6.1.4.1.40482.3.5': 'cto.server error'
}
controllers_info = [
{
"status": "ready",
Expand Down Expand Up @@ -305,6 +312,11 @@ def test_list_alerts(self):
self.assertEqual(list_alerts[0].get('alert_id'),
alerts_info[0].get('id'))

def test_parse_alert(self):
parse_alert = self.driver.parse_alert(context, parse_alert_info)
self.assertEqual(parse_alert.get('alert_id'),
parse_alert_info.get('1.3.6.1.2.1.1.3.0'))

def test_list_controllers(self):
RestHandler.rest_call = mock.Mock(
side_effect=[controllers_info])
Expand All @@ -323,7 +335,8 @@ def test_list_ports(self):
RestHandler.rest_call = mock.Mock(
side_effect=[port_network_info, port_info, hardware_info])
list_ports = self.driver.list_ports(context)
self.assertEqual(list_ports[0].get('name'), hardware_info[0].get('name'))
self.assertEqual(list_ports[0].get('name'),
hardware_info[0].get('name'))

def test_list_storage_pools(self):
list_storage_pools = self.driver.list_storage_pools(context)
Expand Down

0 comments on commit d09a9dc

Please sign in to comment.