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)
# 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)
Re-produces the cause of the error:
======================================================================
ERROR: test_delete_queued_image (tests.unit.test_api.TestGlanceAPI)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/jpipes/repos/glance/bug747799/tests/unit/test_api.py", line 615, in test_delete_queued_image
res = req.get_response(self.api)
File "/home/jpipes/repos/glance/bug747799/.glance-venv/lib/python2.6/site-packages/webob/request.py", line 1008, in get_response
application, catch_exc_info=False)
File "/home/jpipes/repos/glance/bug747799/.glance-venv/lib/python2.6/site-packages/webob/request.py", line 977, in call_application
app_iter = application(self.environ, start_response)
File "/home/jpipes/repos/glance/bug747799/.glance-venv/lib/python2.6/site-packages/webob/dec.py", line 159, in __call__
return resp(environ, start_response)
File "/home/jpipes/repos/glance/bug747799/.glance-venv/lib/python2.6/site-packages/routes/middleware.py", line 131, in __call__
response = self.app(environ, start_response)
File "/home/jpipes/repos/glance/bug747799/.glance-venv/lib/python2.6/site-packages/webob/dec.py", line 159, in __call__
return resp(environ, start_response)
File "/home/jpipes/repos/glance/bug747799/.glance-venv/lib/python2.6/site-packages/webob/dec.py", line 147, in __call__
resp = self.call_func(req, *args, **self.kwargs)
File "/home/jpipes/repos/glance/bug747799/.glance-venv/lib/python2.6/site-packages/webob/dec.py", line 208, in call_func
return self.func(req, *args, **kwargs)
File "/home/jpipes/repos/glance/bug747799/glance/common/wsgi.py", line 228, in __call__
result = method(**arg_dict)
File "/home/jpipes/repos/glance/bug747799/glance/server.py", line 453, in delete
delete_from_backend(image['location'])
KeyError: 'location'
Note the error is a KeyError because test_api uses a db stub, instead of SQLAlchemy, which simply returns None for image.location.
Adding this test to /tests/ unit/test_ api.py:
def test_delete_ queued_ image(self) :
fixture_ headers = {'x-image- meta-store' : 'file',
' x-image- meta-name' : 'fake image #3'}
"""
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.
req = webob.Request. blank(" /images" ) headers. iteritems( ):
req. headers[ k] = v response( self.api)
self.assertEqu als(res. status_ int, httplib.CREATED)
req.method = 'POST'
for k, v in fixture_
res = req.get_
res_body = json.loads( res.body) ['image' ]
self.assertEqu als('queued' , res_body['status'])
# Now try to delete the image... blank(" /images/ 3") response( self.api)
self.assertEqu als(res. status_ int, 200)
req = webob.Request.
req.method = 'DELETE'
res = req.get_
Re-produces the cause of the error:
======= ======= ======= ======= ======= ======= ======= ======= ======= ======= queued_ image (tests. unit.test_ api.TestGlanceA PI) ------- ------- ------- ------- ------- ------- ------- ------- ------- jpipes/ repos/glance/bug747799/tests/ unit/test_ api.py" , line 615, in test_delete_ queued_ image response( self.api) jpipes/ repos/glance/bug747799/.glance- venv/lib/ python2. 6/site- packages/ webob/request. py", line 1008, in get_response info=False) jpipes/ repos/glance/bug747799/.glance- venv/lib/ python2. 6/site- packages/ webob/request. py", line 977, in call_application self.environ, start_response) jpipes/ repos/glance/bug747799/.glance- venv/lib/ python2. 6/site- packages/ webob/dec. py", line 159, in __call__ jpipes/ repos/glance/bug747799/.glance- venv/lib/ python2. 6/site- packages/ routes/ middleware. py", line 131, in __call__ jpipes/ repos/glance/bug747799/.glance- venv/lib/ python2. 6/site- packages/ webob/dec. py", line 159, in __call__ jpipes/ repos/glance/bug747799/.glance- venv/lib/ python2. 6/site- packages/ webob/dec. py", line 147, in __call__ jpipes/ repos/glance/bug747799/.glance- venv/lib/ python2. 6/site- packages/ webob/dec. py", line 208, in call_func jpipes/ repos/glance/bug747799/glance/ common/ wsgi.py" , line 228, in __call__ jpipes/ repos/glance/bug747799/glance/server.py", line 453, in delete from_backend( image[' location' ])
ERROR: test_delete_
-------
Traceback (most recent call last):
File "/home/
res = req.get_
File "/home/
application, catch_exc_
File "/home/
app_iter = application(
File "/home/
return resp(environ, start_response)
File "/home/
response = self.app(environ, start_response)
File "/home/
return resp(environ, start_response)
File "/home/
resp = self.call_func(req, *args, **self.kwargs)
File "/home/
return self.func(req, *args, **kwargs)
File "/home/
result = method(**arg_dict)
File "/home/
delete_
KeyError: 'location'
Note the error is a KeyError because test_api uses a db stub, instead of SQLAlchemy, which simply returns None for image.location.