Adds DELETE to the Parallax REST API.

This commit is contained in:
jaypipes@gmail.com
2010-10-14 13:23:37 -04:00
parent 19a653c984
commit 728b4e5f5f
3 changed files with 56 additions and 4 deletions

View File

@@ -74,8 +74,16 @@ class ImageController(wsgi.Controller):
return dict(image=self._make_image_dict(image))
def delete(self, req, id):
"""Delete is not currently supported """
raise exc.HTTPNotImplemented()
"""Deletes an existing image with the registry.
:param req: Request body. Ignored.
:param id: The opaque internal identifier for the image
:retval Returns 200 if delete was successful, a fault if not.
"""
context = None
updated_image = db.image_destroy(context, id)
def create(self, req):
"""Registers a new image with the registry.

View File

@@ -202,7 +202,8 @@ def stub_out_parallax_db_image_api(stubs):
values['status'] = 'available'
else:
if not values['status'] in self.VALID_STATUSES:
raise exception.Invalid("Invalid status '%s' for image" % values['status'])
raise exception.Invalid("Invalid status '%s' for image" %
values['status'])
self.next_id += 1
self.images.append(values)
@@ -222,7 +223,8 @@ def stub_out_parallax_db_image_api(stubs):
images = [i for i in self.images if str(i['id']) == str(image_id)]
if len(images) != 1 or images[0]['deleted']:
new_exc = exception.NotFound("No model for id %s %s" % (image_id, str(self.images)))
new_exc = exception.NotFound("No model for id %s %s" %
(image_id, str(self.images)))
raise new_exc.__class__, new_exc, sys.exc_info()[2]
else:
return images[0]

View File

@@ -180,3 +180,45 @@ class TestImageController(unittest.TestCase):
# over to Glance to support exception catching into
# standard HTTP errors.
self.assertRaises(exception.NotFound, req.get_response, controllers.API())
def test_delete_image(self):
"""Tests that the /images DELETE parallax API deletes the image"""
# Grab the original number of images
req = webob.Request.blank('/images')
res = req.get_response(controllers.API())
res_dict = json.loads(res.body)
self.assertEquals(res.status_int, 200)
orig_num_images = len(res_dict['images'])
# Delete image #2
req = webob.Request.blank('/images/2')
req.method = 'DELETE'
res = req.get_response(controllers.API())
self.assertEquals(res.status_int, 200)
# Verify one less image
req = webob.Request.blank('/images')
res = req.get_response(controllers.API())
res_dict = json.loads(res.body)
self.assertEquals(res.status_int, 200)
new_num_images = len(res_dict['images'])
self.assertEquals(new_num_images, orig_num_images - 1)
def test_delete_image_not_existing(self):
"""Tests proper exception is raised if attempt to delete non-existing
image"""
req = webob.Request.blank('/images/3')
req.method = 'DELETE'
# TODO(jaypipes): Port Nova's Fault infrastructure
# over to Glance to support exception catching into
# standard HTTP errors.
self.assertRaises(exception.NotFound, req.get_response, controllers.API())