From 0d104e73ad08103d1c983c25841ada15acf7dadb Mon Sep 17 00:00:00 2001 From: jkraitbewr Date: Thu, 9 May 2024 15:36:11 -0400 Subject: [PATCH] Fixed alarm related issues There were several issues related to alarms. * Region name was incorrect * Unsupported alarm types now discard correctly TEST PLAN PASS: Run compliance and quality robot tests, with mock SMO * Deploy oran-o2 application on StarlingX system controller (stx9) * Update/apply override for dev image * Ensure O2 pod is running using correct image * Manually verify alarm related logs for errors Issue-ID: INF-460 Signed-off-by: jkraitbewr Change-Id: I42027ce1ff8dd8e03782e22024b16c1c18abdf5c --- o2ims/adapter/clients/fault_client.py | 16 +++++++++------- o2ims/service/auditor/alarm_handler.py | 12 ++++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/o2ims/adapter/clients/fault_client.py b/o2ims/adapter/clients/fault_client.py index 3717487..989edfc 100644 --- a/o2ims/adapter/clients/fault_client.py +++ b/o2ims/adapter/clients/fault_client.py @@ -150,7 +150,7 @@ class StxFaultClientImp(object): try: sub_is_https = False os_client_args = config.get_stx_access_info( - region_name=subcloud[0].name, + region_name=subcloud[0].region_name, subcloud_hostname=subcloud[0].oam_floating_ip) stx_client = get_stx_client(**os_client_args) except EndpointException as e: @@ -158,7 +158,8 @@ class StxFaultClientImp(object): if CGTSCLIENT_ENDPOINT_ERROR_MSG in msg: sub_is_https = True os_client_args = config.get_stx_access_info( - region_name=subcloud[0].name, sub_is_https=sub_is_https, + region_name=subcloud[0].region_name, + sub_is_https=sub_is_https, subcloud_hostname=subcloud[0].oam_floating_ip) stx_client = get_stx_client(**os_client_args) else: @@ -192,8 +193,8 @@ class StxFaultClientImp(object): alarms = self.fmclient.alarm.list(expand=True) if len(alarms) == 0: return [] - logger.debug('alarm 1:' + str(alarms[0].to_dict())) - # [print('alarm:' + str(alarm.to_dict())) for alarm in alarms if alarm] + [logger.debug( + 'alarm:' + str(alarm.to_dict())) for alarm in alarms if alarm] return [alarmModel.FaultGenericModel( alarmModel.EventTypeEnum.ALARM, self._alarmconverter(alarm)) for alarm in alarms if alarm] @@ -201,7 +202,8 @@ class StxFaultClientImp(object): def getAlarmInfo(self, id) -> alarmModel.FaultGenericModel: try: alarm = self.fmclient.alarm.get(id) - logger.debug('get alarm id ' + id + ':' + str(alarm.to_dict())) + logger.debug( + 'get alarm id: ' + id + ', result:' + str(alarm.to_dict())) except HTTPNotFound: event = self.fmclient.event_log.get(id) return alarmModel.FaultGenericModel( @@ -212,8 +214,8 @@ class StxFaultClientImp(object): def getEventList(self, **filters) -> List[alarmModel.FaultGenericModel]: events = self.fmclient.event_log.list(alarms=True, expand=True) - logger.debug('event 1:' + str(events[0].to_dict())) - # [print('alarm:' + str(event.to_dict())) for event in events if event] + [logger.debug( + 'alarm:' + str(event.to_dict())) for event in events if event] return [alarmModel.FaultGenericModel( alarmModel.EventTypeEnum.EVENT, self._eventconverter(event)) for event in events if event] diff --git a/o2ims/service/auditor/alarm_handler.py b/o2ims/service/auditor/alarm_handler.py index 2847a85..5f6ed35 100644 --- a/o2ims/service/auditor/alarm_handler.py +++ b/o2ims/service/auditor/alarm_handler.py @@ -41,10 +41,6 @@ def update_alarm( alarm_event_record = uow.alarm_event_records.get(fmobj.id) if not alarm_event_record: - logger.info("add alarm event record:" + fmobj.name - + " update_at: " + str(fmobj.updatetime) - + " id: " + str(fmobj.id) - + " hash: " + str(fmobj.hash)) localmodel = create_by(fmobj) content = json.loads(fmobj.content) entity_type_id = content['entity_type_id'] @@ -65,6 +61,14 @@ def update_alarm( extensions = json.loads(host.extensions) if extensions['hostname'] == hostname: localmodel.resourceId = host.resourceId + break + else: + # Example would be when alarm has host=controller + # TODO: Handle host=controller better + logger.warning( + 'Couldnt match alarm event ' + f'to hostname for: {content}') + return uow.alarm_event_records.add(localmodel) logger.info("Add the alarm event record: " + fmobj.id + ", name: " + fmobj.name) -- 2.16.6