From 9a2f30964d190bdc0899492a621b69515c6e81fd Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Sun, 25 Nov 2012 18:37:14 -0500 Subject: [PATCH] Return size as int from store get call The size value needs to be comparable as integers, which a string won't give us. This returns size as an integer from a call to the 'get' method of our known stores. Change-Id: I08ff9c673735eeb5943745ae4a27d6e241101230 --- glance/store/filesystem.py | 2 +- glance/store/http.py | 2 +- glance/store/swift.py | 2 +- glance/tests/functional/store/__init__.py | 4 ++-- glance/tests/functional/store/test_swift.py | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/glance/store/filesystem.py b/glance/store/filesystem.py index c3d6f17f28..5b0dfa01ab 100644 --- a/glance/store/filesystem.py +++ b/glance/store/filesystem.py @@ -155,7 +155,7 @@ class Store(glance.store.base.Store): msg = _("Found image at %s. Returning in ChunkedFile.") % filepath LOG.debug(msg) try: - image_size = str(os.path.getsize(filepath)) + image_size = int(os.path.getsize(filepath)) except os.error: image_size = None return (ChunkedFile(filepath), image_size) diff --git a/glance/store/http.py b/glance/store/http.py index 9585733a68..821981c578 100644 --- a/glance/store/http.py +++ b/glance/store/http.py @@ -177,7 +177,7 @@ class Store(glance.store.base.Store): image_id=location.image_id, store_specs=location.store_specs) return self._query(new_loc, verb, depth + 1) - content_length = resp.getheader('content-length', 0) + content_length = int(resp.getheader('content-length', 0)) return (conn, resp, content_length) def _get_conn_class(self, loc): diff --git a/glance/store/swift.py b/glance/store/swift.py index 5c4bb440d3..4f04dbc3a0 100644 --- a/glance/store/swift.py +++ b/glance/store/swift.py @@ -305,7 +305,7 @@ class Store(glance.store.base.Store): except StopIteration: return '' - length = resp_headers.get('content-length') + length = int(resp_headers.get('content-length', 0)) return (ResponseIndexable(resp_body, length), length) def get_size(self, location): diff --git a/glance/tests/functional/store/__init__.py b/glance/tests/functional/store/__init__.py index 2fab1a3938..6e626af2bf 100644 --- a/glance/tests/functional/store/__init__.py +++ b/glance/tests/functional/store/__init__.py @@ -79,7 +79,7 @@ class BaseTestCase(object): image_id=image_id) (get_iter, get_size) = store.get(location) - self.assertEqual('3', get_size) + self.assertEqual(3, get_size) self.assertEqual('XXX', ''.join(get_iter)) store.delete(location) @@ -96,5 +96,5 @@ class BaseTestCase(object): store.get_store_location_class(), uri=image_uri) (get_iter, get_size) = store.get(location) - self.assertEqual('3', get_size) + self.assertEqual(3, get_size) self.assertEqual('XXX', ''.join(get_iter)) diff --git a/glance/tests/functional/store/test_swift.py b/glance/tests/functional/store/test_swift.py index ce60f8f4a2..7a99fce107 100644 --- a/glance/tests/functional/store/test_swift.py +++ b/glance/tests/functional/store/test_swift.py @@ -221,7 +221,7 @@ class TestSwiftStore(store_tests.BaseTestCase, unittest.TestCase): # Store interface should still be respected even though # we are storing images in multiple Swift objects (get_iter, get_size) = store.get(location) - self.assertEqual('5242880', get_size) + self.assertEqual(5242880, get_size) self.assertEqual('X' * 5242880, ''.join(get_iter)) # The object should have a manifest pointing to the chunks @@ -332,7 +332,7 @@ class TestSwiftStore(store_tests.BaseTestCase, unittest.TestCase): self.assertEqual('', container.get('x-container-write', '')) (get_iter, get_size) = store.get(location) - self.assertEqual('3', get_size) + self.assertEqual(3, get_size) self.assertEqual('XXX', ''.join(get_iter)) store.delete(location)