Skip to content

Commit

Permalink
Raise 404 while deleting a deleted image
Browse files Browse the repository at this point in the history
Fixes bug 1171469

Currently the glance v1 api raises a HTTPForbidden when a user tries
to delete an already deleted image. It should be raising a HTTPNotFound.

Change-Id: I79f83782739bf40f3baba293cbc17fe04ca020bb
  • Loading branch information
iccha.sethi committed Apr 22, 2013
1 parent b56491f commit 7d341de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion glance/api/v1/images.py
Expand Up @@ -838,11 +838,16 @@ def delete(self, req, id):
request=req,
content_type="text/plain")

if image['status'] == 'deleted' or image['status'] == 'pending_delete':
if image['status'] == 'pending_delete':
msg = (_("Forbidden to delete a %s image.") % image['status'])
LOG.debug(msg)
raise HTTPForbidden(explanation=msg, request=req,
content_type="text/plain")
elif image['status'] == 'deleted':
msg = _("Image %s not found." % id)
LOG.debug(msg)
raise HTTPNotFound(explanation=msg, request=req,
content_type="text/plain")

if image['location'] and CONF.delayed_delete:
status = 'pending_delete'
Expand Down
5 changes: 3 additions & 2 deletions glance/tests/unit/v1/test_api.py
Expand Up @@ -2494,8 +2494,9 @@ def test_delete_deleted_image(self):
req = webob.Request.blank("/images/%s" % UUID2)
req.method = 'DELETE'
res = req.get_response(self.api)
self.assertEquals(res.status_int, webob.exc.HTTPForbidden.code)
self.assertTrue('Forbidden to delete a deleted image' in res.body)
self.assertEquals(res.status_int, webob.exc.HTTPNotFound.code)
msg = "Image %s not found." % UUID2
self.assertTrue(msg in res.body)

# Verify the status is still deleted
req = webob.Request.blank("/images/%s" % UUID2)
Expand Down

0 comments on commit 7d341de

Please sign in to comment.