From 5c6fd44504e47ddbec3e0c29d454daeda87f86a4 Mon Sep 17 00:00:00 2001 From: Mitya_Eremeev Date: Fri, 9 Jul 2021 11:37:37 +0300 Subject: [PATCH] Fix Masakari API to properly return error codes Change-Id: I538b9b143c868d9419709356daf0ffc48e2f0df9 Closes-Bug: #1932194 --- masakari/exception.py | 2 +- masakari/tests/unit/api/openstack/test_wsgi.py | 5 +++-- releasenotes/notes/bug-1932194-2b721860bbc26819.yaml | 6 ++++++ 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/bug-1932194-2b721860bbc26819.yaml diff --git a/masakari/exception.py b/masakari/exception.py index 7ce938b3..704d7cac 100644 --- a/masakari/exception.py +++ b/masakari/exception.py @@ -44,7 +44,7 @@ CONF = masakari.conf.CONF class ConvertedException(webob.exc.WSGIHTTPException): def __init__(self, code, title="", explanation=""): - self.code = code + self.code = int(code) # There is a strict rule about constructing status line for HTTP: # '...Status-Line, consisting of the protocol version followed by a # numeric status code and its associated textual phrase, with each diff --git a/masakari/tests/unit/api/openstack/test_wsgi.py b/masakari/tests/unit/api/openstack/test_wsgi.py index 9866be40..9e05bdc4 100644 --- a/masakari/tests/unit/api/openstack/test_wsgi.py +++ b/masakari/tests/unit/api/openstack/test_wsgi.py @@ -253,8 +253,9 @@ class ResourceTest(MicroversionedTest): @extensions.expected_errors(HTTPStatus.BAD_REQUEST) def create(self, req, body): if expected_body != body: - msg = "The request body invalid" - raise webob.exc.HTTPBadRequest(explanation=msg) + raise exception.ConvertedException( + code=HTTPStatus.BAD_REQUEST, + explanation="The request body invalid") return "success" # verify the method: POST app = fakes.TestRouter(Controller()) diff --git a/releasenotes/notes/bug-1932194-2b721860bbc26819.yaml b/releasenotes/notes/bug-1932194-2b721860bbc26819.yaml new file mode 100644 index 00000000..87281294 --- /dev/null +++ b/releasenotes/notes/bug-1932194-2b721860bbc26819.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixes Masakari API to properly return error codes for invalid requests + to the user instead of 500. + `LP#1932194 `__