Return 400 if registry returns 400.
Fixes bug 919244. The registry would return 400 for invalid input, which resulted in an exception.Invalid being thrown in the registry client. There was no exception handler for this exception, so it got bubbled up and turned into a 500. This should fix the problem by adding the missing exception handlers. Change-Id: I75ecfec1c0b0b4b3df1a8c9ace83e75d19527c93
This commit is contained in:
parent
b712949ec5
commit
eb2ab3a40a
@ -93,6 +93,10 @@ class Controller(object):
|
||||
can_share = bool(body['member']['can_share'])
|
||||
try:
|
||||
registry.add_member(req.context, image_id, id, can_share)
|
||||
except exception.Invalid, e:
|
||||
msg = "%s" % e
|
||||
logger.debug(msg)
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
except exception.NotFound, e:
|
||||
msg = "%s" % e
|
||||
logger.debug(msg)
|
||||
@ -121,6 +125,10 @@ class Controller(object):
|
||||
|
||||
try:
|
||||
registry.replace_members(req.context, image_id, body)
|
||||
except exception.Invalid, e:
|
||||
msg = "%s" % e
|
||||
logger.debug(msg)
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
except exception.NotFound, e:
|
||||
msg = "%s" % e
|
||||
logger.debug(msg)
|
||||
|
@ -148,6 +148,24 @@ class TestSharedImagesApi(keystone_utils.KeystoneTests):
|
||||
self.assertEqual(response.status, 200)
|
||||
self.assertEqual(content, '{"images": []}')
|
||||
|
||||
# Build path for the next couple of checks
|
||||
path = ("http://%s:%d/v1/images/%s/members" %
|
||||
("0.0.0.0", self.api_port, image_id))
|
||||
|
||||
# Make sure update with invalid data gets rejected with 400
|
||||
body = {
|
||||
'test': [
|
||||
{
|
||||
'member_id': keystone_utils.bacon_id,
|
||||
'can_share': False,
|
||||
},
|
||||
],
|
||||
}
|
||||
response, _ = self._request(path, 'PUT',
|
||||
keystone_utils.pattieblack_token,
|
||||
body=json.dumps(body))
|
||||
self.assertEqual(response.status, 400)
|
||||
|
||||
# Replace froggy with bacon
|
||||
body = {
|
||||
'memberships': [
|
||||
@ -157,8 +175,6 @@ class TestSharedImagesApi(keystone_utils.KeystoneTests):
|
||||
},
|
||||
],
|
||||
}
|
||||
path = "http://%s:%d/v1/images/%s/members" % \
|
||||
("0.0.0.0", self.api_port, image_id)
|
||||
|
||||
response, content = self._request(path, 'PUT',
|
||||
keystone_utils.pattieblack_token,
|
||||
|
Loading…
Reference in New Issue
Block a user