From 30d8e1b97ce0621a0ce9aae97ad8ab35101860e6 Mon Sep 17 00:00:00 2001 From: Unmesh Gurjar Date: Thu, 6 Sep 2012 00:36:38 -0700 Subject: [PATCH] Specified Content-Length in update request header While uploading a Volume to an image, the HTTPConnection's request method does not set the Content-Length header (since the volume file is a sym link i.e. the os.fstat call returns a st_size of 0). This causes Volume uploads to Glance fail (since the image data is ignored as no content-length is specified). Therefore setting the Content-Length from update( ) method if the image data is provided. Fixes LP: #1045824 Change-Id: If259fc5a338e3e90214a52b773132ed901691c0f --- glanceclient/v1/images.py | 4 ++-- tests/v1/test_images.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/glanceclient/v1/images.py b/glanceclient/v1/images.py index b41b31401..e2b661dc6 100644 --- a/glanceclient/v1/images.py +++ b/glanceclient/v1/images.py @@ -218,16 +218,16 @@ def update(self, image, **kwargs): TODO(bcwaldon): document accepted params """ + hdrs = {} image_data = kwargs.pop('data', None) if image_data is not None: image_size = self._get_file_size(image_data) if image_size != 0: kwargs.setdefault('size', image_size) + hdrs['Content-Length'] = image_size else: image_data = None - hdrs = {} - try: purge_props = 'true' if kwargs.pop('purge_props') else 'false' except KeyError: diff --git a/tests/v1/test_images.py b/tests/v1/test_images.py index 759010f2b..0aa8b2b84 100644 --- a/tests/v1/test_images.py +++ b/tests/v1/test_images.py @@ -390,7 +390,7 @@ def test_update(self): def test_update_with_data(self): image_data = StringIO.StringIO('XXX') self.mgr.update('1', data=image_data) - expect_headers = {'x-image-meta-size': '3'} + expect_headers = {'x-image-meta-size': '3', 'Content-Length': 3} expect = [('PUT', '/v1/images/1', expect_headers, image_data)] self.assertEqual(self.api.calls, expect)