diff --git a/glance/api/v1/upload_utils.py b/glance/api/v1/upload_utils.py index 90dde0c20c..b0787d90d7 100644 --- a/glance/api/v1/upload_utils.py +++ b/glance/api/v1/upload_utils.py @@ -193,6 +193,14 @@ def upload_data_to_store(req, image_meta, image_data, store, notifier): LOG.exception(msg) safe_kill(req, image_id) + except (ValueError, IOError) as e: + msg = _("Client disconnected before sending all data to backend") + LOG.debug(msg) + safe_kill(req, image_id) + raise webob.exc.HTTPBadRequest(explanation=msg, + content_type="text/plain", + request=req) + except Exception as e: msg = _("Failed to upload image %s" % image_id) LOG.exception(msg) diff --git a/glance/tests/unit/v1/test_upload_utils.py b/glance/tests/unit/v1/test_upload_utils.py index 0b69b3b12e..afbe44cce3 100644 --- a/glance/tests/unit/v1/test_upload_utils.py +++ b/glance/tests/unit/v1/test_upload_utils.py @@ -289,6 +289,16 @@ class TestUploadUtils(base.StoreClearingUnitTest): webob.exc.HTTPError, webob.exc.HTTPError) + def test_upload_data_to_store_client_disconnect(self): + self._test_upload_data_to_store_exception( + ValueError, + webob.exc.HTTPBadRequest) + + def test_upload_data_to_store_client_disconnect_ioerror(self): + self._test_upload_data_to_store_exception( + IOError, + webob.exc.HTTPBadRequest) + def test_upload_data_to_store_exception(self): self._test_upload_data_to_store_exception_with_notify( Exception,