Update exception for property protection file

Non existing property protection file raises 500 Internal server
error. If admin/operator specifies non existing property protection
file in glance-api.conf. For example:
    [Default]
    property_protection_file = non_existing_file.yaml
    property_protection_rule_format = policies
Then create or update image. The 500 Internal server error will be
raised. But the expected result is 400 Bad Request.

Add the except of InavlidPropertyProtectionConfiguration exception,
and return 400 Bad Request.

The previous code lacks the specific process of
PropertyProtectionConfiguration exception, so it returned the common
500 error. Now, it returns 400 Bad Request.

Closes-Bug: #1905672
Change-Id: Id77010aac04aa9a4961c5bcafbf12694a0fe17c6
This commit is contained in:
Han Guangyu
2021-11-26 14:25:00 +08:00
committed by Cyril Roelandt
parent 00f453372c
commit 4e59a04d27
2 changed files with 17 additions and 0 deletions

View File

@@ -1293,6 +1293,10 @@ class Resource(object):
"request body contained characters that could not be "
"decoded by Glance")
raise webob.exc.HTTPBadRequest(explanation=msg)
except exception.InvalidPropertyProtectionConfiguration as e:
LOG.exception(_LE("Caught error: %s"),
encodeutils.exception_to_unicode(e))
raise webob.exc.HTTPBadRequest(explanation=e.msg)
except Exception as e:
LOG.exception(_LE("Caught error: %s"),
encodeutils.exception_to_unicode(e))

View File

@@ -301,6 +301,19 @@ class ResourceTest(test_utils.BaseTestCase):
self.assertRaises(AttributeError, resource.dispatch, Controller(),
'index', 'on', pants='off')
def test_dispatch_raises_bad_request(self):
class FakeController(object):
def index(self, shirt, pants=None):
return (shirt, pants)
resource = wsgi.Resource(FakeController(), None, None)
def dispatch(self, obj, action, *args, **kwargs):
raise exception.InvalidPropertyProtectionConfiguration()
self.mock_object(wsgi.Resource, 'dispatch', dispatch)
request = wsgi.Request.blank('/')
self.assertRaises(webob.exc.HTTPBadRequest, resource.__call__,
request)
def test_call(self):
class FakeController(object):
def index(self, shirt, pants=None):