Incorrect exception handling in Fault Management API

Bug #2055133 reported by Diganta Jena
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
StarlingX
In Progress
Undecided
Daniel Marques Caires

Bug Description

Brief Description
-----------------
From the O-RAN O2 interface's Watcher module, a Fault Management API call to StarlingX server to get the Alarm details of a non-existing Alarm ID(old alarm) is returning 500 HTTP Internal Server Error instead of the 404 HTTP Not Found exception.

Severity
--------
Critical as per O-RAN specifications

Steps to Reproduce
------------------
With a valid keystone token($OS_TOKEN) send a GET alarm request with invalid ID as shown below:-

curl -g -i --insecure -X GET http://<server IP:port>/v1/alarms/1532e62c-f04c-48ef-823b-7cfa432722a0 -H "Content-Type: application/json" -H "User-Agent: python-fmclient" -H "X-Auth-Token: $OS_TOKEN"

Expected Behavior
------------------
404 HTTP Not Found

Actual Behavior
----------------
500 HTTP Error

Reproducibility
---------------
100%

Timestamp/Logs
--------------
Log of O-RAN O2 Watcher:-

2023-12-11 08:42:32,772:[urllib3.connectionpool]:[connectionpool.py]-[456] [DEBUG]:http://10.10.10.11:18002 "GET /v1/alarms/1532e62c-f04c-48ef-823b-7cfa432722a0 HTTP/1.1" 500 0
2023-12-11 08:42:32,772:[keystoneauth.session]:[session.py]-[550] [DEBUG]:RESP: [500] content-length: 0 content-type: text/plain date: Mon, 11 Dec 2023 08:42:32 GMT
2023-12-11 08:42:32,772:[fmclient.common.http]:[http.py]-[101] [ERROR]:Request returned failure status 500.
2023-12-11 08:42:32,772:[o2common.service.watcher.base]:[base.py]-[48] [WARNING]:Failed to probe alarm watcher due to: <class 'fmclient.common.exceptions.HttpServerError'> - HTTP Server Error (HTTP 500)

2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor [req-a60767a9-04af-4c56-aa8b-f796ff0fd4df 6bf166da41134647b04826dc900c779a b139a637ac38407f94e3e08fc7372157 default - -] Exception in AuditLogging passed to event 'on_error': 'AlarmNotFound' object has no attribute 'value': AttributeError: 'AlarmNotFound' object has no attribute 'value'
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor Traceback (most recent call last):
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor File "/usr/lib/python3/dist-packages/fm/db/sqlalchemy/api.py", line 207, in alarm_get
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor result = query.one()
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor File "/usr/lib/python3/dist-packages/sqlalchemy/orm/query.py", line 3500, in one
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor raise orm_exc.NoResultFound("No row was found for one()")
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor sqlalchemy.orm.exc.NoResultFound: No row was found for one()
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor During handling of the above exception, another exception occurred:
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor Traceback (most recent call last):
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor File "/usr/lib/python3/dist-packages/wsmeext/pecan.py", line 84, in callfunction
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor result = f(self, *args, **kwargs)
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor File "/usr/lib/python3/dist-packages/fm/api/controllers/v1/alarm.py", line 341, in get_one
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor rpc_ialarm = objects.alarm.get_by_uuid(
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor File "/usr/lib/python3/dist-packages/oslo_versionedobjects/base.py", line 184, in wrapper
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor result = fn(cls, context, *args, **kwargs)
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor File "/usr/lib/python3/dist-packages/fm/objects/alarm.py", line 66, in get_by_uuid
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor return cls.dbapi.alarm_get(uuid)
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor File "/usr/lib/python3/dist-packages/fm/objects/__init__.py", line 23, in wrapper
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor result = fn(*args, **kwargs)
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor File "/usr/lib/python3/dist-packages/fm/db/sqlalchemy/api.py", line 209, in alarm_get
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor raise exceptions.AlarmNotFound(alarm=uuid)
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor fm.common.exceptions.AlarmNotFound: <unprintable AlarmNotFound object>
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor During handling of the above exception, another exception occurred:
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor Traceback (most recent call last):
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor File "/usr/lib/python3/dist-packages/pecan/core.py", line 683, in __call__
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor self.invoke_controller(controller, args, kwargs, state)
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor File "/usr/lib/python3/dist-packages/pecan/core.py", line 574, in invoke_controller
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor result = controller(*args, **kwargs)
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor File "/usr/lib/python3/dist-packages/wsmeext/pecan.py", line 108, in callfunction
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor data = wsme.api.format_exception(
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor File "/usr/lib/python3/dist-packages/wsme/api.py", line 219, in format_exception
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor else six.text_type(error))
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor File "/usr/lib/python3/dist-packages/fm/common/exceptions.py", line 41, in __str__
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor return repr(self.value)
2023-12-11 08:44:59.145 8351 ERROR fm.api.hooks.auditor AttributeError: 'AlarmNotFound' object has no attribute 'value'

Test Activity
-------------
Conformance Testing for O-RAN O2 interface

Workaround
----------
Change O2 code to handle 500 Exception.

Solution
---------
In https://opendev.org/starlingx/fault/src/branch/master/fm-rest-api/fm/fm/common/exceptions.py#L41, the 'value' attribute is incorrect due to which the error is occurring. Please rectify it.

Revision history for this message
Daniel Marques Caires (daniel-caires) wrote (last edit ):

No other response code, except HTTP 200, seems to be working properly.

Revision history for this message
Diganta Jena (djena) wrote :

Yes, since every exception is a child class of ApiError where the __str__() method is invoking the incorrect attribute "value", all exceptions will be overridden to the default 500 HTTPInternalServerError as per https://opendev.org/starlingx/fault/src/branch/master/fm-rest-api/fm/fm/common/exceptions.py#L20

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to fault (master)

Fix proposed to branch: master
Review: https://review.opendev.org/c/starlingx/fault/+/911103

Changed in starlingx:
status: New → In Progress
Changed in starlingx:
assignee: nobody → Daniel Marques Caires (daniel-caires)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.