Comment 2 for bug 747799

Revision history for this message
Jay Pipes (jaypipes) wrote :

Adding this test to /tests/unit/test_api.py:

    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)

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.