Ensure we don't ask a backend store to delete an image if the image is queued or saving.

This commit is contained in:
jaypipes@gmail.com 2011-04-04 10:32:14 -04:00
parent bdd71d8007
commit b1754fb076
3 changed files with 39 additions and 1 deletions

View File

@ -450,7 +450,12 @@ class Controller(wsgi.Controller):
"""
image = self.get_image_meta_or_404(req, id)
delete_from_backend(image['location'])
# The image's location field may be None in the case
# of a saving or queued image, therefore don't ask a backend
# to delete the image if the backend doesn't yet store it.
# See https://bugs.launchpad.net/glance/+bug/747799
if image['location']:
delete_from_backend(image['location'])
registry.delete_image_metadata(self.options, id)

View File

@ -321,6 +321,7 @@ def stub_out_registry_db_image_api(stubs):
values['checksum'] = values.get('checksum')
values['deleted'] = False
values['properties'] = values.get('properties', {})
values['location'] = values.get('location')
values['created_at'] = datetime.datetime.utcnow()
values['updated_at'] = datetime.datetime.utcnow()
values['deleted_at'] = None

View File

@ -582,3 +582,35 @@ class TestGlanceAPI(unittest.TestCase):
req.method = 'DELETE'
res = req.get_response(self.api)
self.assertEquals(res.status_int, webob.exc.HTTPNotFound.code)
def test_delete_queued_image(self):
"""
Here, we try to delete an image that is in the queued state.
Bug #747799 demonstrated that trying to DELETE an image
that had had its save process killed manually results in failure
because the location attribute is None.
"""
# Add an image the way that glance-upload adds an image...
# by reserving a place in the database for an image without
# really any attributes or information on the image and then
# later doing an update with the image body and other attributes.
# We will stop the process after the reservation stage, then
# try to delete the image.
fixture_headers = {'x-image-meta-store': 'file',
'x-image-meta-name': 'fake image #3'}
req = webob.Request.blank("/images")
req.method = 'POST'
for k, v in fixture_headers.iteritems():
req.headers[k] = v
res = req.get_response(self.api)
self.assertEquals(res.status_int, httplib.CREATED)
res_body = json.loads(res.body)['image']
self.assertEquals('queued', res_body['status'])
# Now try to delete the image...
req = webob.Request.blank("/images/3")
req.method = 'DELETE'
res = req.get_response(self.api)
self.assertEquals(res.status_int, 200)