Fixes deletion of invalid image member
This fixes the 500 error on deleting an invalid/non-member tenant of an image. Fixes LP: #1060868 Change-Id: I5a2dc56690d7525127be1a8843004d075a3fe5bb
This commit is contained in:
parent
910852a237
commit
950e700b4f
@ -273,14 +273,16 @@ class Controller(object):
|
||||
raise webob.exc.HTTPForbidden(msg)
|
||||
|
||||
# Look up an existing membership
|
||||
try:
|
||||
session = self.db_api.get_session()
|
||||
members = self.db_api.image_member_find(req.context,
|
||||
image_id=image_id,
|
||||
member=id)
|
||||
members = self.db_api.image_member_find(req.context,
|
||||
image_id=image_id,
|
||||
member=id)
|
||||
if members:
|
||||
self.db_api.image_member_delete(req.context, members[0]['id'])
|
||||
except exception.NotFound:
|
||||
pass
|
||||
else:
|
||||
msg = _("%(id)s is not a member of image %(image_id)s")
|
||||
LOG.debug(msg % locals())
|
||||
msg = _("Membership could not be found.")
|
||||
raise webob.exc.HTTPNotFound(explanation=msg)
|
||||
|
||||
# Make an appropriate result
|
||||
msg = _("Successfully deleted a membership from image %(id)s")
|
||||
|
@ -1873,6 +1873,19 @@ class TestRegistryAPI(base.IsolatedUnitTest):
|
||||
res = req.get_response(self.api)
|
||||
self.assertEquals(res.status_int, webob.exc.HTTPUnauthorized.code)
|
||||
|
||||
def test_delete_member_invalid(self):
|
||||
"""
|
||||
Tests deleting a invalid/non existing member raises right exception
|
||||
"""
|
||||
self.api = test_utils.FakeAuthMiddleware(rserver.API(self.mapper),
|
||||
is_admin=True)
|
||||
req = webob.Request.blank('/images/%s/members/pattieblack' % UUID2)
|
||||
req.method = 'DELETE'
|
||||
|
||||
res = req.get_response(self.api)
|
||||
self.assertEquals(res.status_int, webob.exc.HTTPNotFound.code)
|
||||
self.assertTrue('Membership could not be found' in res.body)
|
||||
|
||||
|
||||
class TestGlanceAPI(base.IsolatedUnitTest):
|
||||
def setUp(self):
|
||||
|
Loading…
Reference in New Issue
Block a user