catch the correct exception for alarm not found case

Issue:
for the alarm_show/alarm_delete/event_show api, if the input UUID
string is not valid, http server side will return error code 500
(Internal Server Error), due to the error code is not set correctly.
Solution:
Correct the error code in server, and add client code to handle
"HTTP 404 - Not Found" error code correctly.

Test:
Run "fm alarm-show/alarm-delete/event-show" with valid/invalid
UUID, and the response is correct. For invalid UUID, response
string will like below. "xxx" for the invalid UUID string.
"Alarm not found: xxx"
"Event log not found: xxx"

Closes-Bug: 1806927

Change-Id: I8d17c5bc55733f269d875ae835ab6295fed4d899
Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
changes/64/642664/5
Shuicheng Lin 4 years ago
parent c6b9accb4f
commit 1faff551f2
  1. 2
      fm-rest-api/centos/build_srpm.data
  2. 15
      fm-rest-api/fm/fm/common/exceptions.py
  3. 2
      python-fmclient/centos/build_srpm.data
  4. 11
      python-fmclient/fmclient/fmclient/common/exceptions.py
  5. 5
      python-fmclient/fmclient/fmclient/v1/alarm_shell.py
  6. 3
      python-fmclient/fmclient/fmclient/v1/event_log_shell.py

@ -1,2 +1,2 @@
SRC_DIR="fm"
TIS_PATCH_VER=2
TIS_PATCH_VER=3

@ -16,7 +16,8 @@ class ApiError(Exception):
message = _("An unknown exception occurred.")
code = webob.exc.HTTPInternalServerError
# 500 - HTTPInternalServerError
code = webob.exc.HTTPInternalServerError.code
def __init__(self, message=None, **kwargs):
@ -51,7 +52,8 @@ class ApiError(Exception):
class NotFound(ApiError):
message = _("Resource could not be found.")
code = webob.exc.HTTPNotFound
# 404 - HTTPNotFound
code = webob.exc.HTTPNotFound.code
class HTTPNotFound(NotFound):
@ -76,7 +78,8 @@ class ServerNotFound(NotFound):
class Invalid(ApiError):
message = _("Unacceptable parameters.")
code = webob.exc.HTTPBadRequest
# 400 - HTTPBadRequest
code = webob.exc.HTTPBadRequest.code
class PatchError(Invalid):
@ -97,12 +100,14 @@ class InvalidIdentity(Invalid):
class PolicyNotAuthorized(ApiError):
message = _("Policy doesn't allow %(action)s to be performed.")
code = webob.exc.HTTPUnauthorized
# 401 - HTTPUnauthorized
code = webob.exc.HTTPUnauthorized.code
class Conflict(ApiError):
message = _('HTTP Conflict.')
code = webob.exc.HTTPConflict
# 409 - HTTPConflict
code = webob.exc.HTTPConflict.code
class AlarmAlreadyExists(Conflict):

@ -1,2 +1,2 @@
SRC_DIR="fmclient"
TIS_PATCH_VER=2
TIS_PATCH_VER=3

@ -85,6 +85,15 @@ class HTTPClientError(HttpError):
message = _("HTTP Client Error")
class HTTPNotFound(HTTPClientError):
"""HTTP 404 - Not Found
Exception for cases in which the server did not find anything
matching the Request-URI.
"""
message = _("HTTP Client Error: Not Found")
class HttpServerError(HttpError):
"""Server-side HTTP error.
@ -163,6 +172,8 @@ def from_response(response, method, url=None):
except KeyError:
if 500 <= response.status_code < 600:
cls = HttpServerError
elif 404 == response.status_code:
cls = HTTPNotFound
elif 400 <= response.status_code < 500:
cls = HTTPClientError
else:

@ -6,6 +6,7 @@
from fmclient import exc
from fmclient.common import exceptions as exc_common
from fmclient.common import utils
from fmclient.common import wrapping_formatters
from fmclient.common import options
@ -26,7 +27,7 @@ def do_alarm_show(cc, args={}):
'''Show an active alarm.'''
try:
fault = cc.alarm.get(args.alarm)
except exc.HTTPNotFound:
except exc_common.HTTPNotFound:
raise exc.CommandError('Alarm not found: %s' % args.alarm)
else:
_display_fault(fault)
@ -37,7 +38,7 @@ def do_alarm_delete(cc, args={}):
'''Delete an active alarm.'''
try:
cc.alarm.delete(args.alarm)
except exc.HTTPNotFound:
except exc_common.HTTPNotFound:
raise exc.CommandError('Alarm not found: %s' % args.alarm)

@ -6,6 +6,7 @@
from fmclient import exc
from fmclient.common import exceptions as exc_common
from fmclient.common import utils
from fmclient.common import wrapping_formatters
from fmclient.common import options
@ -28,7 +29,7 @@ def do_event_show(cc, args={}):
'''Show a event log.'''
try:
log = cc.event_log.get(args.event_log)
except exc.HTTPNotFound:
except exc_common.HTTPNotFound:
raise exc.CommandError('Event log not found: %s' % args.event_log)
else:
_display_event(log)

Loading…
Cancel
Save