Skip to content

Commit

Permalink
Fixes deletion of invalid image member
Browse files Browse the repository at this point in the history
This fixes the 500 error on deleting an invalid/non-member tenant of an image.

Fixes LP: #1060868

Change-Id: I5a2dc56690d7525127be1a8843004d075a3fe5bb
  • Loading branch information
UnmeshG committed Oct 26, 2012
1 parent 910852a commit 950e700
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
16 changes: 9 additions & 7 deletions glance/registry/api/v1/members.py
Expand Up @@ -273,14 +273,16 @@ def delete(self, req, image_id, id):
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")
Expand Down
13 changes: 13 additions & 0 deletions glance/tests/unit/v1/test_api.py
Expand Up @@ -1873,6 +1873,19 @@ def test_delete_member(self):
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):
Expand Down

0 comments on commit 950e700

Please sign in to comment.